diff --git a/CarPlateDetection.py b/CarPlateDetection.py index d20880f..6a0a4cc 100644 --- a/CarPlateDetection.py +++ b/CarPlateDetection.py @@ -1,6 +1,7 @@ import numpy as np import cv2 import imutils +import pytesseract # Read the image file image = cv2.imread('Car_Image_1.jpg') @@ -24,7 +25,7 @@ cv2.imshow("4 - Canny Edges", edged) # Find contours based on Edges -(new, cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) +( cnts, _) = cv2.findContours(edges.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) cnts=sorted(cnts, key = cv2.contourArea, reverse = True)[:30] #sort contours based on their area keeping minimum required area as '30' (anything smaller than this will not be considered) NumberPlateCnt = None #we currently have no Number plate contour @@ -39,7 +40,19 @@ # Drawing the selected contour on the original image -cv2.drawContours(image, [NumberPlateCnt], -1, (0,255,0), 3) -cv2.imshow("Final Image With Number Plate Detected", image) - -cv2.waitKey(0) #Wait for user input before closing the images displayed \ No newline at end of file +mask = np.zeros(gray_img.shape,np.uint8) +new_image = cv2.drawContours(mask,[NumberPlateCnt],0,255,-1) +new_image = cv2.bitwise_and(img,img,mask=mask) +cv2.namedWindow("Final_image",cv2.WINDOW_NORMAL) +cv2.imshow("Final_image",new_image) + +# Configuration for tesseract +config = ('-l eng --oem 1 --psm 3') +pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract' +# Run tesseract OCR on image +text = pytesseract.image_to_string(new_image, config=config) + +# Print number on plate +print(text) + +cv2.waitKey(0) #Wait for user input before closing the images displayed