Mediapipe: How can I connect webcam to Mediapipe for Hand Tracking

Created on 14 Nov 2019  Â·  20Comments  Â·  Source: google/mediapipe

I've tried to run Object Detection on Desktop (CPU) with Webcam but I have some problems. Below is the error shown on the screen

I1114 15:44:40.590370 3102 demo_run_graph_main.cc:52] Initialize the calculator graph.
I1114 15:44:40.613526 3102 demo_run_graph_main.cc:56] Initialize the camera or load the video.
E1114 15:44:40.616816 3102 demo_run_graph_main.cc:141] Failed to run the graph: ;_ capture.isOpened()(mediapipe/examples/desktop/demo_run_graph_main.cc:64)

Please show me what I should do.
Thank you.

desktop

All 20 comments

The error seems to occur because of capture.isOpened() failing. Are you able to use your webcam in OpenCV?
Try a script with just OpenCV (something like https://answers.opencv.org/question/1/how-can-i-get-frames-from-my-webcam/) to confirm that you are able to use your webcam in OpenCV.

@eknight7 Thank for your help. But I don't know how can I able to use my webcam in OpenCv with this script. Because I have access to mediapie while I have very little knowledge of programming. Thank you.

Are you able to use your webcam in another user facing application, such has Hangouts or Skype?

Hi Esha,
Yes, I can.
I can use the Webcam normally for applications like Skype Hangouts or Line

Vào 13:02, Th 6, 15 thg 11, 2019 Esha Uboweja notifications@github.com đã
viết:

Are you able to use your webcam in another user facing application, such
has hangouts or skype?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/google/mediapipe/issues/246?email_source=notifications&email_token=ANYSLWFO2PXLAG54T36RAJDQTYUQFA5CNFSM4JNHLEHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEEKBEY#issuecomment-554213523,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ANYSLWHK3FTWZKIXVXF2MDDQTYUQFANCNFSM4JNHLEHA
.

It seems like the error is because of OpenCV not being able to access the camera. Since your camera works in other applications, it is likely that there is an issue with using OpenCV on your desktop.

Are you seeing the same issue when you try to run the GPU version?

When I try to run the GPU version on my laptop I also have the same problem.

Save the file from https://answers.opencv.org/question/1/how-can-i-get-frames-from-my-webcam/ as vid.cpp.
Then in your terminal, run:

g++ -w vid.cpp -o vid `pkg-config --libs opencv`
./vid

Does that work?

@eknight7 Sorry for my late reply.
It's still can not work. :(

My terminal displayed: Failed to run the graph: ; capture.isOpened( (mediapipe/examples/desktop/demo_run_graph_main.cc:64), although I don't connect webcam with my PC

Were you able to try and run the standalone OpenCV script as described in my previous comment?

I've already tried to run as described in your previous comment, but I don't know where I will put the vid.cpp file. I try to put vid.cpp in same installation directory with opencv but It displayed :
_g++: error: vid.cpp: No such file or directory_

Can you put the vid.cpp file in a different directory, outside the opencv installation directory and try?

I tried it but it still didn't work

Mediapipe relies on opencv to connect to the webcam.
If running the simple _vid.cpp_ camera test didn't work (i.e. didn't connect to and display the webcam), then unfortunately the issue is with opencv installation on your machine, and outside the scope of mediapipe.
Once you get opencv connecting to your webcam, then the mediapipe demos should work.

@ngocthangbme
Are you able to run other desktop demos, such as object detection? (https://mediapipe.readthedocs.io/en/latest/object_detection_desktop.html)

Are you able to run an offline demo such as in https://mediapipe.readthedocs.io/en/latest/object_detection_desktop.html without connecting to a live webcam?

Hi @ngocthangbme ,

Did you finally find how to put a webcam to Mediapipe for Hand Tracking ? I am really interested.

Thanks

@romaindebraize can you please describe your issue? We didn't get a follow-up from @ngocthangbme .

@ngocthangbme i have a UVC camera that i can connect to my Android Phone and i would like to use handtracking with it. To do so, i want to change the input_stream with the stream from my webcam. Any idea ?
Thanks

Change the name of the input video worked for me, i named it input.mp4 or O.mp4 and works, but for some reason does not works with videollamada.mp4.

@eknight7 hi, can you help me? i have the same problem of the guy. I study computer since and i am only missing my final project that i should finish in november and consist in create a system able to understand if hand/hands is/are wearing or not gloves.

Now, i have the same problem of the guy:

I1114 15:44:40.590370 3102 demo_run_graph_main.cc:52] Initialize the calculator graph.
I1114 15:44:40.613526 3102 demo_run_graph_main.cc:56] Initialize the camera or load the video.
E1114 15:44:40.616816 3102 demo_run_graph_main.cc:141] Failed to run the graph: ;_ capture.isOpened()(mediapipe/examples/desktop/demo_run_graph_main.cc:64)

I tried to create a vid.cpp as you said with the code took by the site thay you said but i've this problem:
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
/home/diego/Scrivania/vid.cpp:1:10: fatal error: opencv2/opencv.hp: File o directory non esistente
#include "opencv2/opencv.hp"
^~~~~~~
compilation terminated.

So honestly i have no idea about how to solve this.
Any advices?
many thanks

Was this page helpful?
0 / 5 - 0 ratings