Use USB Camera

Use a standard USB camera to take photos and videos on the Raspberry Pi.

Install FSWebcam

FSWebcam is a simple and straightforward webcam application. The software installation command is as follows:

Example: Add pi user permissions to the group

Command: groups

image-20231218194716544

View USB camera devices

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.

image-20231218194828701

Take a photo

Example: Take a photo and save it as image.jpg (the default path for saving the file is in the user directory)

Example: Take an image file with a resolution of 1280x720 and save it as 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

Time-lapse photography

Create a new Webcam folder and enter the file

Create a new webcam.sh script file and edit the content

File content: The file save path needs to be modified by yourself. My system user name directory is yahboom

image-20231218195342036

Press Ctrl+X, enter Y, and press Enter.

Add executable permissions

Run the script

image-20231218195514605

Use Cron (scheduled tasks)

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

image-20231218195606809

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

image-20231218195932641

After saving the file and exiting, the terminal will output the following:

For Cron jobs, you can learn about the format and syntax by yourself!

image-20231218200313058

Web preview camera

Use Motion to realize real-time viewing of the video shot by the USB camera on the web page.

Install Motion

image-20231218171842216

Modify the configuration file

Add or modify the following content:

Note:

  1. The above options that are not found in the configuration file can be added directly to the file. For example, the stream_maxrate option needs to be added by yourself, and other options are available.
  2. Frame rate: You can modify it yourself (the above parameters are my best results)
  3. The nano editor can use the Ctrl+W shortcut key to search for keywords and quickly locate the content that needs to be modified

Add the following code: motion runs in the background

image-20231218172322743

Start the service

Web preview screen

Enter the start motion service and start motion commands in the terminal:

image-20231218172352764

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