[英]How can I get only the numbers from the image using tesseract in python?
This is the original image这是原图
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
This is the best I have achieved with the code above这是我用上面的代码实现的最好的
I would make it much simpler than that:我会让它比那简单得多:
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.