Write a python program e to aapplyfor a drivers lisece
Answers
Answer:
# to the command
class Text_Extractor():
#Constructor
def __init__(self,image_file):
self.image_file=image_file
if self is None:
return 0
#Function to extract the text from image as string
def extract_text(self):
try:
image=cv2.imread(self.image_file)
# Convert to gray
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#Resize the image
image = cv2.resize(image, None, fx=2, fy=2)
text=pytesseract.image_to_string(image,config='--tessdata-dir "/usr/local/Cellar/tesseract/4.0.0_1/share/tessdata"')
return text
except Exception as e:
print(str(e))
#class to validate if an image is a drivers licence
class Drivers_Licence_Validator:
#Constructor
def __init__(self,text):
self.text=text
#Function to validate an Indian driving licence
def is_licence(self):
res=self.text.split('/n')
for word in res:
if word=='Driving' or 'DRIVING':
print("Document is a Indian Drivers licence")
return True
else:
print("Document is not a Indian Drivers licence")
print("Please try again with a valid Drivers licence")
return False
#Function to find the age of the licence holder
def age(self,y,m,d):
dob = datetime.date(y,m,d)
today = datetime.date.today()
years = today.year - dob.year
if today.month < dob.month or (today.month == dob.month and today.day < dob.day):
years -= 1
return years
#Function to validate if driving licence is expired or not
def is_valid(self):
if (self.is_licence()):
res=self.text.split()
Explanation: