增加:MP版本兼容

(被动包含调整复杂系数为1)
This commit is contained in:
leafiber 2022-06-08 15:46:57 +08:00
parent 8feabea649
commit 4a85384e6e
2 changed files with 185 additions and 177 deletions

View File

@ -19,13 +19,16 @@ class HandDetector:
self.results = None
self.mode = mode
self.max_hands = max_hands
self.modelComplex = False
self.modelComplex = 1
self.detection_con = detection_con
self.min_track_con = min_track_con
# 初始化手部的识别模型
self.mpHands = mp.solutions.hands
self.hands = self.mpHands.Hands(self.mode, self.max_hands, self.detection_con, self.min_track_con)
self.hands = self.mpHands.Hands(static_image_mode=self.mode,
max_num_hands=self.max_hands,
min_detection_confidence=self.detection_con,
min_tracking_confidence=self.min_track_con)
self.mpDraw = mp.solutions.drawing_utils # 初始化绘图器
self.tipIds = [4, 8, 12, 16, 20] # 指尖列表
self.fingers = []

11
demo.py
View File

@ -27,14 +27,16 @@ class HandDetector:
self.results = None
self.mode = mode
self.max_hands = max_hands
self.modelComplex = False
self.modelComplex = 1
self.detection_con = detection_con
self.min_track_con = min_track_con
# 初始化手部的识别模型
self.mpHands = mp.solutions.hands
self.hands = self.mpHands.Hands(self.mode, self.max_hands, self.modelComplex,
self.detection_con, self.min_track_con)
self.hands = self.mpHands.Hands(static_image_mode=self.mode,
max_num_hands=self.max_hands,
min_detection_confidence=self.detection_con,
min_tracking_confidence=self.min_track_con)
self.mpDraw = mp.solutions.drawing_utils # 初始化绘图器
self.tipIds = [4, 8, 12, 16, 20] # 指尖列表
self.fingers = []
@ -154,6 +156,9 @@ class Main:
if (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,
(0, 0, 255), 3)
elif x3 and x1 == 0 and x2 == 0 and (x4 == 0, x5 == 0):
cv2.putText(img, "FUCK YOU!!", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
(0, 0, 255), 3)
elif (x2 == 1 and x3 == 1 and x4 == 1) and (x1 == 0 and x5 == 0):
cv2.putText(img, "3_THREE", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
(0, 0, 255), 3)