Update app.py
Browse files
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 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
107 |
if hands:
|
108 |
hand = hands[0]
|
109 |
bbox = hand["bbox"]
|
110 |
-
cv2.rectangle(img,
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
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 |
|