Skip to content

Commit

Permalink
Merge pull request #863 from ashis2004/ai-virtual-drag-and-drop
Browse files Browse the repository at this point in the history
Add AI Virtual Drag and Drop project using OpenCV
  • Loading branch information
Niketkumardheeryan authored Jul 29, 2024
2 parents 51f6d3d + 421ce82 commit 2579e65
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Binary file added Virtual Drag and Drop Using OpenCV/gates.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions Virtual Drag and Drop Using OpenCV/virtualDragDrop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import cv2 as cv
from cvzone.HandTrackingModule import HandDetector

cap=cv.VideoCapture(0)
hd=HandDetector()

image=cv.imread('gates.jpg')
image=cv.resize(image,(150,150))
x,y=100,100

while 1:
h,w,c=image.shape
ret,img=cap.read()

img=cv.flip(img,1)
hands,img=hd.findHands(img,flipType=False)

if hands:
lm=hands[0]['lmList']
#print(lm)
length,info,img=hd.findDistance(lm[8][0:2],lm[4][0:2],img)
print(length)

if length<20:
pointer=lm[8]
if x <pointer[0]<x+w and y<pointer[1]<y+h:
x,y=pointer[0]-w//2,pointer[1]-h//2
img[y:y+h,x:x+w]=image
cv.imshow('frame',img)
cv.waitKey(1)

0 comments on commit 2579e65

Please sign in to comment.