[英]extract the main heading from the image using openCV and Tesseract in python
As I said, the code was used for something else but I think it can give you a nice piece of code to work with.正如我所说,该代码用于其他用途,但我认为它可以为您提供一段很好的代码。
import numpy as np
from PIL import ImageGrab
from PIL import Image
import cv2
import time
import pytesseract
p1 = 520
p2 = 760
p3 = 1450
p4 = 830
# Those points are pixel points you will need to adjust for your frame
while(True):
frame = np.array(ImageGrab.grab(bbox=(p1 ,p2 , p3, p4)))
frame = cv2.bitwise_not(frame)
cv2.imshow("window", frame)
pytesseract.pytesseract.tesseract_cmd = r'Path\to\tesseract.exe'
txt = pytesseract.image_to_string(frame)
str_num = re.findall(r'.*', txt)
print(txt)
print(str_num)
print("-----------")
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.