A
A
apiwi2021-11-13 16:59:54
Python
apiwi, 2021-11-13 16:59:54

How to find specific text in an OpenCV image?

Here is the code, I'm trying to find the text in the picture, but it doesn't work, as I understand it, the comparison method is not suitable.
Tk, he finds the picture in the picture easily. Please tell me how to fix

import cv2

#TM_SQDIFF_NORMED
method = cv2.TM_SQDIFF_NORMED
small_image = cv2.imread('shab.png', 0) # что ищу
large_image = cv2.imread('output.png', 0) # где ищу
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),10)
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

2 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)

C
calculator212, 2021-11-14
@calculator212

Here is the code, I'm trying to find the text in the picture, but it doesn't work, as I understand it, the method is not suitable
Need tesseract for this and opencv

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question