一. 此次我们来利用opencv2来进行机器视觉的学习
1. 首先我们先来进行一个小的案例的实现.
这次我们是将会进行一个小的矩形手势的移动.
import cv2
from cvzone.HandTrackingModule import HandDetector
cap = cv2.VideoCapture(0)
colorR = (0, 0, 255)
detector = HandDetector(detectionCon=0.7)
cx, cy, w, h = 100, 100, 200, 200
while True:
success, img = cap.read()
img = cv2.flip(img, 1)
detector.findHands(img)
lmList, _ = detector.findPosition(img)
if lmList:
l, _, _ = detector.findDistance(8, 12, img)
if l < 70:
cursor = lmList[8]
if cx - w // 2 < cursor[0] < cx + w // 2 and cy - h // 2 < cursor[1] < cy + h // 2:
colorR = 0, 255, 0
cx, cy = cursor
else:
colorR = 0, 0, 255
cv2.rectangle(img, (cx - w // 2, cy - h // 2), (cx + w // 2, cy + h // 2), colorR, cv2.FILLED)
cv2.imshow("Image", img)
cv2.waitKey(1)
包的版本号