Skip to content

Instantly share code, notes, and snippets.

@omerfarukdemir
Created November 30, 2022 16:51
Show Gist options
  • Select an option

  • Save omerfarukdemir/03dd8967681eca14ed40c114d8bd0b8d to your computer and use it in GitHub Desktop.

Select an option

Save omerfarukdemir/03dd8967681eca14ed40c114d8bd0b8d to your computer and use it in GitHub Desktop.
Pseudo date/time detector
import cv2
import dateutil.parser
import PIL
import pytesseract
# brew install ffmpeg
# brew install tesseract
# pip install opencv-contrib-python pytesseract imutils python-dateutil
def is_date(value: str) -> bool:
try:
dateutil.parser.parse(value, fuzzy=True)
return True
except ValueError:
return False
image = cv2.imread('example_image_path')
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
data = pytesseract.image_to_data(PIL.Image.fromarray(image), output_type=pytesseract.Output.DICT)
for i, text in enumerate(data['text']):
if (is_date(text)):
(x, y, w, h) = (data['left'][i], data['top'][i], data['width'][i], data['height'][i])
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow('image', image)
cv2.waitKey(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment