offifee
Posts: 4
Joined: Wed May 08, 2019 6:19 am

Take picture with USB Camera at incoming signal

Wed May 08, 2019 6:53 am

Hello,

I would like to connect my Raspberry Pi 3 to a USB camera and take a picture at a signal coming in to the Raspberry.
I already was able to take a picture with the

fswebcam image.jpg

command, so the camera works with the Raspberry.

Actually any information about how to interact with the USB camera from the Raspberry apart from using the command window would be useful. All the tutorials I find are for Pi Cameras and coded in a way I am not able to find the things I have to change to make it suitable for a USB camera with my knowledge. Or they just explain how to use a USB camera with the command window.

Would be great if someone could help me!

User avatar
topguy
Posts: 5759
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Take picture with USB Camera at incoming signal

Wed May 08, 2019 11:48 am

What/where/how is the signal ?
Do you have programming experience and if so, which programming language(s) ?

Most USB webcams uses the standarized "UVC" protocol, which means that the Linux kernel creates a V4L2 device named "/dev/video0"
There are a bunch of different programs that works with the V4L2 ( Video for Linux 2 ) API.

Dig deep:
https://linuxtv.org/downloads/v4l-dvb-a ... /v4l2.html

Python:
https://pypi.org/project/v4l2/

offifee
Posts: 4
Joined: Wed May 08, 2019 6:19 am

Re: Take picture with USB Camera at incoming signal

Thu May 09, 2019 2:01 am

Thank you very much for your answer!

I did not finally decide about the way the signal comes in yet. But probably I will just use one of the GPIO Pins on the Raspberry (Edge low to high for taking a picture).

I have experience with C, C++ and MatLab. But I never worked with Python and have no idea about Linux.

As I said, I would like to control the camera somehow without the command window (Python file or something similar). After taking the picture a longer image processing part will be done. I would like to write a file that is started at the signal. The picture is taken and processed after.

And I don't know what I have to do to initialize the camera.

User avatar
topguy
Posts: 5759
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Take picture with USB Camera at incoming signal

Thu May 09, 2019 10:00 am

How quickly does the image need to be taken after the signal ? Are we talking miliseconds or seconds ?
If another signal happens while the previous picture is being taken/processed, do you need to take a new picture or can this signal be ignored ?

Because you can "easily" create a program in C/C++ that listens for a GPIO signal, then uses the "fswebcam" program to capture an image and save it to a file of your choice. Then you can either process that image in the same program or maybe start another program/thread that will do the image-processing and go back to listening on the GPIO.

offifee
Posts: 4
Joined: Wed May 08, 2019 6:19 am

Re: Take picture with USB Camera at incoming signal

Wed May 15, 2019 3:47 am

It does not have to be very fast. And actually it should not be possible that a new signal comes within about 2 seconds, so it can be ignored.

After working a bit more with it that was actually the plan. I would just prefer to write the code in Python instead of C/C++.

Do you maybe have an example/explanation/tutorial how to deal with the programs? I mean, how do I call the second program for processing the picture from the other program? How do I return to the program listening to the signal?
This is the things I never learned and I can not really find information about, maybe it is just too simple :D

User avatar
topguy
Posts: 5759
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Take picture with USB Camera at incoming signal

Wed May 15, 2019 12:29 pm

If you want to continue with Python then there are "fork"ing methods quite similar to what you have in C:
https://www.python-course.eu/forking.php

Return to “Camera board”