How to install a USB webcam in Raspberry Pi

Question: Can I use a standard USB-based webcam on Raspberry Pi? How can I check if my USB webcam is compatible with Raspberry Pi, and how can I install it on Raspberry Pi?

If you want to take pictures or record videos using Raspberry Pi board, you can install Raspberry Pi camera board. If you do not want to shell out money just for the camera board module, there is yet another way, which is to utilize a commonly found USB web camera. You may already have one for your PC.

In this tutorial, we show how to set up a USB web camera on Raspberry Pi board. We assume that you are using Raspbian operation system.

Before we start, it is better to check if your USB web camera is one of those which are known to be compatible with Raspberry Pi. If your USB webcam is not found in the compatibility list, don't be discouraged, as there is still a chance that your USB web camera may be detected by Raspberry Pi.

Check if a USB Webcam is Compatible with Raspberry Pi

To check whether your USB web camera is detected on Raspberry Pi or not, plug it into the USB port of your Raspberry Pi, and type lsusb command in the terminal.

$ lsusb

If the output of the command does not list your webcam, there is a possibility that this is because your Raspberry Pi doesn't supply enough power needed for your USB web camera. In this case, you can try using a separate power line for the USB web camera, such as USB power hub, and then repeat the lsusb command. If the USB webcam is still not recognized, we can only suggest you buy another USB web camera which is supported by Raspberry Pi.

In the above screenshot, the USB web camera is detected as "1e4e:0102", but it doesn't show the maker or the name of the web camera. When we try it with Fedora 20 in a laptop, it is successfully detected as "1e4e:0102 Cubeternet GL-UPC822 UVC WebCam."

Another way to check if your USB web camera is supported by Raspberry Pi is by checking the /dev directory. If there is /dev/video0, this implies that your USB webcam is recognized by Raspberry Pi.

Take a Picture with USB Webcam

After your USB webcam is successfully hooked up with Raspberry Pi, the next thing to do is to take some pictures to verify its functionality.

For this, you can install fswebcam, which is a small webcam application. You can install fswebcam directly from the Raspbian repository as follows.

$ sudo apt-get install fswebcam

Once fswebcam is installed, run the following command in a terminal to capture a picture from the USB webcam:

$ fswebcam --no-banner -r 640x480 image.jpg

This command will capture a picture with 640x480 resolution, and save it as image.jpg. It will not put any banner in the bottom part of the picture.

Here is the result from the fswebcam command with 640x480 resolution.

The next example picture is captured without defining the resolution. The picture color is blueish, and the default resolution is only 358x288.

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

7 thoughts on “How to install a USB webcam in Raspberry Pi

  1. I'm using a program called motionEye on one of my B+'s. It can take snapshots and video snips as well as display live streams - at will or based on motion detection. I am successfully streaming one cheap no-brand usb camera and an IP camera.

  2. I am problem for capturing images using webcam which is given below

    --- Opening /dev/video0...
    Trying source module v4l2...
    /dev/video0 opened.
    No input was specified, using the first.
    --- Capturing frame...
    GD Error: gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file: starts with 0x27 0x7cCaptured frame in 0.00 seconds.
    --- Processing captured image...
    Disabling banner.
    Writing JPEG image to 'image.jpg'.

    • It looks as if you didn't put ".jpg" at the end of your file name. using fswebcam the last argument given should be the name you want the picture to be and it must end with ".jpg". Examples: "image.jpg", "test.jpg" myPhoto.jpg". I hope this helps!

    • use this comand below
      pi@raspberrypi:~ $ fswebcam --no-banner -r 640*480 /home/pi/Pictures/image.jpg

Leave a Reply to j-roc Cancel reply

Your email address will not be published. Required fields are marked *