[英]extract the main heading from the image using openCV and Tesseract in python
正如我所說,該代碼用於其他用途,但我認為它可以為您提供一段很好的代碼。
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.