banner



How To Make Usb Camera

Working with USB webcams on your Raspberry Pi

In well-nigh cases it is best to use a Raspberry Pi photographic camera module. Nevertheless, to help y'all with those cases you lot still want to use a USB webcam, follow the below guide.

Tabular array of contents

  1. Pros and cons of a USB webcam
  2. Setting up and using a USB webcam
  3. Controlling the webcam with Python
  4. Setting up multiple USB webcams

Pros and cons of a USB webcam

USB Webcams generally have inferior quality to the camera modules that connect to the CSI interface. They tin can besides not be controlled using the raspistill and rasivid commands in the terminal neither by the picamera recording package in Python. Still, there may be reasons why yous want to connect a USB camera to your Raspberry Pi, such equally because of the benefit that it is much easier to set up multiple camera's with a unmarried Raspberry Pi (see below).

Setting upwards and using a USB webcam

Y'all can control a USB webcam both using fustigate in the terminal and with Python. First plugin the photographic camera and meet if the Raspberry Pi recognises it by entering lsusb in the final. It should bear witness something like this:

lsusb output

To command the camera in the last I propose to employ the fswebcam packet. To install:

            sudo apt install fswebcam                      

To have an image with a sure resolution and hide the standard banner:

            fswebcam -r 1280x720 --no-banner /images/image1.jpg                      

To observe the supported webcam resolutions:

            v4l2-ctl --listing-formats-ext                      

You could likewise utilize ffmpeg to take images and video. To install:

To take an epitome:

            ffmpeg -f v4l2 -video_size 1280x720 -i /dev/video0 -frames ane out.jpg                      

A more than advanced alternative is mjpeg-streamer, which enables you to stream the camera in a browser. Yous can find a detailed tutorial how to set that upward here.

Decision-making the webcam with Python

A number of solutions exist to connect to the USB camera with Python. Unfortunately the picamera software does not work with USB webcams. I suggest to use OpenCV. To aid install OpenCV, follow my guide hither. Now to tape a single epitome:

            import cv2  cam = cv2.VideoCapture(0)  while True: 	ret, epitome = cam.read() 	cv2.imshow('Imagetest',image) 	k = cv2.waitKey(1) 	if g != -1: 		interruption cv2.imwrite('/domicile/pi/testimage.jpg', image) cam.release() cv2.destroyAllWindows()                      

There are many other options available with opencv. I suggest to read the documentation at opencv.org.

Setting upward multiple USB webcams

You can connect as many webcams as you want every bit long as they are powered up per their requirements, such every bit using a powered USB hub. Each usb web cam that you connect gets listed nether /dev/video<n> where n, starting at 0 for camera 1, is the id of the device.

To list your devices:

You can set the device to use for recordings with the fswebcam software with the --device flag. For instance, to take an image with the second connected USB webcam using fswebcam:

            fswebcam --device /dev/video1 image.jpg                      

And with Python and OpenCV you tin can only set up cv2.VideoCapture to 1.


Source: https://raspberrypi-guide.github.io/electronics/using-usb-webcams

Posted by: zurcherpudge1936.blogspot.com

0 Response to "How To Make Usb Camera"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel