A
A
apiwi2021-11-13 02:59:02
OpenCV
apiwi, 2021-11-13 02:59:02

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:

618efe8514fc0717267397.png
618efea0a1b0b492171328.png
618efed6791b4042289703.png

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)


I also tried just underlining the name of the group. It also went wrong
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

1 answer(s)
A
apiwi, 2021-11-17
@apiwi

Solved the issue with: pdfminer, pdf2image, PIL
Found the coordinates of the desired text using pdfminer, converted it to an image using pdf2image and using PIL cropped the desired area (added values ​​to the coordinates)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question