├── test_images ├── car1.jpeg └── car2.jpg ├── README.md ├── data.csv └── main.py /test_images/car1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanmathik/Indian-License-Plate-Recognition-/HEAD/test_images/car1.jpeg -------------------------------------------------------------------------------- /test_images/car2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanmathik/Indian-License-Plate-Recognition-/HEAD/test_images/car2.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Indian-License-Plate-Recognition- 2 | Indian license plate built using python, opencv and tesseract 3 | 4 | This system will store the license plate along with the date and store it in a csv file. 5 | # Versions 6 | Python 2.7 7 | Opencv 3.4 8 | Tesseract 4 9 | Pandas 0.2 10 | 11 | # Screenshot 12 | 13 | ![Screenshot](https://user-images.githubusercontent.com/42826862/59154117-7125d180-8a88-11e9-99a5-a3b437ce48a0.PNG) 14 | 15 | -------------------------------------------------------------------------------- /data.csv: -------------------------------------------------------------------------------- 1 | sl.no,Date and Time,,vehicle_number 2 | , 3 | 0,MH1IZDE1433 4 | ,,date 5 | 0,MH1IZDE1433,Mon May 6 10:26:43 2019 6 | ,,date 7 | 0,MH1IZDE1433,Sun Jun 9 07:12:17 2019 8 | ,,date 9 | 0,MH1IZDE1433,Sun Jun 9 07:15:06 2019 10 | ,,date 11 | 0,MH1IZDE1433,Sun Jun 9 07:15:50 2019 12 | ,,date 13 | 0,MH1IZDE1433,Sun Jun 9 07:17:47 2019 14 | ,,date 15 | 0,MH1IZDE1433,Sun Jun 9 07:18:13 2019 16 | ,,date 17 | 0,MH1IZDE1433,Sun Jun 9 07:20:00 2019 18 | ,,date 19 | 0,MH1IZDE1433,Sun Jun 9 07:22:08 2019 20 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | import imutils 4 | import sys 5 | import pytesseract 6 | import pandas as pd 7 | import time 8 | 9 | pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe" 10 | image = cv2.imread('car.jpeg') 11 | 12 | image = imutils.resize(image, width=500) 13 | 14 | cv2.imshow("Original Image", image) 15 | 16 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 17 | cv2.imshow("1 - Grayscale Conversion", gray)#1 18 | 19 | gray = cv2.bilateralFilter(gray, 11, 17, 17) 20 | cv2.imshow("2 - Bilateral Filter", gray)#2 21 | 22 | edged = cv2.Canny(gray, 170, 200) 23 | cv2.imshow("4 - Canny Edges", edged)#3 24 | 25 | cv2.waitKey(0) 26 | cv2.destroyAllWindows()#4 27 | 28 | (cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)#removed new 29 | #cv2.imshow("check",edged)#5 30 | cnts=sorted(cnts, key = cv2.contourArea, reverse = True)[:30] 31 | NumberPlateCnt = None 32 | 33 | count = 0 34 | for c in cnts: 35 | peri = cv2.arcLength(c, True) 36 | approx = cv2.approxPolyDP(c, 0.02 * peri, True) 37 | if len(approx) == 4: 38 | NumberPlateCnt = approx 39 | break 40 | #checker 41 | """cv2.drawContours(image, cnts, -1, (0, 0, 255), 5) 42 | 43 | # display original image with contours 44 | cv2.namedWindow("output", cv2.WINDOW_NORMAL) 45 | cv2.imshow("output", image) 46 | cv2.waitKey(0) 47 | cv2.drawContours(edged, [NumberPlateCnt], -1, (0,255,0), 3) 48 | cv2.imshow("checker again",edged)""" 49 | #checker 50 | 51 | # Masking the part other than the number plate 52 | mask = np.zeros(gray.shape,np.uint8) 53 | new_image = cv2.drawContours(mask,[NumberPlateCnt],0,255,-1) 54 | new_image = cv2.bitwise_and(image,image,mask=mask) 55 | #cv2.imshow("lets see",new_image)#6 56 | cv2.namedWindow("Final_image",cv2.WINDOW_NORMAL) 57 | cv2.imshow("Final_image",new_image) 58 | 59 | # Configuration for tesseract 60 | config = ('-l eng --oem 1 --psm 3') 61 | 62 | # Run tesseract OCR on image 63 | text = pytesseract.image_to_string(new_image, config=config) 64 | #print(text)#5 65 | 66 | #Data is stored in CSV file 67 | raw_data = {'date':[time.asctime( time.localtime(time.time()))],'':[text]} 68 | #raw_data = [time.asctime( time.localtime(time.time()))],[text] 69 | 70 | df = pd.DataFrame(raw_data) 71 | df.to_csv('data.csv',mode='a') 72 | 73 | # Print recognized text 74 | print(text) 75 | 76 | cv2.waitKey(0) 77 | cv2.destroyAllWindows()#4 78 | --------------------------------------------------------------------------------