Update app.py
Browse filesI have changed the code to previous version i.e. detect hands
app.py
CHANGED
@@ -248,51 +248,71 @@ output_text = ""
|
|
248 |
if "output_text" not in st.session_state:
|
249 |
st.session_state["output_text"] = ""
|
250 |
|
251 |
-
def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
252 |
-
global indexImg, output_text
|
253 |
|
|
|
254 |
img = frame.to_ndarray(format="bgr24")
|
255 |
-
|
256 |
-
hands, imgOut = detector.findHands(imgOut, flipType=False)
|
257 |
|
258 |
-
|
259 |
|
260 |
-
detections = []
|
261 |
if hands:
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
|
297 |
webrtc_streamer(
|
298 |
key="virtual-keyboard",
|
|
|
248 |
if "output_text" not in st.session_state:
|
249 |
st.session_state["output_text"] = ""
|
250 |
|
|
|
|
|
251 |
|
252 |
+
def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
253 |
img = frame.to_ndarray(format="bgr24")
|
254 |
+
hands, img = detector.findHands(img, flipType=False)
|
|
|
255 |
|
256 |
+
# Render hand detection results
|
257 |
|
|
|
258 |
if hands:
|
259 |
+
hand = hands[0]
|
260 |
+
bbox = hand["bbox"]
|
261 |
+
cv2.rectangle(img, (bbox[0], bbox[1]), (bbox[0]+bbox[2], bbox[1]+bbox[3]), (255, 0, 0), 2)
|
262 |
+
|
263 |
+
cv2.putText(img, 'OpenCV', (50,50), font,
|
264 |
+
fontScale, color, thickness, cv2.LINE_AA)
|
265 |
+
cv2.putText(img, 'OpenCV', (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 255, 255), 1, cv2.LINE_AA)
|
266 |
+
|
267 |
+
result_queue.put(hands)
|
268 |
+
|
269 |
+
# def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
270 |
+
# global indexImg, output_text
|
271 |
+
|
272 |
+
# img = frame.to_ndarray(format="bgr24")
|
273 |
+
# imgOut = segmentor.removeBG(img, imgList[indexImg])
|
274 |
+
# hands, imgOut = detector.findHands(imgOut, flipType=False)
|
275 |
+
|
276 |
+
# buttonList = [Button([30 + col * 105, 30 + row * 120], key) for row, line in enumerate(keys) for col, key in enumerate(line)]
|
277 |
+
|
278 |
+
# detections = []
|
279 |
+
# if hands:
|
280 |
+
# for i, hand in enumerate(hands):
|
281 |
+
# lmList = hand['lmList']
|
282 |
+
# bbox = hand['bbox']
|
283 |
+
# label = "Hand"
|
284 |
+
# score = hand['score']
|
285 |
+
# box = np.array([bbox[0], bbox[1], bbox[0] + bbox[2], bbox[1] + bbox[3]])
|
286 |
+
# detections.append(Detection(label=label, score=score, box=box))
|
287 |
+
|
288 |
+
# if lmList:
|
289 |
+
# x4, y4 = lmList[4][0], lmList[4][1]
|
290 |
+
# x8, y8 = lmList[8][0], lmList[8][1]
|
291 |
+
# distance = np.sqrt((x8 - x4) ** 2 + (y8 - y4) ** 2)
|
292 |
+
# click_threshold = 10
|
293 |
+
|
294 |
+
# for button in buttonList:
|
295 |
+
# x, y = button.pos
|
296 |
+
# w, h = button.size
|
297 |
+
# if x < x8 < x + w and y < y8 < y + h:
|
298 |
+
# cv2.rectangle(imgOut, button.pos, (x + w, y + h), (0, 255, 160), -1)
|
299 |
+
# cv2.putText(imgOut, button.text, (x + 20, y + 70), cv2.FONT_HERSHEY_PLAIN, 5, (255, 255, 255), 3)
|
300 |
+
|
301 |
+
# if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
|
302 |
+
# if time.time() - prev_key_time[i] > 2:
|
303 |
+
# prev_key_time[i] = time.time()
|
304 |
+
# if button.text != 'BS' and button.text != 'SPACE':
|
305 |
+
# output_text += button.text
|
306 |
+
# elif button.text == 'BS':
|
307 |
+
# output_text = output_text[:-1]
|
308 |
+
# else:
|
309 |
+
# output_text += ' '
|
310 |
+
|
311 |
+
# result_queue.put(detections)
|
312 |
+
# st.session_state["output_text"] = output_text
|
313 |
+
# return av.VideoFrame.from_ndarray(imgOut, format="bgr24")
|
314 |
+
|
315 |
+
|
316 |
|
317 |
webrtc_streamer(
|
318 |
key="virtual-keyboard",
|