0

I'm working on template matching Using implemented function to make a match space between them and getting local maxima of the expected matches in the original photo

now, I have the local maxima points x , y displayed in a list

in my GUI I want to draw a rectangle or a circle around the point of local maxima displaying them in the detected pattern label (grayscale of original image with the rectangle on the detected shape) like this

GUI Example

two functions for rectangle and circle, how can i connect those two functions to be drawn around the point of local maxima when i already display an image on the label in the GUI, such that the local maxima point is taken and used to be the center of the rectangle on the displayed image on label except those functions are with matplot i want them on already existing image on label in GUI

def make_rects(plt_object,xy,template):
        htemp, wtemp = template.shape
        for ridx in range(xy.shape[0]):
            y,x = xy[ridx]
            r =  plt.Rectangle((x-wtemp/2, y-htemp/2), wtemp, htemp, edgecolor='g', facecolor='none')
            plt_object.add_patch(r)

    def make_circles(plt_object,xy,template):
        htemp, wtemp = template.shape
        for ridx in range(xy.shape[0]):
            y,x = xy[ridx]
            plt_object.plot(x, y, 'o', markeredgecolor='g', markerfacecolor='none', markersize=10)

Here is my implemented function

 import numpy as np
 from scipy.signal import correlate2d

        def match_template_corr(x, temp):
            y = np.empty(x.shape)
            y = correlate2d(x, temp, 'same')
            return y

GUI Picture: enter image description here

  • Does this answer your question? [OpenCV performance on template matching](https://stackoverflow.com/questions/7139606/opencv-performance-on-template-matching) – Joe Apr 25 '20 at 09:39
  • This is a pretty common task and there are hundreds of examples to be found. What makes your case special? – Joe Apr 25 '20 at 09:40
  • That i'm connectiong it with GUI and I'm not using a built-in function – Hassan Bosha Apr 25 '20 at 09:55
  • my problem is drawing circles or rectangles around the point of maxima – Hassan Bosha Apr 25 '20 at 09:56
  • Everybody is doing that https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_template_matching/py_template_matching.html – Joe Apr 25 '20 at 09:57
  • https://medium.com/analytics-vidhya/finding-waldo-feature-matching-for-opencv-9bded7f5ab10 – Joe Apr 25 '20 at 09:58
  • http://cs231n.stanford.edu/reports/2017/pdfs/817.pdf – Joe Apr 25 '20 at 09:59
  • 1
    Try to break you problem down into simple parts: 1.) show images in a GUI 2.) use a template matching algorithm 3.) drawing circles and rectangles in your GUI. Solve each of this, then combine them. – Joe Apr 25 '20 at 10:00
  • they use matchTemplate from openCv , they are using matplot , I'm using implemented function and i should display the image on a label on GUI – Hassan Bosha Apr 25 '20 at 10:05
  • Your "implemented function" is something that you find as very simple example in the documentation to [scipy.signal.correlate2d](https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.signal.correlate2d.html). The line `y = np.empty(x.shape)` does not do anything. Ok, then from the list I mentioned above, you did 2.), now do the other parts. Google them separately and you will find plenty examples for your GUI toolkit. Then combine the three things. – Joe Apr 25 '20 at 12:04
  • is there any useful link for how to draw a shape on an image on the label in the GUI – Hassan Bosha Apr 25 '20 at 14:06
  • https://github.com/sbme-tutorials/sbme-tutorials.github.io/blob/master/2020/cv/notebooks/template_matching.ipynb , this link works with it , but with plotting not GUI – Hassan Bosha Apr 25 '20 at 14:07
  • which GUI toolkit are you using? Qt, wx, GTK, SWT? You can find a useful link by googling "your toolkit name draw circle" – Joe Apr 25 '20 at 14:18

0 Answers0