In practice, the support for USB cameras on the Raspberry Pi is not as perfect as that for CSI cameras. Occasionally, there may be situations where the USB camera cannot be used, and the built-in camera commands raspistill and raspivid are also unusable. However, fswebcam, a small camera program (official website), can support USB cameras very well. The usage is also quite simple.
Installing fswebcam
Install fswebcam to access the camera and take pictures.
sudo apt-get install fswebcam
Usage of fswebcam
fswebcam --help
Usage: fswebcam [][[]... ]
Options:
-?, --help Display this help page and exit.
-c, --configLoad configuration from file.
-q, --quiet Hides all messages except for errors.
-v, --verbose Displays extra messages while capturing
--version Displays the version and exits.
-l, --loopRun in loop mode.
-b, --background Run in the background.
-o, --outputOutput the log to a file.
-d, --deviceSets the source to use.
-i, --inputSelects the input to use.
-t, --tunerSelects the tuner to use.
-f, --frequencySelects the frequency use.
-p, --paletteSelects the palette format to use.
-D, --delaySets the pre-capture delay time. (seconds)
-r, --resolutionSets the capture resolution.
--fpsSets the capture frame rate.
-F, --framesSets the number of frames to capture.
-S, --skipSets the number of frames to skip.
--dumpframeDump a raw frame to file.
-s, --set=Sets a control value.
--revert Restores original captured image.
--flipFlips the image. (h, v)
--crop[,] Crop a part of the image.
--scaleScales the image.
--rotateRotates the image in right angles.
--deinterlace Reduces interlace artifacts.
--invert Inverts the images colours.
--greyscale Removes colour from the image.
--swapchannelsSwap channels c1 and c2.
--no-banner Hides the banner.
--top-banner Puts the banner at the top.
--bottom-banner Puts the banner at the bottom. (Default)
--banner-colourSets the banner colour. (#AARRGGBB)
--line-colourSets the banner line colour.
--text-colourSets the text colour.
--font <[name][:size]> Sets the font and/or size.
--no-shadow Disables the text shadow.
--shadow Enables the text shadow.
--titleSets the main title. (top left)
--no-title Clears the main title.
--subtitleSets the sub-title. (bottom left)
--no-subtitle Clears the sub-title.
--timestampSets the timestamp format. (top right)
--no-timestamp Clears the timestamp.
--gmt Use GMT instead of local timezone.
--infoSets the info text. (bottom right)
--no-info Clears the info text.
--underlaySets the underlay image.
--no-underlay Clears the underlay.
--overlaySets the overlay image.
--no-overlay Clears the overlay.
--jpegOutputs a JPEG image. (-1, 0 - 95)
--pngOutputs a PNG image. (-1, 0 - 10)
--saveSave image to file.
--execExecute a command and wait for it to complete.
Using fswebcam
Check for devices under /dev/ that have video0. Run the lsusb command to get information about the relevant camera. Run the following command in the terminal to capture a photo from the camera.
fswebcam --no-banner -r 640x480 image.jpg
Alternatively, you can directly use:
fswebcam image.jpg
You can take a photo directly, -d is used to specify which camera device to use. -r specifies the resolution of the image, and the last is the path where the photo is saved.
If the captured photo is completely dark, it may be related to the camera’s startup delay. You can solve this by adding the -S parameter to skip the first few frames. For example, use the command:
fswebcam -S 10 image.jpg
The links in the text can be clicked to read the original text at the end
More exciting content
Making a motorcycle dashboard with Raspberry Pi
Making an intelligent pet feeding machine with Raspberry Pi
Creating an intelligent planetary observer based on Raspberry Pi
Handmade metal wire frame craft X-wing clock
Arduino + 280 LEDs DIY music spectrum light
DIY Stanford Pupper 12 Degrees of Freedom Quadruped Robot Dog
Barrier: Keyboard and mouse sharing solution between PC and Raspberry Pi