Spaces:
Configuration error
Configuration error
Commit ·
3fbf9d4
1
Parent(s): 1dfe1a9
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import cv2
|
| 2 |
import gradio as gr
|
| 3 |
-
from google.colab.patches import cv2_imshow
|
| 4 |
thres = 0.45 # Threshold to detect object
|
| 5 |
|
| 6 |
|
|
@@ -12,7 +11,7 @@ def Detection(filename):
|
|
| 12 |
cap.set(4,720)
|
| 13 |
cap.set(10,70)
|
| 14 |
|
| 15 |
-
error="
|
| 16 |
classNames= []
|
| 17 |
FinalItems=[]
|
| 18 |
classFile = 'coco.names'
|
|
@@ -35,33 +34,32 @@ def Detection(filename):
|
|
| 35 |
net.setInputSwapRB(True)
|
| 36 |
|
| 37 |
while True:
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
cv2_imshow(img)
|
| 58 |
-
cv2.waitKey(10)
|
| 59 |
-
except Exception as err:
|
| 60 |
-
print(err)
|
| 61 |
-
t=str(err)
|
| 62 |
-
if t.__contains__(error):
|
| 63 |
-
break
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
print(FinalItems)
|
| 67 |
return str(FinalItems)
|
|
|
|
| 1 |
import cv2
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
thres = 0.45 # Threshold to detect object
|
| 4 |
|
| 5 |
|
|
|
|
| 11 |
cap.set(4,720)
|
| 12 |
cap.set(10,70)
|
| 13 |
|
| 14 |
+
error="in function 'cv::imshow'"
|
| 15 |
classNames= []
|
| 16 |
FinalItems=[]
|
| 17 |
classFile = 'coco.names'
|
|
|
|
| 34 |
net.setInputSwapRB(True)
|
| 35 |
|
| 36 |
while True:
|
| 37 |
+
success,img = cap.read()
|
| 38 |
+
try:
|
| 39 |
+
classIds, confs, bbox = net.detect(img,confThreshold=thres)
|
| 40 |
+
except:
|
| 41 |
+
pass
|
| 42 |
+
print(classIds,bbox)
|
| 43 |
+
try:
|
| 44 |
+
if len(classIds) != 0:
|
| 45 |
+
for classId, confidence,box in zip(classIds.flatten(),confs.flatten(),bbox):
|
| 46 |
+
|
| 47 |
+
cv2.rectangle(img,box,color=(0,255,0),thickness=2)
|
| 48 |
+
cv2.putText(img,classNames[classId-1].upper(),(box[0]+10,box[1]+30),
|
| 49 |
+
cv2.FONT_HERSHEY_COMPLEX,1,(0,255,0),2)
|
| 50 |
+
cv2.putText(img,str(round(confidence*100,2)),(box[0]+200,box[1]+30),
|
| 51 |
+
cv2.FONT_HERSHEY_COMPLEX,1,(0,255,0),2)
|
| 52 |
+
if FinalItems.count(classNames[classId-1]) == 0:
|
| 53 |
+
FinalItems.append(classNames[classId-1])
|
| 54 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
cv2.imshow("Output",img)
|
| 57 |
+
cv2.waitKey(10)
|
| 58 |
+
except Exception as err:
|
| 59 |
+
print(err)
|
| 60 |
+
t=str(err)
|
| 61 |
+
if t.__contains__(error):
|
| 62 |
+
break
|
| 63 |
|
| 64 |
print(FinalItems)
|
| 65 |
return str(FinalItems)
|