Pratyush101 commited on
Commit
cb8aa2b
·
verified ·
1 Parent(s): 76cc581

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -101,21 +101,31 @@ result_queue = queue.Queue()
101
 
102
  def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
103
  img = frame.to_ndarray(format="bgr24")
104
- hands, img = detector.findHands(img, flipType=False)
105
-
106
- # Render hand detection results
 
 
 
 
107
  if hands:
108
  hand = hands[0]
109
  bbox = hand["bbox"]
110
- cv2.rectangle(img, (bbox[0], bbox[1]), (bbox[0]+bbox[2], bbox[1]+bbox[3]), (255, 0, 0), 2)
111
-
112
- cv2.putText(img, 'OpenCV', (50,50), font,
113
- fontScale, color, thickness, cv2.LINE_AA)
114
- cv2.putText(img, 'OpenCV', (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 255, 255), 1, cv2.LINE_AA)
115
-
116
- result_queue.put(hands)
117
-
118
-
 
 
 
 
 
 
119
  return av.VideoFrame.from_ndarray(img, format="bgr24")
120
 
121
 
 
101
 
102
  def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
103
  img = frame.to_ndarray(format="bgr24")
104
+
105
+ # Ensure dimensions are provided or preprocess image
106
+ height, width, _ = img.shape
107
+
108
+ # Try passing image dimensions explicitly
109
+ hands, img = detector.findHands(img, flipType=False, imgDim=(width, height))
110
+
111
  if hands:
112
  hand = hands[0]
113
  bbox = hand["bbox"]
114
+ cv2.rectangle(img,
115
+ (bbox[0], bbox[1]),
116
+ (bbox[0] + bbox[2], bbox[1] + bbox[3]),
117
+ (255, 0, 0), 2)
118
+
119
+ # Render text once
120
+ font = cv2.FONT_HERSHEY_SIMPLEX
121
+ fontScale = 2
122
+ color = (255, 255, 255)
123
+ thickness = 2
124
+ cv2.putText(img, 'OpenCV', (50, 50), font, fontScale, color, thickness, cv2.LINE_AA)
125
+
126
+ # Pass simplified results to the queue
127
+ result_queue.put({"bbox": bbox, "landmarks": hand["landmarks"]})
128
+
129
  return av.VideoFrame.from_ndarray(img, format="bgr24")
130
 
131