Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI Virtual Drag and Drop using OpenCv issue #844 #868

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
40 changes: 40 additions & 0 deletions Virtual Drag and Drop Using OpenCV/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# AI Virtual Drag and Drop

This project uses OpenCV and cvzone's HandTrackingModule to create a virtual drag and drop interface. The program captures video from the webcam, detects hands, and allows the user to drag and drop an image using their index finger and thumb.

## Features
- Real-time hand detection using the webcam.
- Virtual drag and drop functionality for a specified image.
- Simple and intuitive interface.

## Installation

1. Clone the repository:
```bash
git clone https://github.com/yourusername/AI-Virtual-Drag-and-Drop.git
cd AI-Virtual-Drag-and-Drop
```

2. Install the required packages:
```bash
pip install -r requirements.txt
```

## Usage

1. Place the image you want to use (e.g., `gates.jpg`) in the same directory as the script.
2. Run the script:
```bash
python drag_and_drop.py
```

## Requirements
- Python 3.x
- OpenCV
- cvzone

## How it works

The script captures video frames from the webcam and uses the HandTrackingModule from cvzone to detect hands. When the distance between the index finger and thumb is less than a certain threshold, the image can be dragged around the screen by moving the hand.


4 changes: 4 additions & 0 deletions Virtual Drag and Drop Using OpenCV/requirement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#required packages/libraries that need to installed

opencv-python
cvzone
30 changes: 30 additions & 0 deletions Virtual Drag and Drop Using OpenCV/virtualDragDrop.ipynb
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)