在python中使用openCV和Tesseract从图像中提取主标题

2024-06-12 01:27:31 发布

您现在位置:Python中文网/ 问答频道 /正文

this is the input image

现在我想使用openCV和tesseract来提取图像的标题

预期输出--

[演示药品分销商]

请帮忙


Tags: 图像标题opencv分销商tesseract药品
1条回答
网友
1楼 · 发布于 2024-06-12 01:27:31

正如我所说,该代码用于其他用途,但我认为它可以为您提供一段很好的代码

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

相关问题 更多 >