Skip to content

Instantly share code, notes, and snippets.

@paulwababu
Created February 5, 2023 09:10
Show Gist options
  • Save paulwababu/95b80e2eebf300150cc2faaf201261c6 to your computer and use it in GitHub Desktop.
Save paulwababu/95b80e2eebf300150cc2faaf201261c6 to your computer and use it in GitHub Desktop.
import pytesseract
import cv2
# Read the ID image into memory
image = cv2.imread("polo.jpg")
# Pre-process the image by converting it to grayscale and applying thresholding
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
# Run OCR on the pre-processed image
text = pytesseract.image_to_string(thresh, lang="eng")
print(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment