Feb 21, 2024 03:45 PM
(This post was last modified: Feb 21, 2024 03:50 PM by LatestGreatestPro.)
Hello all,
I recently joined this forum and upgraded and I love it here!
Anyways, my issue is i have shipping labels from UPS for my business and I want to use a script in python to extract the name of the recipient on the shipping label, the reference numbers, and the tracking number. Issue is when I run this script:
It’s inaccurate as shipping labels have different font sizes and the text can be quite close to each others (horizontally)
I recently joined this forum and upgraded and I love it here!
Anyways, my issue is i have shipping labels from UPS for my business and I want to use a script in python to extract the name of the recipient on the shipping label, the reference numbers, and the tracking number. Issue is when I run this script:
Code
import cv2
import pytesseract
# Load image
img = cv2.imread("example_image.jpg")
# Convert image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Apply threshold to convert to binary image
threshold_img = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
# Pass the image through pytesseract
text = pytesseract.image_to_string(threshold_img)
# Print the extracted text
print(text)It’s inaccurate as shipping labels have different font sizes and the text can be quite close to each others (horizontally)




![[Image: 12XdAdJ.gif]](https://i.imgur.com/12XdAdJ.gif)