Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,78 +6,86 @@ import pandas as pd
|
|
6 |
import time
|
7 |
import os.path
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
cv2.
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
cv2.drawContours(
|
35 |
-
# cv2.imshow("
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
#
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
df.
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
import time
|
7 |
import os.path
|
8 |
|
9 |
+
import io
|
10 |
+
import streamlit as st
|
11 |
+
bytes_data=None
|
12 |
+
|
13 |
+
img_file_buffer=st.camera_input("Take a picture")
|
14 |
+
if img_file_buffer is not None:
|
15 |
+
|
16 |
+
test_image = Image.open(img_file_buffer)
|
17 |
+
image = imutils.resize(test_image, width=500)
|
18 |
+
|
19 |
+
cv2.imshow("Original Image", image)
|
20 |
+
|
21 |
+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
22 |
+
#cv2.imshow("1 - Grayed image", gray)
|
23 |
+
|
24 |
+
gray = cv2.bilateralFilter(gray, 11, 17, 17)
|
25 |
+
#cv2.imshow("2 - Smoothened image", gray)
|
26 |
+
|
27 |
+
edged = cv2.Canny(gray, 170, 200)
|
28 |
+
# cv2.imshow("3 - Edged image", edged)
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
cnts,new=cv2.findContours(edged.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
|
33 |
+
image1=image.copy()
|
34 |
+
cv2.drawContours(image1,cnts,-1,(0,255,0),3)
|
35 |
+
# cv2.imshow("countours",image1)
|
36 |
+
|
37 |
+
cnts=sorted(cnts,key=cv2.contourArea,reverse=True)[:30]
|
38 |
+
screenCnt=None
|
39 |
+
image2=image.copy()
|
40 |
+
cv2.drawContours(image2,cnts,-1,(0,0,255),3)
|
41 |
+
# cv2.imshow("Top 30 contours",image2)
|
42 |
+
|
43 |
+
i=1
|
44 |
+
for c in cnts:
|
45 |
+
perimeter = cv2.arcLength(c, True)
|
46 |
+
approx = cv2.approxPolyDP(c, 0.018 * perimeter, True)
|
47 |
+
if len(approx) == 4:
|
48 |
+
screenCnt = approx
|
49 |
+
|
50 |
+
x,y,w,h = cv2.boundingRect(c)
|
51 |
+
new_img=image[y:y+h,x:x+w]
|
52 |
+
cv2.imwrite('./'+str(i)+'.png',new_img)
|
53 |
+
i+=1
|
54 |
+
break
|
55 |
+
|
56 |
+
cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 3)
|
57 |
+
# cv2.imshow("image with detected license plate", image)
|
58 |
+
|
59 |
+
Cropped_loc = './1.png'
|
60 |
+
cv2.imshow("cropped", cv2.imread(Cropped_loc))
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
# Configuration for tesseract
|
65 |
+
pytesseract.pytesseract.tesseract_cmd=r"D:\number plate\tessract\tesseract.exe"
|
66 |
+
|
67 |
+
# Run tesseract OCR on image
|
68 |
+
text = pytesseract.image_to_string(Cropped_loc,lang="eng")
|
69 |
+
|
70 |
+
#Data is stored in CSV file
|
71 |
+
raw_data = {'date': [time.asctime( time.localtime(time.time()) )],'v_number': [text] }
|
72 |
+
|
73 |
+
df = pd.DataFrame(raw_data, columns = ['date', 'v_number'])
|
74 |
+
|
75 |
+
file_path = 'data.csv'
|
76 |
+
header = not os.path.exists(file_path) # Check if the file exists and set header flag accordingly
|
77 |
+
|
78 |
+
|
79 |
+
df.to_csv('data.csv',mode='a',header=header,index=False)
|
80 |
+
"""the mode='a' parameter ensures that each new entry is appended to the existing CSV
|
81 |
+
file instead of replacing it. The header=False parameter prevents the column headers
|
82 |
+
from being written repeatedly when appending entries. The index=False parameter
|
83 |
+
excludes the index column from being written to the CSV file."""
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
# Print recognized text
|
88 |
+
print(text)
|
89 |
+
cv2.waitKey(0)
|
90 |
+
if bytes_data is None:
|
91 |
+
st.stop()
|