BilalSardar commited on
Commit
7a25466
·
1 Parent(s): 466c167

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -1,5 +1,8 @@
1
  import cv2
2
  import gradio as gr
 
 
 
3
  thres = 0.45 # Threshold to detect object
4
 
5
 
@@ -36,6 +39,30 @@ def Detection(filename):
36
 
37
  while True:
38
  success,img = cap.read()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  try:
40
  classIds, confs, bbox = net.detect(img,confThreshold=thres)
41
  except:
@@ -72,5 +99,5 @@ def Detection(filename):
72
  interface = gr.Interface(fn=Detection,
73
  inputs=["video"],
74
  outputs="text",
75
- title='Object Detection in Video')
76
  interface.launch(inline=False,debug=True)
 
1
  import cv2
2
  import gradio as gr
3
+ import fast_colorthief
4
+ import webcolors
5
+ from PIL import Image
6
  thres = 0.45 # Threshold to detect object
7
 
8
 
 
39
 
40
  while True:
41
  success,img = cap.read()
42
+
43
+
44
+
45
+ # #Colour
46
+ try:
47
+ image = Image.fromarray(img)
48
+ image = image.convert('RGBA')
49
+ image = np.array(image).astype(np.uint8)
50
+ palette=fast_colorthief.get_palette(image)
51
+
52
+
53
+ for i in range(len(palette)):
54
+ diff={}
55
+ for color_hex, color_name in webcolors.CSS3_HEX_TO_NAMES.items():
56
+ r, g, b = webcolors.hex_to_rgb(color_hex)
57
+ diff[sum([(r - palette[i][0])**2,
58
+ (g - palette[i][1])**2,
59
+ (b - palette[i][2])**2])]= color_name
60
+ if FinalItems.count(diff[min(diff.keys())])==0:
61
+ FinalItems.append(diff[min(diff.keys())])
62
+
63
+ except:
64
+ pass
65
+
66
  try:
67
  classIds, confs, bbox = net.detect(img,confThreshold=thres)
68
  except:
 
99
  interface = gr.Interface(fn=Detection,
100
  inputs=["video"],
101
  outputs="text",
102
+ title='Object & Color Detection in Video')
103
  interface.launch(inline=False,debug=True)