1 bugfix:修复内存泄露问题
2 bugfix:解决无法退出问题
This commit is contained in:
parent
857b09a49b
commit
4e2ba65d3e
14
origin.py
14
origin.py
@ -1,4 +1,3 @@
|
||||
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
"""
|
||||
@ -15,12 +14,12 @@ import cv2
|
||||
import mediapipe as mp
|
||||
|
||||
|
||||
|
||||
class HandDetector:
|
||||
"""
|
||||
使用mediapipe库查找手。导出地标像素格式。添加了额外的功能。
|
||||
如查找方式,许多手指向上或两个手指之间的距离。而且提供找到的手的边界框信息。
|
||||
"""
|
||||
|
||||
def __init__(self, mode=False, maxHands=2, detectionCon=0.5, minTrackCon=0.5):
|
||||
"""
|
||||
:param mode: 在静态模式下,对每个图像进行检测
|
||||
@ -42,7 +41,6 @@ class HandDetector:
|
||||
self.tipIds = [4, 8, 12, 16, 20] # 指尖列表
|
||||
self.fingers = []
|
||||
self.lmList = []
|
||||
self.connection = [(1,0,5),(1,0,17),(5,0,17),(2,1,0),(3,2,1),(4,3,2),(0,5,6),(0,5,9),(6,5,9),(5,6,7),(6,7,8),(5,9,13),(5,9,10),(10,9,13),(9,10,11),(10,11,12),(9,13,14),(9,13,17),(14,13,17),(13,14,15),(14,15,16),(13,17,18),(0,17,13),(0,17,18),(17,18,19),(18,19,20)]
|
||||
|
||||
def findHands(self, img, draw=True):
|
||||
"""
|
||||
@ -138,6 +136,7 @@ class HandDetector:
|
||||
else:
|
||||
return "Left"
|
||||
|
||||
|
||||
class Main:
|
||||
def __init__(self):
|
||||
self.camera = cv2.VideoCapture(0, cv2.CAP_DSHOW)
|
||||
@ -145,8 +144,9 @@ class Main:
|
||||
self.camera.set(4, 720)
|
||||
|
||||
def Gesture_recognition(self):
|
||||
while True:
|
||||
fps = cv2.CAP_PROP_FPS
|
||||
self.detector = HandDetector()
|
||||
while True:
|
||||
frame, img = self.camera.read()
|
||||
img = self.detector.findHands(img)
|
||||
lmList, bbox = self.detector.findPosition(img)
|
||||
@ -180,9 +180,13 @@ class Main:
|
||||
cv2.putText(img, "GOOD!", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,
|
||||
(0, 0, 255), 3)
|
||||
cv2.imshow("camera", img)
|
||||
|
||||
key = cv2.waitKey(1)
|
||||
if cv2.getWindowProperty('camera', cv2.WND_PROP_VISIBLE) < 1:
|
||||
break
|
||||
cv2.waitKey(1)
|
||||
elif key == 27:
|
||||
break
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user