I want to be able to take a picture using the webcam from the terminal. This image then will be saved to a file. How can this be done?
Here is Solutions:
We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.
There is another application which can be used to capture the images from the webcam named as
Fswebcam. you can install that with
sudo apt-get install fswebcam
you can have a sample shot with the following command.
fswebcam -r 640x480 --jpeg 85 -D 1 web-cam-shot.jpg
In the above code syntax ,
-r stands for Image resolution ,
--jpeg stand for format type of the image &
85 for its quality standard,
-D stands for delay set before capture.
Now your image finally saved with web-cam-shot.jpg name.
Hope that helps.
If you’re looking for something automated
webcam is pretty decent. It has lots of lovely options for pushing the photos over the Internet.
If you want something more manual, and we’re talking about a camera supported by V4L/UVC (most of them) you can use
streamer to capture a frame from the device:
streamer -f jpeg -o image.jpeg
ffmpeg, you can capture a frame from your device as well. For example:
avconv -f video4linux2 -s 640x480 -i /dev/video0 -ss 0:0:2 -frames 1 /tmp/out.jpg
ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 -ss 0:0:2 -frames 1 /tmp/out.jpg
This will open
/dev/video0 as a
video4linux2 compatible device, set up resolution to
640x480, stream for 2 seconds (
00:00:02 or simply
2), then capture
one single frame, saving it to
Check if your device is
/dev/video0, as it can be different for you.
The available resolutions depend on your webcam. Mine goes up to 640×480 and I checked it with a tool called
qv4l2, which is used to configure a video4linux2 device.
-ss parameter is used to allow the device to start up correctly. Here in my tests, there is a fade-in effect while the camera is being turned on, so, if I just omit
-ss 2, the captured frame will be very dark.
You can also try uvccapture.
Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂