Answer the question
In order to leave comments, you need to log in
How to do pattern search and selection in OpenCV?
I can't figure out what's wrong?
I 'm
looking for
a picture in a picture, but the highlights are not where they should be .
I tried all the search methods
. Please tell me
code:
import cv2
method = cv2.TM_CCOEFF
small_image = cv2.imread('shab4.png') # что ищу
large_image = cv2.imread('output.png') # где ищу
result = cv2.matchTemplate(small_image, large_image, method)
mn,_,mnLoc,_ = cv2.minMaxLoc(result)
MPx,MPy = mnLoc
trows,tcols = small_image.shape[:2]
cv2.rectangle(large_image, (MPx,MPy),(MPx+tcols,MPy+trows),(0,0,255),5)
res = cv2.resize(large_image, dsize=(2500,2500))
cv2.namedWindow("Resized", cv2.WINDOW_NORMAL)
cv2.imshow("Resized", res)
cv2.waitKey(0)
import cv2
method = cv2.CHAIN_APPROX_SIMPLE
small_image = cv2.imread('shab.png')
large_image = cv2.imread('output.png')
result = cv2.matchTemplate(small_image, large_image, method)
mn,_,mnLoc,_ = cv2.minMaxLoc(result)
MPx,MPy = mnLoc
trows,tcols = small_image.shape[:2]
h = (MPx + tcols//2)
v = (MPy + trows//2)
cv2.line(large_image, (MPx, (MPy+MPy+trows)//2), (MPx+tcols, (MPy+MPy+trows)//2), (0,255,255), thickness=10, lineType=8, shift=0)
cv2.imwrite('one.jpg', large_image)
res = cv2.resize(large_image, dsize=(2500,2500))
cv2.namedWindow("Resized", cv2.WINDOW_NORMAL)
cv2.imshow("Resized", res)
cv2.waitKey(0)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question