Skip to content

Instantly share code, notes, and snippets.

@aniruddha27
Created April 25, 2020 09:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aniruddha27/48869a2020c3526cecf20c93df7a20e8 to your computer and use it in GitHub Desktop.
Save aniruddha27/48869a2020c3526cecf20c93df7a20e8 to your computer and use it in GitHub Desktop.
# text detection
def contours_text(orig, img, contours):
for cnt in contours:
x, y, w, h = cv2.boundingRect(cnt)
# Drawing a rectangle on copied image
rect = cv2.rectangle(orig, (x, y), (x + w, y + h), (0, 255, 255), 2)
cv2.imshow('cnt',rect)
cv2.waitKey()
# Cropping the text block for giving input to OCR
cropped = orig[y:y + h, x:x + w]
# Apply OCR on the cropped image
config = ('-l eng --oem 1 --psm 3')
text = pytesseract.image_to_string(cropped, config=config)
print(text)
@hieudx149
Copy link

what is the img paramenter for?
and what is the orig paramenter when i call contours_text function ?

@Olamilekan002
Copy link

I think orig should be the original image and img should be the transformed image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment