0

Basically I'm trying to measure the displacemtent of the template along of the next image. I extract the roi of the image at t0, then I apply matchTemplate function on the image at t1 and finally use the euclidean distance. Here is that part of the code:

#template first point[50:100, 150:200]
x1 = 150
y1 = 50
#top_left point of template matching
x2 = 149
y2 = 53
euc_dist = np.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

Is this a pythonic way to do? I think that is a little bit complicated approximation.

Chacho Fuva
  • 353
  • 1
  • 4
  • 17
  • 1
    Yes, that's the right way to do it. – rayryeng Jul 08 '20 at 01:48
  • There's not another way to make the approach? Or maybe improve it, like use a centroid in the template? – Chacho Fuva Jul 08 '20 at 19:20
  • Template matching gives you the top left corner of where the template matches. Why would you want to use the centroid? But there's no other way to estimate the displacement with `cv2.matchTemplate`. Template matching gives you a response of where the template best matched. You find the largest location in this map, then find the distance to this location. Even the OpenCV docs in their example show you that this is the way. I don't see what other way could be more efficient. https://stackoverflow.com/a/14417703/3250829 – rayryeng Jul 08 '20 at 20:28

0 Answers0