How do I utilize the built-in camera to take photographs?
You can use the fswebcam app to capture photos with the built-in webcam with a resolution upto VGA (640x480). For detailed usage, consult the Man Page (man fswebcam). Or the Raspberry Pi official documentation.
A quick example of taking a photo:
1) Open a new Terminal window (Ctrl+Alt+t).
2) Type the following command:
fswebcam -r 640x480 Photo1.jpg
3) Post in front of the camera, when ready to take a photo, press Enter.
4) The new photo should be saved as Photo1.jpg in your home directory.
For additional explanation, you can view this short Youtube video.
You can write a Bash script which takes a picture with the webcam and save it with a filename based on the current time. The example script below saves the images in the /home/pi/webcam directory, so create the webcam subdirectory first with:
To create a script named webcam.sh, open up your editor of choice and write (or copy & paste) the following example code:
fswebcam -r 640x480 --no-banner /home/pi/webcam/$DATE.jpg
This script will take a picture and name the image file with a timestamp. Say we saved the script as webcam.sh, we would first make the file executable:
chmod +x webcam.sh
Then run with:
Which would run the commands in the file and give the usual output:
--- Opening /dev/video0...
Trying source module v4l2...
No input was specified, using the first.
--- Capturing frame...
Corrupt JPEG data: 2 extraneous bytes before marker 0xd6
Captured frame in 0.00 seconds.
--- Processing captured image...
Writing JPEG image to '/home/pi/webcam/2022-06-21_143826.jpg'.