简体   繁体   English

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

[英]extract the main heading from the image using openCV and Tesseract in python

这是输入图像

now i want to use openCV and tesseract to extract the title of the image.现在我想使用 openCV 和 tesseract 来提取图像的标题。

Expected Output --预计 Output --

[ Demo Pharma Distributors ] [演示药品经销商]

Please Help请帮忙

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM