n0no123 commited on
Commit
c1d54c1
1 Parent(s): ab73231

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +49 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ from matplotlib import pyplot as plt
3
+ import gradio as gr
4
+
5
+
6
+ def my_app(img):
7
+ # Opening image
8
+ # img = cv2.imread("image.jpg")
9
+
10
+ # OpenCV opens images as BRG
11
+ # but we want it as RGB We'll
12
+ # also need a grayscale version
13
+ img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
14
+ img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
15
+
16
+
17
+ # Use minSize because for not
18
+ # bothering with extra-small
19
+ # dots that would look like STOP signs
20
+ stop_data = cv2.CascadeClassifier('stop_data.xml')
21
+
22
+ found = stop_data.detectMultiScale(img_gray,
23
+ minSize=(20, 20))
24
+
25
+ # Don't do anything if there's
26
+ # no sign
27
+ amount_found = len(found)
28
+
29
+ if amount_found != 0:
30
+
31
+ # There may be more than one
32
+ # sign in the image
33
+ for (x, y, width, height) in found:
34
+
35
+ # We draw a green rectangle around
36
+ # every recognized sign
37
+ cv2.rectangle(img_rgb, (x, y),
38
+ (x + height, y + width),
39
+ (0, 255, 0), 5)
40
+
41
+ # Creates the environment of
42
+ # the picture and shows it
43
+ plt.subplot(1, 1, 1)
44
+ plt.imshow(img_rgb)
45
+ plt.show()
46
+
47
+
48
+ gr.interface.Interface(fn=my_app, live=True, inputs=gr.Image(
49
+ source='webcam', streaming=True), outputs="text").launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ opencv-python
2
+ matplotlib
3
+ gradio