DEV Community

Cover image for Finger Detection and Tracking using OpenCV and Python

Finger Detection and Tracking using OpenCV and Python

Amar Prakash Pandey on July 28, 2018

TL;DR. Code is here. Finger detection is an important feature of many computer vision applications. In this application, A histogram based approac...
Collapse
 
tungts1101 profile image
tungts1101 •

Got this error after I pressed 'z' key:

Traceback (most recent call last):
File "FingerDetection.py", line 186, in
main()
File "FingerDetection.py", line 171, in main
manage_image_opr(frame, hand_hist)
File "FingerDetection.py", line 136, in manage_image_opr
contour_list = contours(hist_mask_image)
File "FingerDetection.py", line 23, in contours
_, cont, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
ValueError: not enough values to unpack (expected 3, got 2)

Do you have any idea?

Collapse
 
amarlearning profile image
Amar Prakash Pandey •

@tungts1101 I will suggest you use opencv-python version 3.4.*. You are facing this issue because you are using some higher version of opencv-python.

You can download the correct dependencies using requirement.txt file present in the repository.

Hint: Use command sudo pip install -r requirement.txt

Collapse
 
tungts1101 profile image
tungts1101 •

That's work. But I think there's still something need to be done in order to eliminate noise in background.

Thread Thread
 
amarlearning profile image
Amar Prakash Pandey •

Yes, that's an issue. You can take that up if you want.

Collapse
 
databits profile image
Mitch •

Update this line...
From:
_, cont, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

To:
cont, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

That should fix the issue for CV 4.5

Collapse
 
mrcomnguoi profile image
MrComNguoi •

Thank you, it works

Collapse
 
lukasswiss profile image
lukasswiss •

Hi, this is a great tutorial but my program will not recognize my hand. I hold it up in the proper position, but the green boxes remain. I know that my code is not wrong because I cross-referenced it with your github repo. Do you have any idea why this could be happening?

Collapse
 
amarlearning profile image
Amar Prakash Pandey • • Edited

Hi @lukasswiss , I am glad that you liked my post.

Once you place your hand to cover all boxes, you have to press 'Z' key.

Collapse
 
jeisonsanches profile image
Jeison Sanches •

Amazing!

Collapse
 
amarlearning profile image
Amar Prakash Pandey • • Edited

Thanks, Jeison!

Collapse
 
kataras profile image
Gerasimos (Makis) Maropoulos •

Nice Amar, will be interested to see more from you here although I am not even a python coder!

Collapse
 
amarlearning profile image
Amar Prakash Pandey •

Thanks @kataras , I am really happy that you liked it. 😊

Collapse
 
martinneumann profile image
Info Comment hidden by post author - thread only accessible via permalink
Martin Neumann •

You copied this verbatim from here: benmeline.com/finger-tracking-with...

Please name your sources at least!

Collapse
 
subinsaju profile image
SUBIN SAJU •

sir can we do if we write 5 in air then the output as 5 will be in the output can we do like that

Collapse
 
amarlearning profile image
Amar Prakash Pandey •
Collapse
 
geeva22 profile image
Geeva •

What is the use of this project? Problem statement?

Collapse
 
lixingyu1591 profile image
lixingyu1591 •

It's awesome man! However, could you please tell me what kind of algorithm you used in calculating the farthest point?

Collapse
 
talhasharif281 profile image
talhasharif281 •

Can we do this in MATLAB? If yes, how?

Collapse
 
amarlearning profile image
Amar Prakash Pandey •

I have no idea about MATLAB, so can't say anything.

Collapse
 
ben profile image
Ben Halpern •

Wow this is super cool stuff!

Collapse
 
amarlearning profile image
Amar Prakash Pandey • • Edited

Thanks @ben , glad you liked it!

Some comments have been hidden by the post's author - find out more