修改:低置信度,输出unknown
This commit is contained in:
parent
b435541723
commit
29960f24c2
@ -1,14 +1,8 @@
|
|||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
"""
|
|
||||||
信号设计课程小组设计
|
|
||||||
|
|
||||||
@ by: Leaf
|
|
||||||
@ date: 2022-05-28
|
|
||||||
"""
|
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import mediapipe as mp
|
import mediapipe as mp
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
class HandDetector:
|
class HandDetector:
|
||||||
@ -27,7 +21,7 @@ class HandDetector:
|
|||||||
self.results = None
|
self.results = None
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.max_hands = max_hands
|
self.max_hands = max_hands
|
||||||
self.modelComplex = 1
|
self.modelComplex = False
|
||||||
self.detection_con = detection_con
|
self.detection_con = detection_con
|
||||||
self.min_track_con = min_track_con
|
self.min_track_con = min_track_con
|
||||||
|
|
||||||
@ -79,7 +73,7 @@ class HandDetector:
|
|||||||
px, py = int(lm.x * w), int(lm.y * h)
|
px, py = int(lm.x * w), int(lm.y * h)
|
||||||
x_list.append(px)
|
x_list.append(px)
|
||||||
y_list.append(py)
|
y_list.append(py)
|
||||||
self.lmList.append([px, py])
|
self.lmList.append(np.array([px, py]))
|
||||||
if draw:
|
if draw:
|
||||||
cv2.circle(img, (px, py), 5, (255, 0, 255), cv2.FILLED)
|
cv2.circle(img, (px, py), 5, (255, 0, 255), cv2.FILLED)
|
||||||
x_min, x_max = min(x_list), max(x_list)
|
x_min, x_max = min(x_list), max(x_list)
|
||||||
@ -117,7 +111,9 @@ class HandDetector:
|
|||||||
fingers.append(0)
|
fingers.append(0)
|
||||||
# 4 Fingers
|
# 4 Fingers
|
||||||
for i in range(1, 5):
|
for i in range(1, 5):
|
||||||
if self.lmList[self.tipIds[i]][1] < self.lmList[self.tipIds[i] - 2][1]:
|
# if self.lmList[self.tipIds[i]][1] < self.lmList[self.tipIds[i] - 2][1]:
|
||||||
|
if np.dot(self.lmList[self.tipIds[i]-2]-self.lmList[self.tipIds[i]-3],
|
||||||
|
self.lmList[self.tipIds[i]-1]-self.lmList[self.tipIds[i]-2]) >= 0:
|
||||||
fingers.append(1)
|
fingers.append(1)
|
||||||
else:
|
else:
|
||||||
fingers.append(0)
|
fingers.append(0)
|
||||||
@ -152,8 +148,16 @@ class Main:
|
|||||||
if lm_list:
|
if lm_list:
|
||||||
x_1, y_1 = bbox["bbox"][0], bbox["bbox"][1]
|
x_1, y_1 = bbox["bbox"][0], bbox["bbox"][1]
|
||||||
x1, x2, x3, x4, x5 = self.detector.fingers_up()
|
x1, x2, x3, x4, x5 = self.detector.fingers_up()
|
||||||
|
if (np.linalg.norm(lm_list[4]-lm_list[8]) < 50) and (np.linalg.norm(lm_list[4]-lm_list[12]) < 50):
|
||||||
if (x2 == 1 and x3 == 1) and (x4 == 0 and x5 == 0 and x1 == 0):
|
cv2.putText(img, "7_SEVEN", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||||
|
(0, 0, 255), 3)
|
||||||
|
elif (np.linalg.norm(lm_list[4]-lm_list[8]) < 50) and (x4 == 1 and x5 == 1 and x3 == 1):
|
||||||
|
cv2.putText(img, "OK", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||||
|
(0, 0, 255), 3)
|
||||||
|
elif (np.linalg.norm(lm_list[4]-lm_list[12]) < 50) and (x4 == 1 and x5 == 1 and x2 == 1):
|
||||||
|
cv2.putText(img, "flip", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||||
|
(0, 0, 255), 3)
|
||||||
|
elif (x2 == 1 and x3 == 1) and (x4 == 0 and x5 == 0 and x1 == 0):
|
||||||
cv2.putText(img, "2_TWO", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
cv2.putText(img, "2_TWO", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||||
(0, 0, 255), 3)
|
(0, 0, 255), 3)
|
||||||
elif (x2 == 1 and x3 == 1 and x4 == 1) and (x1 == 0 and x5 == 0):
|
elif (x2 == 1 and x3 == 1 and x4 == 1) and (x1 == 0 and x5 == 0):
|
||||||
@ -165,19 +169,24 @@ class Main:
|
|||||||
elif x1 == 1 and x2 == 1 and x3 == 1 and x4 == 1 and x5 == 1:
|
elif x1 == 1 and x2 == 1 and x3 == 1 and x4 == 1 and x5 == 1:
|
||||||
cv2.putText(img, "5_FIVE", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
cv2.putText(img, "5_FIVE", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||||
(0, 0, 255), 3)
|
(0, 0, 255), 3)
|
||||||
elif x2 == 1 and x1 == 0 and (x3 == 0, x4 == 0, x5 == 0):
|
elif (x2 == 1 and x1 == 0) and (x3 == 0 and x4 == 0 and x5 == 0):
|
||||||
cv2.putText(img, "1_ONE", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
cv2.putText(img, "1_ONE", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||||
(0, 0, 255), 3)
|
(0, 0, 255), 3)
|
||||||
elif x1 == 1 and x2 == 1 and (x3 == 0, x4 == 0, x5 == 0):
|
elif (x1 == 1 and x2 == 1) and (x3 == 0 and x4 == 0 and x5 == 0):
|
||||||
cv2.putText(img, "8_EIGHT", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
cv2.putText(img, "8_EIGHT", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||||
(0, 0, 255), 3)
|
(0, 0, 255), 3)
|
||||||
elif x1 == 1 and x5 == 1 and (x3 == 0, x4 == 0, x5 == 0):
|
elif (x1 == 1 and x5 == 1) and (x3 == 0 and x4 == 0 and x2 == 0):
|
||||||
cv2.putText(img, "6_SIX", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
cv2.putText(img, "6_SIX", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||||
(0, 0, 255), 3)
|
(0, 0, 255), 3)
|
||||||
elif x1 and (x2 == 0, x3 == 0, x4 == 0, x5 == 0):
|
elif x1 and (x2 == 0 and x3 == 0 and x4 == 0 and x5 == 0):
|
||||||
cv2.putText(img, "GOOD!", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
cv2.putText(img, "GOOD!", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||||
(0, 0, 255), 3)
|
(0, 0, 255), 3)
|
||||||
|
elif (x1 == 1 and x2 == 1 and x5 == 1) and (x3 == 0 and x4 == 0):
|
||||||
|
cv2.putText(img, "yo", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||||
|
(0, 0, 255), 3)
|
||||||
|
else:
|
||||||
|
cv2.putText(img, "unknown", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||||
|
(0, 0, 255), 3)
|
||||||
cv2.imshow("camera", img)
|
cv2.imshow("camera", img)
|
||||||
key = cv2.waitKey(1)
|
key = cv2.waitKey(1)
|
||||||
if cv2.getWindowProperty('camera', cv2.WND_PROP_VISIBLE) < 1:
|
if cv2.getWindowProperty('camera', cv2.WND_PROP_VISIBLE) < 1:
|
Loading…
x
Reference in New Issue
Block a user