现在,我们已经完成手势的识别与结果输出,我们把完整代码运行一下,即可验证出我们的代码效果 。
完整代码完整代码如下
# -*- coding:utf-8 -*-"""CODE >>> SINCE IN CAIXYPROMISE.STRIVE FOR EXCELLENT.CONSTANTLY STRIVING FOR SELF-IMPROVEMENT.@ by: caixy@ date: 2021-10-1"""import cv2from HandTrackingModule import HandDetectorclass Main:def __init__(self):self.camera = cv2.VideoCapture(0,cv2.CAP_DSHOW)self.camera.set(3, 1280)self.camera.set(4, 720)def Gesture_recognition(self):while True:self.detector = HandDetector()frame, img = self.camera.read()img = self.detector.findHands(img)lmList, bbox = self.detector.findPosition(img)if lmList:x_1, y_1 = bbox["bbox"][0], bbox["bbox"][1]x1, x2, x3, x4, x5 = self.detector.fingersUp()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 (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)elif (x2 == 1 and x3 == 1 and x4 == 1 and x5 == 1) and (x1 == 0):cv2.putText(img, "4_FOUR", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,(0, 0, 255), 3)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,(0, 0, 255), 3)elif x2 == 1 and (x1 == 0, x3 == 0, x4 == 0, x5 == 0):cv2.putText(img, "1_ONE", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,(0, 0, 255), 3)elif x1 and (x2 == 0, x3 == 0, x4 == 0, x5 == 0):cv2.putText(img, "GOOD!", (x_1, y_1), cv2.FONT_HERSHEY_PLAIN, 3,(0, 0, 255), 3)cv2.imshow("camera", img)if cv2.getWindowProperty('camera', cv2.WND_PROP_VISIBLE) < 1:breakcv2.waitKey(1)# if cv2.waitKey(1) & 0xFF == ord("q"):#breakif __name__ == '__main__':Solution = Main()Solution.Gesture_recognition()效果一目了然,计算机成功识别了你的手势并把内容输出 。快去试试吧!
【一文带你读懂Python计算机视觉中的OpenCV手势识别方法】
推荐阅读
- 一文了解MQTT协议
- 一文搞懂HTTP,TCP,UDP,Socket,WebSocket
- 一文让你彻底搞清楚,Linux零拷贝技术的那些事儿
- 一文读懂所有HTTP状态码含义
- HDMI和DP区别在哪里?电脑连接线怎么选,一文看懂连接线的历史
- 手把手带你撸一个最简单实时数据库
- 「自动化运维」带你入门ansible
- 一文带你理解URI 和 URL 有什么区别?
- 2022年新版Windows 11升级指南:准备工作,一文读懂
- 电脑装哪个系统好,win7还是win10?一文消除你的纠结
