[英]Can't get numbers from image with python, Tesseract and opencv
[英]How can I get only the numbers from the image using tesseract in python?
這是原圖
def extract_number(video_name):
global read
img = cv2.imread(video_name)
HSV_image = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(HSV_image)
s = cv2.GaussianBlur(s, (1, 1), 0)
thresh = cv2.threshold(
s, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
cv2.imwrite('{}.png'.format(video_name), thresh)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, ksize=(1, 2))
thresh = cv2.dilate(thresh, kernel)
txt = image_to_string(thresh, config='--oem 1 --psm 13')
return txt
這是我用上面的代碼實現的最好的
我會讓它比那簡單得多:
def extract_number(your_image):
# open the image
img = cv2.imread(your_image)
# turn it to a binary image, no need to save it.
[ret, binary_image] = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY)
# turn it into text (you are probably going to have issues depending on the image)
txt = image_to_string(binary_image, config='--oem 1 --psm 13')
return txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.