Using a USB Webcam with Raspberry Pi

You can use a standard USB webcam to take photos and videos on the Raspberry Pi instead of using the Raspberry Pi camera module.

NOTE:The quality and configurability of the camera module far exceed that of a standard USB webcam.

First, install the fswebcam package:
sudo apt install fswebcam
If you are not using the default user account pi, you need to add your username to the video group; otherwise, you will see a ‘permission denied’ error.
sudo usermod -a -G video <username>
To check if the user has been correctly added to the group, use the groups command.

Basic Usage

Enter the fswebcam command followed by the filename to take a photo with the webcam and save it to the specified filename:

fswebcam image.jpg
This command will display the following information:
--- Opening /dev/video0...Trying source module v4l2.../dev/video0 opened.No input was specified, using the first.Adjusting resolution from 384x288 to 352x288.--- Capturing frame...Corrupt JPEG data: 2 extraneous bytes before marker 0xd4Captured frame in 0.00 seconds.--- Processing captured image...Writing JPEG image to 'image.jpg'.
Using a USB Webcam with Raspberry Pi
NOTE: Using a small default resolution will display a timestamp banner.
The resolution of the webcam used in this example is 1280 x 720. To specify what resolution I want to capture the image, please use the following -r flag:
fswebcam -r 1280x720 image2.jpg
This command will display the following information:
--- Opening /dev/video0...Trying source module v4l2.../dev/video0 opened.No input was specified, using the first.--- Capturing frame...Corrupt JPEG data: 1 extraneous bytes before marker 0xd5Captured frame in 0.00 seconds.--- Processing captured image...Writing JPEG image to 'image2.jpg'.
Using a USB Webcam with Raspberry Pi
The webcam took a photo at full resolution and displayed the banner.

Remove Banner

Now add the –no-banner flag:
fswebcam -r 1280x720 --no-banner image3.jpg
Which displays the following information:
--- Opening /dev/video0...Trying source module v4l2.../dev/video0 opened.No input was specified, using the first.--- Capturing frame...Corrupt JPEG data: 2 extraneous bytes before marker 0xd6Captured frame in 0.00 seconds.--- Processing captured image...Disabling banner.Writing JPEG image to 'image3.jpg'.
Using a USB Webcam with Raspberry Pi
Now, the photo is taken at full resolution without the banner.

Leave a Comment

×