Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize virtual drag-and-drop effect by using gesture recognition in OpenCV

Shulou Source: shulou.com Published: 2022-06-02 02:32:26 10月03日 Update

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

Tags: Box fingertip index finger test gesture effect code content square picture article so that middle finger value interest boy buddy that is very soon. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information vpn Huawei Linux Apple