I am trying to get the number below a barcode in an image. I have tried the same code with some other images and works fine but not for that image Here's the image 
And here is the code till now
def readNumber(): image = cv2.imread(sTemp) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(gray, (3,3), 0) thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1] kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3)) opening = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel, iterations=1) invert = 255 - opening data = pytesseract.image_to_string(invert, lang='eng', config='--psm 6 -c tessedit_char_whitelist=0123456789') print(data) try: data = re.findall('(\d{9})\D', data)[0] except: data = '' return data And I used it using this line
readNumber() https://stackoverflow.com/questions/66126756/read-text-below-barcode-pytesseract-python February 10, 2021 at 04:38AM

没有评论:
发表评论