簡體   English   中英

在 python 中使用 openCV 和 Tesseract 從圖像中提取主標題

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

這是輸入圖像

現在我想使用 openCV 和 tesseract 來提取圖像的標題。

預計 Output --

[演示葯品經銷商]

請幫忙

正如我所說,該代碼用於其他用途,但我認為它可以為您提供一段很好的代碼。

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