How to realize virtual drag-and-drop effect by using gesture recognition in OpenCV
This article mainly introduces OpenCV how to use gesture recognition to achieve virtual drag and drop effect, the article is very detailed, has a certain reference value, interested friends must read it!
The first step
Set the display box through opencv and call the camera to display the current screen.
Import cv2cap = cv2.VideoCapture (0) cap.set (3Power1280) cap.set (4720) while True: succes, img = cap.read () cv2.imshow ("Image", img) cv2.waitKey (1) step 2
To find the hand in the current screen, this article will use the hand tracking module in cv zone
From cvzone.HandTrackingModule import HandDetectordetector = HandDetector (detectionCon=0.8) # changed the default confidence level to make its detection more accurate
Find the complete code for the hand
Import cv2from cvzone.HandTrackingModule import HandDetectorcap = cv2.VideoCapture (0) cap.set (3Power1280) cap.set (4720) detector = HandDetector (detectionCon=0.8) while True: succes, img = cap.read () detector.findHands (img) lmList, _ = detector.findPosition (img) cv2.imshow ("Image", img) cv2.waitKey (1)
Step three
The third step is to create a square first
Cv2.rectangle (img, (100100), (300300), (0,0,255), cv2.FILLED)
Then check to see if our index finger enters the box, and if so, the box changes color
If lmList: cursor = lmList [8] if 100