Use USB CameraInstall FSWebcamView USB camera devicesTake a photoTime-lapse photographyUse Cron (scheduled tasks)Web preview cameraInstall MotionModify the configuration fileStart the serviceWeb preview screen
Use a standard USB camera to take photos and videos on the Raspberry Pi.
FSWebcam is a simple and straightforward webcam application. The software installation command is as follows:
sudo apt install fswebcam
Example: Add pi user permissions to the group
xxxxxxxxxx
sudo usermod -a -G video pi
Command: groups
Use the lsusb command to view all USB devices recognized by the system;
Use the ls /dev/video* command to list all video devices recognized by the system.
xxxxxxxxxx
The following two commands are to detect the information displayed by the camera. You can compare the differences by yourself:
One is image/video acquisition, and the other is metadata acquisition.
Example: Take a photo and save it as image.jpg (the default path for saving the file is in the user directory)
xxxxxxxxxx
fswebcam image.jpg
Example: Take an image file with a resolution of 1280x720 and save it as image2.jpg
xxxxxxxxxx
fswebcam -r 1280x720 image2.jpg
Example: Take an image file with a resolution of 1280x720, do not display time and other information on the image, and save it as image3.jpg
xxxxxxxxxx
fswebcam -r 1280x720 --no-banner image3.jpg
Create a new Webcam folder and enter the file
xxxxxxxxxx
mkdir Webcam
xxxxxxxxxx
cd Webcam
Create a new webcam.sh script file and edit the content
xxxxxxxxxx
sudo nano webcam.sh
File content: The file save path needs to be modified by yourself. My system user name directory is yahboom
x#!/bin/bash
DATE=$(date +"%Y-%m-%d_%H%M")
fswebcam -r 1280x720 --no-banner /home/pi/Webcam/$DATE.jpg
Press Ctrl+X, enter Y, and press Enter.
Add executable permissions
xxxxxxxxxx
sudo chmod +x webcam.sh
Run the script
xxxxxxxxxx
./webcam.sh
Open the cron table for editing. You will be prompted to select an editor for the first use. It is recommended to use the nano editor
xxxxxxxxxx
crontab -e
Add the following code to the edited document: The first 5 * signs represent a timer of 1 minute, and 2>&1 is to input the error output to the standard output
xxxxxxxxxx
* * * * * /home/pi/Webcam/webcam.sh 2>&1
After saving the file and exiting, the terminal will output the following:
xxxxxxxxxx
crontab: installing new crontab
For Cron jobs, you can learn about the format and syntax by yourself!
xxxxxxxxxx
If the image is not generated after one minute, you can restart the service and check whether the path is correct!
Start cron service: sudo service cron start
Stop cron service: sudo service cron stop
xxxxxxxxxx
If the cron service stop command cannot turn off the camera's automatic shooting, it is recommended to use the crontab -e command directly to delete the previously edited content!
Use Motion to realize real-time viewing of the video shot by the USB camera on the web page.
xxxxxxxxxx
CSI cameras cannot use this method to preview the camera!
xxxxxxxxxx
sudo apt install motion
xxxxxxxxxx
sudo nano /etc/motion/motion.conf
Add or modify the following content:
xxxxxxxxxx
daemon on
stream_localhost off
picture_output off
movie_output off
stream_maxrate 100
framerate 70
width 640
height 480
Note:
xxxxxxxxxx
stream_maxrate: real-time streaming frame rate
framerate: frame rate
width: image width
height: image height
The above parameters can be adjusted!
xxxxxxxxxx
sudo nano /etc/default/motion
Add the following code: motion runs in the background
xxxxxxxxxx
start_motion_daemon=yes
xxxxxxxxxx
sudo service motion start
xxxxxxxxxx
sudo service motion stop
xxxxxxxxxx
sudo service motion restart
xxxxxxxxxx
sudo motion
Enter the start motion service and start motion commands in the terminal:
xxxxxxxxxx
sudo service motion start
sudo motion
After turning on motion, enter the car IP:8081 in the browser on the same LAN to view the real-time camera screen.
Example: 192.168.2.93:8081