Vikas01 commited on
Commit
6ae34d7
·
1 Parent(s): 7eed370

Update app.py

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