OpenCV Template Matching: Restrict search area
Asked Answered
F

1

6

I have working OpenCV template matching code made with python. Now I am searching for a way to tell OpenCV to search only in a supplied area (x, y, w, h), is that possible?

Regards, Philip

Fungistat answered 19/12, 2013 at 13:59 Comment(0)
I
6
roi = image[y:y+h , x:x+w]

cv2.matchTemplate(roi, templ, ...
Ingunna answered 19/12, 2013 at 14:3 Comment(7)
So technically I just create a new image out of the original and then search in it?Fungistat
it's just a subrect of the original image ( so, not a copy, if you were asking this )Ingunna
Problem is I get a NameError: global name 'y' is not definedFungistat
hey, ofc. you've got to replace x,y,w,h with your numbers thereIngunna
I don't get it. So I if I have a image called template that is made with cv2.imread() I just do roi = template[10,10,10,10] and then I have a 10x10 sized chunk starting at coordinates X:10 and Y:10?Fungistat
make it: template[10:20, 10:20] thenIngunna
Please, complete your answer with a full formula and ideally a working example.Lucullus

© 2022 - 2024 — McMap. All rights reserved.