Difference between revisions of "OV5647 Camera"
Yousimaier17 (talk | contribs) |
Yousimaier17 (talk | contribs) |
||
Line 550: | Line 550: | ||
rpicam-hello --rotation 0 | rpicam-hello --rotation 0 | ||
</pre> | </pre> | ||
+ | |||
===== Camera Control Options ===== | ===== Camera Control Options ===== | ||
*The following options control the image processing and algorithms that affect the camera's image quality. | *The following options control the image processing and algorithms that affect the camera's image quality. | ||
Line 646: | Line 647: | ||
incadescent 2500K ~ 3000K | incadescent 2500K ~ 3000K | ||
tungsten 3000K ~3500K | tungsten 3000K ~3500K | ||
− | fluorescent | + | fluorescent 4000K ~ 4700K |
− | indoor | + | indoor 3000K ~ 5000K |
daylight 5500K ~ 6500 K | daylight 5500K ~ 6500 K | ||
cloudy 7000K ~ 8500K | cloudy 7000K ~ 8500K |
Revision as of 17:48, 20 January 2025
| ||||||||||||||||||||||
| ||||||||||||||||||||||
|
Contents
Product Parameters
- Pixel: 5 Megapixels
- Image Sensor: OV5647
- Static Image Resolution: 2592 x 1944
- Supports 1080p30, 720p60, and 640x480p60/90 Video Recording
- CMOS Size: 1/4 Inch
- Field of View (FOV): 77°/120°/160°/220°
- Focal Length:
- OV5647 Camera (77): 2.85mm ±5%
- OV5647 Camera (120): 1.79mm ±5%
- OV5647 Camera (160): 1.05mm ±5%
- OV5647 Camera (220): 2.16mm ±5% (Manually Adjustable Focus)
- Infrared Function: Without Infrared, With Infrared
User Instructions
Driver Support
Hardware Connection
Insert the camera's ribbon cable into the slot between the Ethernet port and the HDMI port, with the silver shiny side facing the HDMI port. You need to open the latch of the Raspberry Pi's on-board ribbon cable slot before inserting the cable. The ribbon cable should be inserted tightly into the slot, and care should be taken to avoid bending it. After inserting the ribbon cable, make sure to close the latch of the slot again.
Test Camera
Bullseye System
- Raspberry Pi 5 requires the latest version of Raspberry Pi OS Bookworm.
Note: For the latest Bullseye image, the camera interface is already enabled by default, so there is no need to configure it using raapi-config.
- Open the command line terminal and execute the following commands to get system updates:
sudo apt-get update sudo apt-get upgrade
- Enter the command to preview the camera feed:
sudo libcamera-hello -t 0
- To close the preview window, you can click the 'x' to close it. Alternatively, you can return to the terminal interface and use ctrl-c to terminate the program.
- If you want to capture an image, you can execute the command:
libcamera-jpeg -o test.jpg
Note: If using Camera module 3, autofocus functionality will be enabled.
Buster System
- Open the command line terminal and execute the following commands to get system updates:
sudo apt-get update sudo apt-get upgrade
- Configure the camera using raspi-config. Execute:
sudo raspi-config
- Navigate to: Interfacing Options --> Camera --> Would you like the camera interface to be enabled? Select <Yes>
- Reboot the system: When prompted "Would you like to reboot now?", select Yes
- Alternatively, you can reboot by executing the command:
sudo reboot
- After configuring and connecting the camera, you can use the photo and video functions by powering on the Raspberry Pi.
- Open the Raspberry Pi terminal and start the camera preview:
sudo raspistill -t 0
- To close the preview window, you can terminate the program using ctrl-c.
Checking the Camera
- After installing the camera, you can use the following command to check if there are any issues with the camera and if the development board detects the camera and the number of cameras:
ls /dev/video*
- You can use v4l2-utils to further check the number and specifications of the cameras.
'''Check for comprehensive camera information''' v4l2-ctl --list-devices When multiple cameras are connected, you can use this command to determine the corresponding camera numbers. '''Check the camera's specification parameters''' v4l2-ctl --device=/dev/video0 --list-formats-ext You can change video0 to the camera you want to query.
Accessing the Camera
- To check the version of your system, please execute sudo cat /etc/os-release and look for information related to the following two images, then choose accordingly.
- Raspberry Pi OS Bookworm has changed the camera capture applications from libcamera-* to rpicam-*. Currently, users are allowed to continue using the old libcamera, but libcamera will be deprecated in the future, so please transition to using rpicam as soon as possible.
- If you are using the Raspberry Pi OS Bullseye system, please scroll down to use the #libcamera software stack tutorial in this guide.
Rpicam
- When running the latest version of Raspberry Pi OS, rpicam-apps comes with five basic functions already installed. In this case, the official Raspberry Pi camera will also be detected and automatically enabled.
- You can check if everything is working properly by entering:
rpicam-hello 0
- You will see a camera preview window for about five seconds.
- Note: If you are running on a Raspberry Pi 3 or earlier device with Bullseye, you may need to re-enable Glamor for the X Windows hardware-accelerated preview window to work properly. In the terminal window, enter sudo raspi-config, then select Advanced Options, Glamor, and Yes. Exit and restart your Raspberry Pi. By default, Raspberry Pi 3 and earlier devices running Bullseye may not be using the correct display driver. Please refer to the /boot/firmware/config.txt file and ensure that dtoverlay=vc4-fkms-v3d or dtoverlay=vc4-kms-v3d is currently active. If you need to change this setting, please restart.
rpicam-hello
- This command is used to preview the camera and display the camera feed on the screen.
- Example:
- To preview the camera in real-time, execute the following command in the terminal
rpicam-hello -t 0
- Where -t 0 indicates continuous preview until the program is terminated, and users can adjust it according to their needs.
- Tuning Files:
- Libcamera on Raspberry Pi has tuning files for each different type of camera module. The parameters in these files are passed to the algorithms and hardware to produce the best quality images. Libcamera can only automatically determine the image sensor being used, not the entire module, even though the entire module affects the "tuning". Therefore, it is sometimes necessary to override the default tuning file for a specific sensor.
- For example, the NoIR (No Infra-Red filter) version of the sensor requires different AWB (Auto White Balance) settings compared to the standard version, so the IMX219 NoIR used with a Pi 4 or earlier device should be run as follows:
rpicam-hello --tuning-file /usr/share/libcamera/ipa/rpi/vc4/imx219_noir.json
- The Raspberry Pi 5 uses different tuning files in a different folder, so here you would use:
rpicam-hello --tuning-file /usr/share/libcamera/ipa/rpi/pisp/imx219_noir.json
- This also means that users can copy existing tuning files and make changes according to their preferences, as long as the --tuning-file parameter points to the new version.
- The --tuning-file parameter, like other command-line options, is applicable to all rpicam-apps.
rpicam-jpeg
- This command is a simple program for capturing static images. To capture a full-resolution JPEG image, use the following command, which will display a preview for about five seconds and then capture a full-resolution JPEG image to the file test.jpg.
- Example:
- Executing the following command in the terminal will display a preview for about 5 seconds and then take a full-pixel JPEG image:
rpicam-jpeg -o test.jpg
- Where test.jpg represents the filename.
- The -t <duration> option can be used to change the length of the preview display, and the --width and --height options will change the resolution of the captured static image.
rpicam-jpeg -o test.jpg -t 2000 --width 640 --height 480
Exposure Control:
- All of these rpicam-apps allow users to run the camera with a fixed shutter speed and gain. To capture an image with an exposure time of 20ms and a gain of 1.5x, the gain will be used as analog gain within the sensor until it reaches the maximum analog gain allowed by the kernel sensor driver, after which the remainder will be used as digital gain.
rpicam-jpeg -o test.jpg -t 2000 --shutter 20000 --gain 1.5
- Where --shutter 20000 represents an exposure of 20ms, and --gain 1.5 means the camera gain is set to 1.5x.
- The AEC/AGC algorithm on Raspberry Pi allows applications to specify exposure compensation: it can make the image darker or brighter by a given number of stops.
rpicam-jpeg --ev -0.5 -o darker.jpg rpicam-jpeg --ev 0 -o normal.jpg rpicam-jpeg --ev 0.5 -o brighter.jpg
- Digital Gain:
- Digital gain is applied by the ISP, not by the sensor. The digital gain will always be very close to 1.0 unless:
- The total requested gain (via the --gain option or through the exposure profile in camera adjustments) exceeds the gain that can be used as analog gain within the sensor. Only the additional gain needed will be used as digital gain.
- One of the color gains is less than 1 (please note that color gains are also used as digital gains). In this case, the reported digital gain will stabilize at 1 / the minimum (of red gain, blue gain). This means that a unit digital gain is applied to one of the color channels (other than the green channel).
- AEC/AGC is changing. When AEC/AGC moves, there is usually some degree of change in digital gain to try to eliminate any fluctuations, but it quickly returns to normal.
rpicam-still
- rpicam-still and rpicam-jpeg are very similar, mimicking many of the functions of the original raspistill application.
- Example: To take a photo, execute the following command in the terminal:
rpicam-still -o test.jpg
- Where test.jpg represents the filename.
- Encoder:
- rpicam-still allows files to be saved in multiple different formats. It supports png and bmp encoding. It also allows files to be saved as binary dumps of RGB or YUV pixels, without encoding or file format. In the latter case, the application reading the file must understand its own pixel arrangement.
rpicam-still -e png -o test.png rpicam-still -e bmp -o test.bmp rpicam-still -e rgb -o test.data rpicam-still -e yuv420 -o test.data
- Note that the format in which the image is saved depends on the -e (equivalent to --encoding) option and is not automatically selected based on the output filename.
- Raw Image Capture
- A raw image is the image produced directly by the image sensor before any processing by the ISP (Image Signal Processor) or any CPU cores. For color image sensors, these are typically Bayer format images. Please note that raw images are quite different from the processed but unencoded RGB or YUV images we saw earlier.
- To capture a raw image:
rpicam-still --raw --output test.jpg
- Here, the -r option (also --raw) indicates capturing both the raw image and a JPEG. In practice, the raw image is the raw image from which the JPEG is generated. The raw image is saved in DNG (Adobe Digital Negative) format and is compatible with many standard applications (such as draw or RawTherapee). The raw image is saved to a file with the same name but with a .dng extension, hence test.dng.
- These DNG files contain metadata related to the image capture, including black level, white balance information, and the color matrix used by the ISP to generate the JPEG. This makes these DNG files more convenient for "manual" raw conversion using some of the tools mentioned above at a later time. Use exiftool to display all the metadata encoded into the DNG file:
File Name : test.dng Directory : . File Size : 24 MB File Modification Date/Time : 2021:08:17 16:36:18+01:00 File Access Date/Time : 2021:08:17 16:36:18+01:00 File Inode Change Date/Time : 2021:08:17 16:36:18+01:00 File Permissions : rw-r--r-- File Type : DNG File Type Extension : dng MIME Type : image/x-adobe-dng Exif Byte Order : Little-endian (Intel, II) Make : Raspberry Pi Camera Model Name : /base/soc/i2c0mux/i2c@1/imx477@1a Orientation : Horizontal (normal) Software : rpicam-still Subfile Type : Full-resolution Image Image Width : 4056 Image Height : 3040 Bits Per Sample : 16 Compression : Uncompressed Photometric Interpretation : Color Filter Array Samples Per Pixel : 1 Planar Configuration : Chunky CFA Repeat Pattern Dim : 2 2 CFA Pattern 2 : 2 1 1 0 Black Level Repeat Dim : 2 2 Black Level : 256 256 256 256 White Level : 4095 DNG Version : 1.1.0.0 DNG Backward Version : 1.0.0.0 Unique Camera Model : /base/soc/i2c0mux/i2c@1/imx477@1a Color Matrix 1 : 0.8545269369 -0.2382823821 -0.09044229197 -0.1890484985 1.063961506 0.1062747385 -0.01334283455 0.1440163847 0.2593136724 As Shot Neutral : 0.4754476844 1 0.413686484 Calibration Illuminant 1 : D65 Strip Offsets : 0 Strip Byte Counts : 0 Exposure Time : 1/20 ISO : 400 CFA Pattern : [Blue,Green][Green,Red] Image Size : 4056x3040 Megapixels : 12.3 Shutter Speed : 1/20
- We note that there is only one calibration illuminant (the illuminant determined by the AWB algorithm, although it is always labeled as "D65"), and dividing the ISO number by 100 gives the analog gain being used.
- Long Exposure
- To capture images with long exposures, disable AEC/AGC and AWB, as these algorithms will force the user to wait for many frames while they converge.
- The way to disable them is by providing explicit values. Additionally, the --immediate option can be used to skip the entire preview phase of the capture. Therefore, to perform a 100-second exposure capture, use:
rpicam-still -o long_exposure.jpg --shutter 100000000 --gain 1 --awbgains 1,1 --immediate
- For reference, the maximum exposure times for the three official Raspberry Pi cameras can be found in this table.
rpicam-vid
- rpicam-vid helps us capture video on Raspberry Pi devices. Rpicam-vid displays a preview window and writes the encoded bitstream to the specified output. This produces an unpacked video bitstream that is not packaged in any type of container (such as an mp4 file) format.
- Rpicam-vid uses H.264 encoding.
- For example, the following command writes a 10-second video to a file named test.h264:
rpicam-vid -t 10s -o test.h264
- Where -t 10s indicates recording a 10-second video, and test.h264 is the filename.
- You can play the resulting file using VLC and other video players:
VLC test.h264
- On the Raspberry Pi 5, you can output directly to the MP4 container format by specifying the MP4 file extension for the output file:
rpicam-vid -t 10s -o test.mp4
- Encoder
- Rpicam-vid supports Motion JPEG as well as uncompressed and unformatted YUV420:
rpicam-vid -t 10000 --codec mjpeg -o test.mjpeg rpicam-vid -t 10000 --codec yuv420 -o test.data
- --The --codec option sets the output format, not the file extension of the output file.
- The --segment option splits the output file into chunks of a specified size (in milliseconds). By specifying very short (1 millisecond) segments, this can conveniently decompose a Motion JPEG stream into individual JPEG files. For example, the following command combines 1-millisecond segments with a counter in the output filename, generating a new filename for each segment:
rpicam-vid -t 10000 --codec mjpeg --segment 1 -o test%05d.jpeg
- Capturing High Frame Rate Video
- To minimize frame loss for high frame rate (> 60fps) video, try the following configuration adjustments:
- Set the H.264 target level to 4.2 using the --level 4.2 parameter.
- Disable software color denoising by setting the denoise option to cdn_off.
- Disable the display window with the nopreview option to free up some additional CPU cycles.
- Set force_turbo=1 in /boot/firmware/config.txt to ensure that the CPU clock does not throttle during video capture. For more information, refer to the force_turbo documentation.
- Adjust the ISP output resolution parameters to --width 1280 --height 720 or lower to achieve the frame rate target.
- On the Raspberry Pi 4, you can overclock the GPU to improve performance by adding gpu_freq=550 or a higher frequency in /boot/firmware/config.txt. For details, refer to the overclocking documentation.
- The following command demonstrates how to achieve 1280×720 120fps video:
- To minimize frame loss for high frame rate (> 60fps) video, try the following configuration adjustments:
rpicam-vid --level 4.2 --framerate 120 --width 1280 --height 720 --save-pts timestamp.pts -o video.264 -t 10000 --denoise cdn_off -n
- Integration of Libav with picam-vid
- Rpicam-vid can encode audio and video streams using the ffmpeg/libav codec backend. You can save these streams to files or stream them over a network.
- To enable the libav backend, pass libav to the codec option:
rpicam-vid --codec libav --libav-format avi --libav-audio --output example.avi
- UDP
- To stream video over UDP using the Raspberry Pi as a server, use the following command, replacing the <IP-addr> placeholder with the IP address of the client or multicast address, and the <port> placeholder with the port you want to use for streaming:
rpicam-vid -t 0 --inline -o udp://<ip-addr>:<port>
- To view the video stream over UDP using the Raspberry Pi as a client, use the following command, replacing the <port> placeholder with the port you want to stream on:
vlc udp://@:<port> :demux=h264
- Alternatively, use the following command on the client to stream using ffplay:
ffplay udp://<ip-addr-of-server>:<port> -fflags nobuffer -flags low_delay -framedrop
- TCP
- Video can also be transmitted over TCP. Use the Raspberry Pi as a server:
rpicam-vid -t 0 --inline --listen -o tcp://0.0.0.0:<port>
- To view the video stream over TCP using the Raspberry Pi as a client, use the following command:
vlc tcp/h264://<ip-addr-of-server>:<port>
- Alternatively, use the following command on the client to stream using ffplay at 30 frames per second:
ffplay tcp://<ip-addr-of-server>:<port> -vf "setpts=N/30" -fflags nobuffer -flags low_delay -framedrop
- RTSP
- To stream video over RTSP using VLC with the Raspberry Pi as a server, use the following command:
rpicam-vid -t 0 --inline -o - | cvlc stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/stream1}' :demux=h264
- To view the video stream over RTSP using the Raspberry Pi as a client, use the following command:
ffplay rtsp://<ip-addr-of-server>:8554/stream1 -vf "setpts=N/30" -fflags nobuffer -flags low_delay -framedrop
- Or use the following command on the client to stream using VLC:
vlc rtsp://<ip-addr-of-server>:8554/stream1
- If you need to close the preview window on the server, use the nopreview command.
- Use the inline flag to force stream header information into each inline frame, which helps clients understand the stream if they miss the beginning.
rpicam-raw
- rpicam-raw records video directly from the sensor as raw Bayer frames. It does not display a preview window. To record a two-second raw clip into a file named test.raw, execute the following command:
- To record a 2-second raw data clip, run the following command in the terminal:
rpicam-raw -t 2000 -o test.raw
- Rpicam-raw outputs raw frames without any format information. The application prints the pixel format and image dimensions to the terminal window to assist users in parsing the pixel data.
- By default, rpicam-raw outputs raw frames in a single, potentially very large file. Use the segment option to direct each raw frame to a separate file, using the %05d directive to make
rpicam-raw -t 2000 --segment 1 -o test%05d.raw
- With fast storage devices, rpicam-raw can write 18MB, 12MP HQ camera frames to disk at 10fps. Rpicam-raw cannot format output frames as DNG files; to achieve this, use rpicam-still with a framerate option below 10 to avoid dropped frames:
rpicam-raw -t 5000 --width 4056 --height 3040 -o test.raw --framerate 8
- For more information on the raw format, please refer to the mode documentation.
rpicam-detect
- Note: rpicam-detect is not included in the Raspberry Pi OS. If you have installed TensorFlow Lite, you can build rpicam-detect. For more information, see the rpicam-apps build instructions. Don't forget to pass -DENABLE_TFLITE=1 when running cmake.
- rpicam-detect displays a preview window and uses the Google MobileNet v1 SSD (Single Shot Detector) neural network, trained to recognize approximately 80 classes of objects using the Coco dataset. Rpicam-detect can identify people, cars, cats, and many other objects.
- Whenever rpicam-detect detects a target object, it captures a full-resolution JPEG. It then returns to monitoring preview mode.
- For general information on using the model, please refer to the TensorFlow Lite Object Detector section. For example, you can monitor your cat while you're away:
rpicam-detect -t 0 -o cat%04d.jpg --lores-width 400 --lores-height 300 --post-process-file object_detect_tf.json --object cat
rpicam Parameter Settings
- Print program help information, which lists the available setting options for each program command, and then exit.
rpicam-hello -h
- --version outputs the version strings for libcamera and rpicam-apps
rpicam-hello --version
- Example output:
rpicam-apps build: ca559f46a97a 27-09-2021 (14:10:24) libcamera build: v0.0.0+3058-c29143f7
- --list-cameras lists the cameras connected to the Raspberry Pi and their available sensor modes
rpicam-hello --list-cameras
- Sensor mode identifiers have the following format:
S<Bayer order><Bit-depth>_<Optional packing> : <Resolution list>
- Cropping is specified in native sensor pixels (even in pixel binning modes) as (<x>, <y>)/<Width>×<Height>. (x, y) specifies the position of the cropping window of size width × height within the sensor array.
- For example, the following output shows information for an IMX219 sensor with index 0 and an IMX477 sensor with index 1:
Available cameras ----------------- 0 : imx219 [3280x2464] (/base/soc/i2c0mux/i2c@1/imx219@10) Modes: 'SRGGB10_CSI2P' : 640x480 [206.65 fps - (1000, 752)/1280x960 crop] 1640x1232 [41.85 fps - (0, 0)/3280x2464 crop] 1920x1080 [47.57 fps - (680, 692)/1920x1080 crop] 3280x2464 [21.19 fps - (0, 0)/3280x2464 crop] 'SRGGB8' : 640x480 [206.65 fps - (1000, 752)/1280x960 crop] 1640x1232 [41.85 fps - (0, 0)/3280x2464 crop] 1920x1080 [47.57 fps - (680, 692)/1920x1080 crop] 3280x2464 [21.19 fps - (0, 0)/3280x2464 crop] 1 : imx477 [4056x3040] (/base/soc/i2c0mux/i2c@1/imx477@1a) Modes: 'SRGGB10_CSI2P' : 1332x990 [120.05 fps - (696, 528)/2664x1980 crop] 'SRGGB12_CSI2P' : 2028x1080 [50.03 fps - (0, 440)/4056x2160 crop] 2028x1520 [40.01 fps - (0, 0)/4056x3040 crop] 4056x3040 [10.00 fps - (0, 0)/4056x3040 crop]
- --camera Select the camera to use. Specify an index from the list of available cameras.
rpicam-hello --list-cameras 0 rpicam-hello --list-cameras 1
- --config -c, Specify a file containing command parameters and values. Typically named example_configuration.txt, with options and values specified as key-value pairs, one per line.
timeout=99000 verbose=
- Note: Omit the -- prefix usually used for parameters in the command line. For flags without values, such as verbose in the example above, a trailing = must be included.
- Then you can run the following command to specify a timeout of 99000 milliseconds and verbose output:
rpicam-hello --config example_configuration.txt
- --time -t, Default delay of 5000 milliseconds.
rpicam-hello -t
- Specify how long the application runs before shutting down. This applies to video recording and preview windows. When capturing still images, the application displays a preview window for the timeout milliseconds before capturing the output image.
rpicam-hello -t 0
- --preview Set the position (x, y coordinates) and size (w, h dimensions) of the desktop or DRM preview window. Does not affect the resolution or aspect ratio of the image requested from the camera.
- Pass the preview window dimensions in the following comma-separated format: x,y,w,h
rpicam-hello --preview 100,100,500,500
- --fullscreen -f, Forces the preview window to use the entire screen with no borders or title bar. Scales the image to fit the entire screen. Does not accept a value.
rpicam-hello -f
- --qt-preview Uses a Qt preview window, which consumes more resources than other options but supports X window forwarding. Incompatible with the fullscreen flag. Does not accept a value.
rpicam-hello --qt-preview
- --nopreview Prevents the application from displaying a preview window. Does not accept a value.
rpicam-hello --nopreview
- --info-text
- Default: "#%frame (%fps fps) exp %exp ag %ag dg %dg"
- When running in a desktop environment, sets the provided string as the title of the preview window. Supports the following image metadata substitutions:
Command Description %frame Frame sequence number %fps Instantaneous frame rate %exp Shutter speed when the image was captured, in ms %ag Image analog gain controlled by the sensor chip %dg Image digital gain controlled by the ISP %rg Gain for the red component of each pixel %bg Gain for the blue component of each pixel %focus Focus measure of the image, with higher values indicating sharper images %lp Current lens diopter (distance in 1/meters) %afstate Auto-focus status (idle, scanning, focused, failed)
rpicam-hello --info-test "Focus measure: %focus"
- --width
- --height
- Each accepts a single number to define the dimensions (in pixels) of the captured image.
- For rpicam-still, rpicam-jpeg, and rpicam-vid, specifies the output resolution.
- For rpicam-raw, specifies the raw frame resolution. For cameras with a 2×2 bin readout mode, specify a resolution equal to or less than the bin mode to capture 2×2 bin raw frames.
- Has no effect with rpicam-hello.
- Record 1080p video
rpicam-vid -o test.h264 --width 1920 --height 1080
- Capture a JPEG at 2028×1520 resolution. If used with an HQ camera, uses 2×2 bin mode, so the raw file (test.ng) contains a 2028×1520 raw Bayer image.
rpicam-still -r -o test.jpg --width 2028 --height 1520
- --viewfinder-width
- --viewfinder-height
- Each accepts a number to define the dimensions (in pixels) of the image displayed in the preview window. Does not affect the size of the preview window, as the image is resized to fit. Does not affect captured still images or videos.
rpicam-still --viewfinder-width 1920 --viewfinder-height 1080
- --mode Allows specifying the camera mode in the following colon-separated format: <width>:<height>:<bit-depth>:<packing>. If the provided values do not match exactly, the system selects the closest available option for the sensor. Use packed (P) or unpacked (U) formats, which affect the format of stored video and still images but not the format of frames passed to the preview window.
- Bit-depth and packing are optional, with a default bit-depth of 12 and packing of P (packed). For information on bit depths, resolutions, and packing options available for your sensor, see list-cameras. Examples:
- 4056:3040:12:P - 4056×3040 resolution, 12 bits/pixel, packed.
- 1632:1224:10 - 1632×1224 resolution, 10 bits/pixel.
- 2592:1944:10:U - 2592×1944 resolution, 10 bits/pixel, unpacked.
- 3264:2448 - 3264×2448 resolution.
- --viewfinder-mode Same as the mode option but applies to the data passed to the preview window. For more information, see the mode documentation.
- --lores-width and --lores-height
- Provide a second, low-resolution image stream from the camera, scaled down to the specified dimensions. Each accepts a number to define the dimensions (in pixels) of the low-resolution stream. Available for preview and video modes. Not provided for still captures. For rpicam-vid, disables additional color denoising processing. Useful for image analysis in conjunction with image post-processing.
rpicam-hello --lores-width 224 --lores-height 224
- --hflip Horizontally flips the image. Does not accept a value.
rpicam-hello --hflip -t 0
- --vflip Vertically flips the image. Does not accept a value.
rpicam-hello --vflip -t 0
- --rotation Rotates the image extracted from the sensor. Only accepts values 0 or 180.
rpicam-hello --rotation 0
- --roi Crops the image extracted from the full sensor domain. Accepts four decimal values ranging from 0 to 1 in the following format: <x>,<y>,<w>,<h>. Each of these values represents a percentage of the available width and height as a decimal between 0 and 1.
- These values define the following proportions:
<x>: X coordinate to skip before extracting the image <y>: Y coordinate to skip before extracting the image <w>: Width of the image to extract <h>: Height of the image to extract
- Default is 0,0,1,1 (start from the first X coordinate and the first Y coordinate, use 100% of the image width, and use 100% of the image height).
- Examples:
- rpicam-hello --roi 0.25,0.25,0.5,0.5 selects half of the total pixels cropped from the center of the image (skip the first 25% of the X coordinates, skip the first 25% of the Y coordinates, use 50% of the total image width, and use 50% of the total image height).
- rpicam-hello --roi 0,0,0.25,0.25 selects one-quarter of the total pixels cropped from the top-left corner of the image (skip 0% of the X coordinates, skip 0% of the Y coordinates, use 25% of the image width, and use 25% of the image height).
- --rotation Rotate the image extracted from the sensor. Only values 0 or 180 are accepted.
- off - Disable HDR.
- auto - Enable HDR on supported devices. Use the sensor's built-in HDR mode if available. If the sensor does not have a built-in HDR mode, use the on-board HDR mode (if available).
- single-exp Enable HDR on supported devices. Use the sensor's built-in HDR mode if available. If the sensor does not have a built-in HDR mode, use the on-board HDR mode (if available).
rpicam-hello --hdr
- Use the on-board HDR mode if available, even if the sensor has a built-in HDR mode. If the on-board HDR mode is not available, disable HDR.
- Raspberry Pi 5 and later devices have an on-board HDR mode.
- To check for built-in HDR mode in the sensor, add this option to list the cameras.
rpicam-hello --rotation 0
Camera Control Options
- The following options control the image processing and algorithms that affect the camera's image quality.
- Sharpness
- Sets the image sharpness. Accepts values within the following range:
- 0.0 applies no sharpening
- Values greater than 0.0 but less than 1.0 apply less sharpening than the default
- 1.0 applies the default amount of sharpening
- Values greater than 1.0 apply additional sharpening
- Sets the image sharpness. Accepts values within the following range:
rpicam-hello --sharpness 0.0
- Contrast
- Specifies the image contrast. Accepts values within the following range:
- 0.0 applies minimum contrast
- Values greater than 0.0 but less than 1.0 apply less contrast than the default
- 1.0 applies the default contrast
- Values greater than 1.0 apply additional contrast
- Specifies the image contrast. Accepts values within the following range:
rpicam-hello --contrast 0.0
- Brightness
- Specifies the image brightness, added as an offset to all pixels in the output image. Accepts values within the following range:
- -1.0 for minimum brightness (black)
- 0.0 applies standard brightness
- 1.0 applies maximum brightness (white)
- For more usage, refer to ev.
- Specifies the image brightness, added as an offset to all pixels in the output image. Accepts values within the following range:
rpicam-hello --brightness 1.0
- Saturation
- Specifies the image color saturation. Accepts values within the following range:
- 0.0 applies minimum saturation (grayscale)
- Values greater than 0.0 but less than 1.0 apply less saturation than the default
- 1.0 applies the default saturation
- Values greater than 1.0 apply additional saturation
- Specifies the image color saturation. Accepts values within the following range:
rpicam-hello --saturation 0.6
- EV
- Specifies the Exposure Value (EV) compensation for the image. Accepts a numerical value that controls the target value passed to the auto-exposure/gain control (AEC/AGC) processing algorithm along the following spectrum:
- -10.0 applies the minimum target value
- 0.0 applies the standard target value
- 10.0 applies the maximum target value
- Specifies the Exposure Value (EV) compensation for the image. Accepts a numerical value that controls the target value passed to the auto-exposure/gain control (AEC/AGC) processing algorithm along the following spectrum:
rpicam-hello --ev 10.0
- Shutter
- Specifies the exposure time using the shutter, in microseconds. When you use this option, the gain can still vary. If the camera operates at a frame rate that is too fast to allow the specified exposure time (e.g., 1 fps with an exposure time of 10000 microseconds), the sensor will use the maximum exposure time allowed by the frame rate.
- For a list of minimum and maximum shutter times for the official camera, please refer to the camera hardware documentation. Values higher than the maximum may result in undefined behavior.
rpicam-hello --shutter 10000
- Gain
- analoggain has the same effect as gain
- Sets the combined analog and digital gain. Only analog gain is used when the sensor driver can provide the required gain. When the analog gain reaches its maximum, the ISP applies digital gain. Accepts numerical values.
- For a list of analog gain limits for the official camera, please refer to the camera hardware documentation.
- Sometimes, the digital gain may exceed 1.0 even when the analog gain limit is not exceeded. This can occur in the following situations:
- When any of the color gains are below 1.0, which results in the digital gain stabilizing at 1.0/min(red gain, blue gain). This applies the total digital gain to any color channel above 1.0 to avoid color shift artifacts.
- Slight differences when auto-exposure/gain control (AEC/AGC) changes.
rpicam-hello --gain 0.8
- Metering (Default: centre)
- Sets the metering mode for the auto-exposure/gain control (AEC/AGC) algorithm. Accepts the following values:
- centre for center-weighted metering
- spot for spot metering
- average for average or full-frame metering
- custom for a custom metering mode defined in the camera tuning file
- For more information on defining custom metering modes and adjusting zone weights in existing metering modes, please refer to the Tuning Guide for Raspberry Pi Camera and libcamera.
- Sets the metering mode for the auto-exposure/gain control (AEC/AGC) algorithm. Accepts the following values:
rpicam-hello --metering centre
- Exposure
- Sets the exposure profile. Changing the exposure profile should not affect the image exposure. Instead, different modes adjust the gain settings to achieve the same net result. Accepts the following values:
- sport: short exposure time, high gain
- normal: normal exposure, normal gain
- long: long exposure time, low gain
- You can edit the exposure profiles using a tuning file. For more information, please refer to the Tuning Guide for Raspberry Pi Camera and libcamera.
- Sets the exposure profile. Changing the exposure profile should not affect the image exposure. Instead, different modes adjust the gain settings to achieve the same net result. Accepts the following values:
rpicam-hello --exposure sport
- AWB
- Sets the exposure profile. Changing the exposure profile should not affect the image exposure. Instead, different modes adjust the gain settings to achieve the same final result. Available white balance modes:
Mode Color Temperature auto 2500K ~ 8000K incadescent 2500K ~ 3000K tungsten 3000K ~3500K fluorescent 4000K ~ 4700K indoor 3000K ~ 5000K daylight 5500K ~ 6500 K cloudy 7000K ~ 8500K custom custom Custom range, set via tuning file
- No mode completely disables AWB. Instead, you can use awbgains to adjust color gains.
- For more information on AWB modes, including how to define custom modes, please refer to the Tuning Guide for Raspberry Pi Camera and libcamera.
rpicam-hello --awb auto
- AWBGains
- Sets fixed red and blue gain values to replace the auto white balance (AWB) algorithm. Setting non-zero values disables AWB. Accepts comma-separated numerical input in the format: <red_gain>,<blue_gain>
rpicam-jpeg -o test.jpg --awbgains 1.5,2.0
- Denoise
- Default: auto
- Sets the denoising mode. Accepts the following values:
- auto: enables standard spatial denoising. Uses ultra-fast color denoising for video and high-quality color denoising for images. Does not enable additional color noise reduction in the preview window.
- off: turns off both spatial and color denoising.
- cdn_off: disables color noise.
- cdn_fast: uses fast color denoising.
- cdn_hq: uses high-quality color denoising. Not suitable for video/viewfinder due to reduced throughput.
- Even fast color denoising can reduce the frame rate. High-quality color denoising significantly reduces the frame rate.
rpicam-hello --denoise off
- Tuning-file
- Specifies the camera tuning file. Tuning files allow you to control many aspects of image processing, including auto-exposure/gain control (AEC/AGC), auto white balance (AWB), color shading correction, color processing, denoising, and more. Accepts the tuning file path as input. For detailed information on tuning files, please refer to Tuning Files.
- Autofocus-mode
- Default: default
- Specifies the autofocus mode. Accepts the following values:
- default: puts the camera in continuous autofocus mode unless the lens position or autofocus capture overrides to manual mode
- manual: does not move the lens unless the lens position is manually configured
- auto: only moves the lens for an autofocus scan when the camera starts or before capturing, if autofocus capture is also used
- continuous: automatically adjusts the lens position as the scene changes
- This option is only supported by certain camera
rpicam-hello --autofocus-mode auto
- autofocus-range
- Default value: normal
- Specifies the autofocus range. Accepts the following values:
- normal: Focus range is fairly close to infinity
- macro: Only focuses on nearby objects, including the closest focal distance supported by the camera
- full: Focuses on the entire range, from the nearest object to infinity
- This option is only supported by certain camera modules.
rpicam-hello autofocus-range normal
- autofocus-speed
- Default value: normal
- Specifies the autofocus speed. Accepts the following values:
- normal: Changes the lens position at a normal speed
- fast: Quickly changes the lens position
- This option is only supported by certain camera modules.
rpicam-hello --autofocus-speed normal
- autofocus-window
- Specifies the autofocus window within the full area of the sensor. Accepts four decimal values ranging from 0 to 1, in the format: <x>, <y>, <w>, <h>. Each of these values is represented as a fraction between 0 and 1, indicating a percentage of the available width and height.
- These values define the following proportions:
- <x>: X-coordinate to skip before applying autofocus
- <y>: Y-coordinate to skip before applying autofocus
- <w>: Width of the autofocus area
- <h>: Height of the autofocus area
- The default value uses the middle third of the output image in both dimensions (1/9 of the total image area).
- Examples:
rpicam-hello—autofocus-window 0.25,0.25,0.5,0.5
- Selects half of the total number of pixels cropped from the center of the image (skips the first 25% of the X-coordinate, skips the first 25% of the Y-coordinate, uses 50% of the total image width, uses 50% of the total image height).
rpicam-hello—autofocus-window 0,0,0.25,0.25
- Selects one-quarter of the total number of pixels cropped from the top-left corner of the image (skips 0% of the X-coordinate, skips 0% of the Y-coordinate, uses 25% of the image width, uses 25% of the image height).
This option is only supported by certain camera modules.
- lens-position
- Default value: default
- Moves the lens to a fixed focal distance, typically represented in diopters (units of 1/meter distance). Accepts the following range of values:
- 0.0: Moves the lens to the "infinity" position
- Any other number: Moves the lens to the 1/number position. For example, a value of 2.0 will focus at approximately 0.5m
- normal: Moves the lens to the default position corresponding to the lens's hyperfocal distance
- Lens calibration is not perfect, so different camera modules of the same model may vary.
- verbose
- Alias: -v
- Default value: 1
- Sets the verbosity level. Accepts the following values:
- 0: No output
- 1: Normal output
- 2: Verbose output
rpicam-hello --verbose 1
- For more detailed information, refer here.
libcamera软件栈
libcamera-hello
- 该命令用来预览摄像头并将摄像头画面显示在屏幕上。
- 示例:
- 终端执行以下语句即可实时预览摄像头
libcamera-hello -t 0
- 其中 -t 0 表示一直预览至终止程序,用户可根据自己的需要进行调整。
- 调谐文件:
- 树莓派的libcamera驱动会针对不同的摄像头模块调用一个调谐文件,调谐文件中提供了各种参数,器调用摄像头的时候,libcamera会调用调谐文件中的参数,结合算法对图像进行处理最终输出成预览画面。由于libcamera驱动只能自动感光芯片信号,但是摄像头的最终显示效果还会受整个模块的影响,调谐文件的使用就是为了可以灵活处理不同模块的摄像头,调整提高图像质量。
- 如果在使用默认调谐文件的情况下,摄像头的输出图像不理想的话,用户可以通过调用自定义的调谐文件来对图像进行调整。比如,如果你使用的是官方的NOIR版本摄像头,相对于于Raspberry Pi Camera V2 常规款,NOIR摄像头可能需要不同的白平衡参数,这种情况下就可以通过调用调谐文件来进行切换。
libcamera-hello --tuning-file /usr/share/libcamera/ipa/raspberrypi/imx219_noir.json
- 用户可以复制默认的调谐文件,根据自己的需求进行修改。
- 备注:调谐文件的使用适用于其他的libcamera指令,后续指令中就不再做介绍
- 预览窗口:
- 大部分的libcamera指令都会显示一个预览窗口在屏幕上,用户可以通过--info-text 参数来自定义预览窗口的标题信息, 同时也可以通过%directives 调用一些摄像头参数并显示在窗口上
- 比如如果使用HQ Camera: 可以通过--info-txe "%focus" 在窗口上显示摄像头的焦距
libcamera-hello --info-text "focus %focus"
- 备注:更多关于参数的设置,可以参考后续的指令参数设置章节
libcamera-jpeg
- 该命令一个简单的静态图片拍摄程序,libcamera-jpeg相对于libcamera-still来讲更加简洁,并且有很多相同的功能来完成图片拍摄。
- 示例:
- 终端执行以下语句会显示一个5秒左右的预览串口,然后拍摄一张全像素的JPEG图像:
libcamera-jpeg -o test.jpg
- 其中test.jpg表示文件名
- 曝光控制:
- 用户可以通过-t 参数来设置预览时间,同时可以通过--width 和 --height来设置拍摄图像的分辨率。例如
libcamera-jpeg -o test.jpg -t 2000 --width 640 --height 480
- 所有的libcamera指令都允许用户自己设置快门时间和增益,比如:
libcamera-jpeg -o test.jpg -t 2000 --shutter 20000 --gain 1.5
- 其中 --shutter 20000 表示曝光 20ms, --gain 1.5 表示摄像头增益被设置为1.5倍。
- 这个指令会拍摄一张图像,拍摄中会曝光20ms并且摄像头增益被设置为1.5倍。设置的增益参数,会首先设置感光芯片内部的模拟增益参数,如果设置的增益超过了驱动内置的最大的模拟增益的数值,会先设置芯片的最大模拟增益,然后将剩下的增益倍数作为数字增益来生效。
- 备注:数字增益是通过ISP(图像信号处理)来实现的,并非是直接调整芯片内置寄存器。正常情况下,默认的数字增益趋近于1.0,除非是有有以下三种情况。
- 整体的增益参数需求,也就是当模拟增益无法满足设定的增益参数需求的时候,会需要数字增益来做补偿
- 其中一个颜色增益小于1 (颜色增益是通过数字增益来实现的),在这种情况下, 最后获得增益就是稳定为 1/min(red_gain, blue_gain), 也就是实际是上应用了统一的数字增益, 且是其中一个颜色通道的增益值(非绿色通道)。
- AEC/AGC被修改了。如果AEC/AGC有变化的时候, 数值增益也会一定程度上会发生变化,从何来来消除任何波动,但是这种变化会被快速恢复到"正常"值
- 树莓派的AEC/AGX算法允许程序指定曝光补偿,也就是通过设置光圈数值来调整图像的亮度。比如:
libcamera-jpeg --ev -0.5 -o darker.jpg libcamera-jpeg --ev 0 -o normal.jpg libcamera-jpeg --ev 0.5 -o brighter.jpg
libcamera-still
- libcamera-still和libcamera-jpeg非常相似,不同的是libcamera继承了更多raspistill的功能。
- 示例:终端执行以下语句即可拍照
libcamera-still -o test.jpg
- 其中test.jpg表示文件名
- 编码器:
- libcamea-still支持不同格式的图像文件,可以支持png和bmp编码,也支持直接不带编码或者任何图像格式地将RGB或者YUV像素的二进制转储保存成文件。如果是直接保存RGB或者YUV数据,程序在读取此类文件的时候必须了解文件的像素排列方式。
libcamera-still -e png -o test.png libcamera-still -e bmp -o test.bmp libcamera-still -e rgb -o test.data libcamera-still -e yuv420 -o test.data
- 图像保存的格式是通过-e参数控制的, 如果没有调用-e参数设置的话,默认按照输出的文件名的格式保存。
- 原始图像拍摄
- 原始图像(Raw image)图像就是直接图像传感器输出的图像, 没有经过任何ISP或者CPU处理。对于彩色相机传感器,一般来说原始图像的输出格式是Bayer. 注意原始图和我们之前说的位编码的RGB和YUV图像不同,RGB和YUV也是经过ISP处理后的图像的。
- 拍摄一张原始图像的指令:
libcamera-still -r -o test.jpg
- 原始图像一般是以DNG (Adobe digital Negative) 格式保存的,DNG格式可以兼容大部分标准程序, 比如dcraw 或者RawTherapee. 原始图像会被保存为.dng后缀的相同名字的文件,比如如果运行上面的指令,为被另存为test.dng, 并同时生成一张jpeg文件。DNG文件中包含了已图像获取有关的元数据, 比如白平衡数据,ISP颜色矩阵等。
- 超长曝光
- 如果要拍摄一张超长曝光的图片,我们需要禁用AEC/AGC和白平衡,否则这些算法会导致图片在收敛的时候多等待很多帧数据。禁用这些算法需要另设置显式值,另外, 用户可以通过--immediate设置来跳过预览过程。
- 这里是拍摄一张曝光100秒的图像指令:
libcamera-still -o long_exposure.jpg --shutter 100000000 --gain 1 --awbgains 1,1 --immediate
- 备注:几款官方摄像头的最长曝光时间参考表格.
libcamera-vid
- libcamera-vid是一个视频录制程序, 默认使用的是树莓派的硬件H.264编码器。这个程序运行之后会在屏幕上显示一个预览窗口,同时将比特流编码输出到指定文件。
- 示例:终端执行以下语句即可录制视频
libcamera-vid -t 10000 -o test.h264
- 其中-t 10000 表示录制10秒的视频,test.h264表示文件名
- 如果要查看视频可以用vlc来进行播放
vlc test.h264
- 备注:录制的是未打包的视频流, 用户可以使用--save-pts 设置输出时间戳,方便后续将比特流转成其他视频格式。
libcamera-vid -o test.h264 --save-pts timestamps.txt
- 如果想要输出mkv文件,可以用以下指令:
mkvmerge -o test.mkv --timecodes 0:timestamps.txt test.h264
- 编码器
- 树莓派支持JPEG格式以及没有压缩和格式的YUV420:
libcamera-vid -t 10000 --codec mjpeg -o test.mjpeg libcamera-vid -t 10000 --codec yuv420 -o test.data
- --codec选项设置的是输出格式,而不是输出文件的扩展名。
- 使用--segment参数可以将输出文件分割成段(单位是ms),适用于需要脚JPEG视频流分割成单独的时间比较短(大概1ms)的JPEG文件
libcamera-vid -t 10000 --codec mjpeg --segment 1 -o test%05d.jpeg
- UDP 视频流传输
- 可以使用UDP进行视频流传输,树莓派端运行(server):
libcamera-vid -t 0 --inline -o udp://<ip-addr>:<port>
- 其中<ip-addr>需要替换成实际的客户端IP地址或者组播地址。
- 在客户端(client),输入以下指令进行视频流获取和显示(两个指令使用一种即可);
vlc udp://@:<port> :demux=h264 vlc udp://@:<port> :demux=h264
- 注意:port需要跟你在树莓派端设置的一致
- TCP视频流传输
- 可以使用TCp进行视频流传输, 树莓派端运行(server):
libcamera-vid -t 0 --inline --listen -o tcp://0.0.0.0:<port>
- 客户端(client)运行:
vlc tcp/h264://<ip-addr-of-server>:<port> #两条指令选一条即可 ffplay tcp://<ip-addr-of-server>:<port> -vf "setpts=N/30" -fflags nobuffer -flags low_delay -framedrop
- RTSP视频流传输
- 在树莓派上,通常使用vlc来对RTSP视频流做处理,
libcamera-vid -t 0 --inline -o - | cvlc stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/stream1}' :demux=h264
- 播放端,可以运行以下任一条指令:
vlc rtsp://<ip-addr-of-server>:8554/stream1 ffplay rtsp://<ip-addr-of-server>:8554/stream1 -vf "setpts=N/30" -fflags nobuffer -flags low_delay -framedrop
- 在所有预览指令中,如果想要关掉树莓派端的预览窗口,可以用参数-n(--nopreview)设置。另外注意--inline参数的设置,改设置会强制将视频流的报头信息包含在每个 I (intra)帧中,这个设置可以让客户端在丢失视频头的情况下仍然可以正确解析视频流。
- 高帧率模式
- 如果使用libcamera-vid指令录制高帧率视频(一般高于60fps),同时减少丢帧情况,需要注意以下几点:
- H264 的目标级别需要设置成4.2, 可以使用--level 4.2 参数设置
- 必须关闭彩色降噪功能,可以使用--denoise cdn_off参数设置
- 如果设置的帧率高于100fps,关掉预览窗口,释放更多CPU资源,避免丢帧。可以使用参数-n设置
- 建议在/boot/config.txt文件中添加设置force_turbo=1, 来保证视频流或中中,CPU时钟不会被限制
- 调整ISP输出分辨率,使用-width 1280 --height 720 设置分辨率,或者设置成更低的分辨率,具体以摄像头型号为准。
- 如果你使用的是Pi 4或这个更高性能的型号,可以在/boot/config.txt文件中添加设置gpu_freq=550或者更高,来对主板GPU进行超频,来达到更高的性能效果。
- 例如,录制 1280 x720 120fps视频。
- 如果使用libcamera-vid指令录制高帧率视频(一般高于60fps),同时减少丢帧情况,需要注意以下几点:
libcamera-vid --level 4.2 --framerate 120 --width 1280 --height 720 --save-pts timestamp.pts -o video.264 -t 10000 --denoise cdn_off -n
libcamera-raw
- libcamera-raw类似于视频录制程序,不同的地方时,libcamera-raw录制的是直接传感器输出的Bayer格式的数据,也就是原始图像数据。libcamera-raw不会显示预览窗口。
- 终端执行以下语句即可录制一个2秒的原始数据片段:
libcamera-raw -t 2000 -o test.raw
- 程序会在没有格式信息的情况下直接转储原始帧,程序会将像素格式和图像尺寸直接打印在终端,用户可以根据输出的数据查看像素数据.默认情况下,程序会将原始帧保存成一个文件,文件通常比较大,用户可以通过--segement参数将文件进行分割。
libcamera-raw -t 2000 --segment 1 -o test%05d.raw
- 如果内存条件比较好(比如使用SSD), libcamera-raw可以以大概10帧每秒的速度将官方的HQ Camera的数据(大概18MB每帧)写入到硬盘中, 为了达到这个速度,程序写入的是没有格式化过的原始帧,没有办法像libcamera-still那样保存成DNG文件。 如果想要确保不出现丢帧的情况,可以使用--framerate 降低帧率。
libcamera-raw -t 5000 --width 4056 --height 3040 -o test.raw --framerate 8
通用的指令设置选项
通用的指令设置选项适用于libcamera的所有指令
- 打印程序帮助信息,可以打印每个程序指令的可用设置选项,然后退出.
--help -h
- 所有libcamera-apps 在看到 --version 选项时,都会打印出 libcamera 和 libcamera-apps 的版本字符串,然后退出
--version
libcamera-apps build: ca559f46a97a 27-09-2021 (14:10:24) libcamera build: v0.0.0+3058-c29143f7
- 显示识别到的可支持的摄像头,同时列出了每个摄像头支持的传感器模式。
--list-cameras
Available cameras ----------------- 0 : imx219 [3280x2464] (/base/soc/i2c0mux/i2c@1/imx219@10) Modes: 'SRGGB10_CSI2P' : 640x480 [206.65 fps - (1000, 752)/1280x960 crop] 1640x1232 [41.85 fps - (0, 0)/3280x2464 crop] 1920x1080 [47.57 fps - (680, 692)/1920x1080 crop] 3280x2464 [21.19 fps - (0, 0)/3280x2464 crop] 'SRGGB8' : 640x480 [206.65 fps - (1000, 752)/1280x960 crop] 1640x1232 [41.85 fps - (0, 0)/3280x2464 crop] 1920x1080 [47.57 fps - (680, 692)/1920x1080 crop] 3280x2464 [21.19 fps - (0, 0)/3280x2464 crop] 1 : imx477 [4056x3040] (/base/soc/i2c0mux/i2c@1/imx477@1a) Modes: 'SRGGB10_CSI2P' : 1332x990 [120.05 fps - (696, 528)/2664x1980 crop] 'SRGGB12_CSI2P' : 2028x1080 [50.03 fps - (0, 440)/4056x2160 crop] 2028x1520 [40.01 fps - (0, 0)/4056x3040 crop] 4056x3040 [10.00 fps - (0, 0)/4056x3040 crop]
- 按照打印的信息, IMX219摄像头后缀0, IM新477摄像头后缀1. 在调用摄像头的时候,就可以对应的后缀进行指定
- 指定摄像头
--camera
- 对应的后缀可以参考指令--list-camera的打印信息。
- 设置指定文件
--config -c
- 一般情况下,我们可以通过指令直接设置摄像头参数,这里使用--config参数,可以指定设置文件,直接读取文件中的设置参数来对摄像头预览效果进行设置。例如:
libcamera-hello -c config.txt
- 其中的设置文件中,一行一个设置参数,用key=value的格式,例如:
timeout=99000 verbose=
- 注:即使是隐式选项也需要使用 =,而且命令行中使用的 -- 也被省略了。只允许使用长格式选项(不接受 t=99000)。
- 设置了程序运行时间
--timeout -t
- 如果运行的是视频录制指令,timeout选项设置的是录制时长,如果运行的是图像拍摄指令,timeout设置的拍摄并输出图像之前的预览时间。
- 如果在运行libcamera程序的时候没有设置timeout,默认的timeout数值就是5000(5秒), 如果将timeout设置为0,那程序就会一直运行。例如:
libcamera-hello -t 0
预览窗口
- 预览窗口设置
--preview -p
- -p 设置预览预览窗口大小以及窗口的位置(则合格设置在 X和DRM版本的窗口中都有效),设置格式为 --preview <x. y, w, h> 其中x y设置预览窗口在显示屏上的坐标位置, w和h设置的是预览窗口的宽度和长度
- 预览串口的设置不会影响摄像头图像预览的分辨率和宽高比。 程序会将预览图像缩放到预览窗口中显示,并会按照原来的图像宽高比做适配。例如:
libcamera-hello -p 100,100,500,500
- 全屏预览模式
--fullscreen -f
- -f选项设置预览窗口全屏显示,全屏显示模式的预览窗口和边框。同-p一样,不会影响分辨率和宽高比,会自动适配。例如:
libcamera-still -f -o test.jpg
- 使用基于 Qt 的预览窗口
--qt-preview
- 使用基于QT框架的预览窗口, 正常情况下不推荐用这个设置,因为这个预览程序不会使用零拷贝缓冲区共享以及GPU加速, 这个会导致占用资源过高。 QT预览窗口支持X转发(默认预览程序不支持).
- Qt预览串口不支持--fullscreen设置选项, 如果用户要使用Qt预览,建议保持小预览窗口,避免资源占用过高影响系统正常运行。例如:
libcamera-hello --qt-preview
- 不预览图像
--nopreview -n
- 这个设置会关掉图像预览功能.示例:
libcamera-still -n -o test.jpg
- 设置预览窗口的标题和信息显示
--info-text
- 提供的字符串被设置为预览窗口(在X Windows下运行时)的标题。此外,字符串中可能包含多个%指令,这些指令由图像元数据中的信息替代。允许的指令:
指令 说明 %frame 帧序列号 %fps 瞬时帧速率 %exp 捕捉图像时的快门速度, 单位是ms %ag 感光芯片控制的图像模拟增益 %dg 通过ISP控制的图像数值增益 %rg 每个像素点红色组件的增益 %bg 每个像素点蓝色组件的增益 %focus 图像的角点度量,数值越大表示图像越清晰 %lp 当前镜头的屈光度 (1/米为单位的距离) %afstate 自动对焦状态 (idle, scanning, focused, failed)
- 如果没有指定窗口信息,默认的--info-text设置为 "#%frame (%fps fps) exp %exp ag %ag dg %dg"。例如:
libcamera-hello --info-text "Focus measure: %focus"
摄像头分辨率和读数
- 设置图像的分辨率
--width --height
- 这两个参数分别设置图像的宽度和高度。对于libcamera-still, libcamera-jpeg和libcamera-vid指令,这两个参数可以设置输出图像/视频的分辨率。
- 如果使用libcamera-raw指令,这两个参数会影响获取的元数据帧的大小。 摄像头有一个2x2的分块读取模式,如果设置的分辨率小于分开模式, 摄像头会按照2x2的分块大小获取元数据帧。
- 如果使用libcamera-hello指令,无法指定分辨率.
- 示例:
libcamera-vid -o test.h264 --width 1920 --height 1080 录制1080p视频 libcamera-still -r -o test.jpg --width 2028 --height 1520 拍摄一张分辨率为2028x1520的JPEG图像。
- 设置预览图像的分辨率
--viewfinder-width --viewfinder-height
- 该设置仅影响预览的图像大小(指libcamera-hello、libcamera-jpeg和libcamera-still的预览阶段)。并不会影响最终输出的图像或者视频的分辨率。 预览图像大小的设备不会影响预览窗口尺寸,会根据窗口适配。例如:
libcamera-hello --viewfinder-width 640 --viewfinder-height 480
- 强制分辨率
--rawfull
- 无论要求的输出分辨率(由 --width 和 --height 给定)如何,该选项都会强制传感器以全分辨率读出模式进行静态和视频捕捉。:此设置libcamera-hello无效。
- 使用该选项通常会导致帧速率下降,全分辨率模式下,帧读取速度会比较慢。例如:
libcamera-raw -t 2000 --segment 1 --rawfull -o test%03d.raw
- 指令会捕捉多个全分辨率原始图像。如果你使用的是HQ摄像头。每个帧的大小为18MB,而如果没有设置--rawfull,HQ摄像头默认的是2x2模式, 每帧的数据大小只有4.5MB.
- 指定传感器模式
--mode
- 这个参数比rawfull更通用,用于设置摄像头模式,使用的时候,需要指定宽度,高度,位深度和打包模式,并用冒号分割。设置的数值不一定要完全精确,系统会自动匹配最接近的数值,另外位深度和打包模式是可设置的(默认为12和P,表示打包).例如:
- 4056:3040:12:P - 4056x3040分辨率,12bit每像素, 打包。打包意味着原始图像数据会在缓冲区被打包,这种情况下,两个像素点仅会占用3个字节,可以节省内存
- 1632:1224:10 - 1632x1224分辨率,10bit每像素, 默认打包。10-bit 打包的模式下,4个像素点数据会占用5 bytes.
- 2592:1944:10:U -2592x1944分辨率,10bits每像素,不打包。不打包的情况下,每个限速会占用2bytes内存,这种情况下,最高的6 bits会被设置为0
- 3262:2448 -3264x2448分辨率, 默认使用12bits和打包模式。 但是,如果摄像头型号,比如Camera V2 (IMX219)不支持12bits模式,系统会自动选择为10bits模式
- --mode参数是用来在录制视频和拍摄静态图像的时候设置摄像头模式,如果想要在预览的时候设置,可以用--viewfinder-mode
- 这个参数比rawfull更通用,用于设置摄像头模式,使用的时候,需要指定宽度,高度,位深度和打包模式,并用冒号分割。设置的数值不一定要完全精确,系统会自动匹配最接近的数值,另外位深度和打包模式是可设置的(默认为12和P,表示打包).例如:
--viewfinder-mode // 指定传感器模式,以 <width>:<height>:<bit-depth>:<packing> 表示
- 该选项与 --mode 选项完全相同,不同之处在于它只适用于剧照捕捉的预览阶段(libcamera-hello 应用程序也使用该选项)。
- 低分辨率图像设置
--lores-width --lores-height
- libcamera 允许从摄像机系统向应用程序传输第二个较低分辨率的图像流。在预览和视频模式下(即 libcamera-hello、libcamera-still和libcamera-vid)该图像流均可用,除其他外,还可用于图像分析。对于静态捕捉,低分辨率图像流不可用。
- 低分辨率图像流的视场角与其他图像流相同。如果为低分辨率流指定了不同的宽高比,那么这些图像将被压缩,像素不再是正方形。
- 在视频录制(libcamera-vid)过程中,如果设置了低分辨率,会禁用掉颜色去噪处理等功能。例如:
libcamera-hello --lores-width 224 --lores-height 224
- 注意,低分辨率设置通常要结合图像后处理使用,否则效用不大。
- 翻转图像
--hflip #水平翻转图像 --vflip #垂直翻转图像 --rotation #根据给出的角度,水平或者垂直翻转图像
- --rotation的参数目前只支持0 和180, 其实就是相当于--hflip和--vflip.。例如:
libcamera-hello --vflip --hflip
- 裁剪图像
--roi #裁剪图像<x, y, w, h>
- --roi允许用户从传感器提供的完整图像中根据坐标裁剪自己想要的图像区域,也就是数字缩放,注意坐标值要是在有效范围的。 比如 --roi 0, 0, 1, 1就是无效的指令。
- 示例:示例指令会从图像中心裁剪1/4图像出来。
libcamera-hello --roi 0.25,0.25,0.5,0.5
- HDR 模式运行
--hdr
- --hdr选项会使摄像头以HDR(高动态范围)模式运行。该选项仅适用于某些受支持的摄像头,包括Raspberry Pi Camera Module 3系列.例如:
libcamera-still --hdr -o hdr.jpg 捕捉静态图像, libcamera-vid --hdr -o hdr.h264 捕捉视频。
- 使用 HDR 选项通常会导致不同的相机模式,这可以通过比较 libcamera-hello --list-cameras 和 libcamera-hello --hdr --list-cameras 的输出来检查。
- 用户也可以提供 --hdr 0 或 --hdr 1,前者禁用 HDR 模式(相当于完全省略该选项),后者则与单独使用 --hdr 相同。
- 注:对于 Raspberry Pi 摄像头模块 3,非 HDR 模式包括通常的全分辨率(1200 万像素)模式及其等效的半分辨率 2x2 分档(300 万像素)模式。在 HDR 模式下,只有一个半分辨率(300 万像素)模式可用,而且在不重启相机应用程序的情况下,无法在 HDR 和非 HDR 模式之间切换
摄像头控制
以下选项会影响图像处理和控制算法,从而影响摄像机的图像质量。
- 设置图像的锐度
--sharpness <number>
- 通过<number>数值调整图像的锐度。 如果设置为0,就是不应用锐化。 如果设置的值超过1.0,会使用额外的锐化。例如:
libcamera-still -o test.jpg --sharpness 2.0
- 设置图像对比度
--contrast <number>
- 通过<number> 调整图像对比度。数值为 0 时,对比度最小;数值为 1.0 时,使用默认的对比度;数值大于 1.0 时,使用额外的对比度。例如:
libcamera-still -o test.jpg --contrast 1.5
- 设置图像亮度
--brightness <number>
- 通过<number>调整图像亮度,设置范围是-1.0 ~ 1.0。数值-1.0会产生(几乎)黑色图像,数值1.0会产生几乎全白的图像,数值0.0会产生标准图像亮度。例如:
libcamera-still -o test.jpg --brightness 0.2
- 注意,亮度参数会增加(或减少)输出图像中所有像素的偏移量。通常使用--ev选项更为合适。
- 设置图像色彩饱和度
--saturation <number>
- 通过<number>调整色彩饱和度。数值为0时会生成灰度图像,数值为1.0时会使用默认的色彩饱和度,数值大于1.0时会应用额外的色彩饱和度。例如:
libcamera-still -o test.jpg --saturation 0.8
- 设置EV补偿
--ev <number>
- 通过<number>设置图像的EV补偿,以光圈为单位,单位为光圈,范围为 -10至10。默认值为0。它的工作原理是提高或降低 AEC/AGC算法试图匹配的目标值。例如:
libcamera-still -o test.jpg --ev 0.3
- 设置曝光时间
--shutter <number>
- 注:如果相机的帧率太快,可能会导致无法按照设定的快门时间工作,如果遇到这种情况,可以尝试用--framerate来降低帧速率。
libcamera-hello --shutter 30000
- 设置增益值
--gain <number> #设置增益值(数值增益和模拟增益组合) --analoggain #模拟增益 --gain的代名词
- --analoggain和--gain实际上是完全相同的,设置了将使用的模拟和数字增益,使用analoggain只是为了兼容raspicam的程序。如果传感器驱动程序可以提供所需的增益,那么将只使用模拟增益。一旦模拟增益达到最大允许值,超出部分将作为数字增益提供。
- 注意:在某些情况下,即使没有超过模拟增益限制,数字增益也可能超过1。这种情况可能发生在:
- 任一色彩增益低于1.0,都会导致数字增益稳定在1.0/min(red_gain,blue_gain)。这意味着应用于任何色彩通道的总数字增益都不会低于1.0,因为这会导致色彩失真。
- 当 AEC/AGC 发生变化时,数字增益可能会略有不同,但这种影响应该只是短暂的。
- 设置测光模式
--metering <string>
- 设置AEC/AGC算法的测光模式, 可用的参数有:
centre - 中心测光 (默认) spot -点测光 averag -平均或者全幅测光 custom -自定义测光模式, 可以通过调谐文件设置
- 有关定义自定义测光模式以及如何在现有测光模式中调整区域权重的详细信息,请参阅Raspberry Pi 相机和 libcamera 的调整指南
- 示例:
libcamera-still -o test.jpg --metering spot
- 设置曝光配置文件
--exposure <string>
- 曝光模式可以设置为normal或者sport. 这两种模式的报告配置文件不会影响图像的整体曝光,但是如果是sport模式的话,程序会缩短曝光时间和提高正义来达到同样的曝光效果。
- 曝光配置文件可在相机调校文件中编辑。有关详情,请参阅Raspberry Pi 相机和 libcamera 的调校指南
- 示例:
libcamera-still -o test.jpg --exposure sport
- 设置白平衡模式
--awb <string>
- 可用的白平衡模式:
模式 色温 auto 2500K ~ 8000K incadescent 2500K ~ 3000K tungsten 3000K ~3500K fluorescent 4000K ~ 4700K indoor 3000K ~ 5000K daylight 5500K ~ 6500 K cloudy 7000K ~ 8500K custom 自定义范围, 通过调谐文件设置
- 注意:这些值只是近似值,可能会根据摄像机的调整而有所不同。
- 有关 AWB 模式以及如何定义自定义模式的更多信息,请参阅Raspberry Pi 摄像头和 libcamera 的调整指南
- 示例:
libamera-still -o test.jpg --awb tungsten
- 设置固定的颜色增益
--awbgains <number,number>
- 通过<number>来设置红色和蓝色增益值,并直接使用它们来代替 AWB 算法。在此设置非零值会禁用 AWB 计算。
- 示例:
libcamera-still -o test.jpg --awbgains 1.5, 2.0
- 设置去噪模式
--denoise <string>
- 支持的去噪模式:
auto -默认模式, 使用标准空间去噪, 如果是视频,会使用快速色彩降噪,拍摄静态图片的时候会使用高质量的色彩降噪。预览图像不会使用任何色彩去噪 off - 关闭空间去噪和色彩去噪 cdn_off -关闭色彩去噪 cdn_fast - 使用快速色彩去噪 cdn_hq - 使用高质量色彩去噪,不适用于视频录制。
- 注意,即使使用快速彩色去噪也会导致帧频降低。高质量的色彩去噪通常会导致更低的帧频。
- 示例:
libcamera-vid -o test.h264 --denoise cdn_off
- 指定摄像头调谐文件
--tuning-file <string>
- 这标识了应使用的 JSON 格式调整文件的名称。调整文件涵盖图像处理的许多方面,包括 AEC/AGC、AWB、色彩阴影校正、色彩处理、去噪等。
- 关于更多调谐文件的说明, 可以参考官方教程
- 示例:
libcamera-hello --tuning-file ~/my~camera-tuning.json
- 设置自动对焦模式
--autofocus-mode <string>
- 设置自动对焦模式,可以选择以下模式:
default -默认情况下,摄像头会凯子连续自动对焦模式,除非设置了--lens-position 或者 --autofocus-on-capture 手动对焦的方式 manual -手动对焦模式,可以通过--lens-position来设置对焦位置 auto -只有在开启摄像头的时候会做一次对焦,其他情况下不调整对焦。(如果使用的是libcamera-still指令,只有使用--autofocus-on-capture情况下,会在拍照前做一次对焦) continuous -摄像头会根据场景变化,自动调整对焦位置
- 此选项仅支持某些相机模块(如:Raspberry Pi Camera Module 3系列)
- 设置自动对焦范围
--autofocus-range <string>
- 设置自动对焦范围,可以选择以下:
normal --默认项, 从最近到无穷远 macro -微距模式,只对近处的物体对焦。 full -全距离模式,对最近物体调整到无穷远
- 此选项仅支持某些相机模块(如:Raspberry Pi Camera Module 3系列)
- 设置对焦速度
--autofocus-speed <string>
- 设置对焦速度,可以选择以下:
normal -默认项,正常速度 fast -快速对焦模式
- 此选项仅支持某些相机模块(如:Raspberry Pi Camera Module 3系列)
- 显示自动对焦窗口
--autofocus-window
- 显示自动对焦窗口,格式为 x,y,width,height,其中坐标以整个图像的比例给出。例如,--autofocus-window 0.25,0.25,0.5,0.5 将选择一个窗口,该窗口在每个维度上都是输出图像大小的一半,并以中间为中心。
- 默认值会导致算法在两个维度上都使用输出图像的中间三分之一(即图像总面积的 1/9)。
- 此选项仅支持某些相机模块(如:Raspberry Pi Camera Module 3系列)
- 设置对焦位置
--lens-position <string>
- 将镜头移动到固定焦距,一般用屈光度(单位为1 /米距离)给出。例如:
0.0 --设置对焦位置为无穷远 Any other number --设置对焦位置为 1/number number是你设置的任意数值, 比如,如果设置2, 表示会对焦到0.5m的位置 default -- 对焦到镜头超焦距相对于的默认位置
- 注意,镜头只能进行近似校准,不同相机模块之间很可能存在差异。
- 此选项仅支持某些相机模块(如:Raspberry Pi Camera Module 3系列)
输出文件选项
- 输出文件名
--output -o
- 设置输出图像或者视频的文件名。 除了设置文件名之外,还可以指定输出的udp或者tcp服务器地址,从而将图像输出到服务器上。 有兴趣的可以查看后续tcp和udp的相关设置说明。
- 示例:
libcamera-vid -t 100000 --segment 10000 -o chunk%04d.h264
- 记录一个 100 秒的文件,每段 10 秒,每个文件命名为 chunk.h264,但包含一个递增计数器。请注意,%04d 会将计数写入字符串,但会通过添加前导零填充到至少 4 个字符的总宽度。
libcamera-vid -t 0 --inline -o udp://192.168.1.13:5000
- 将H.264视频流传输到端口 5000 上的网络地址 192.168.1.13
- 输出文件计数器
--wrap <number>
- 当输出到带有递增计数器(如输出文件名中的 %d)的文件时,当计数器达到该值时,将其归零。
- 示例:
libcamera-vid -t 0 --codec mjpeg --segment 1 --wrap 100 -o image%d.jpg
- 马上刷新输出文件
--flush
- --flush会将每一帧图像写入的同时都马上更新到硬盘中,降低延迟。而不是等待系统刷新。
- 示例:
libcamera-vid -t 10000 --flush -o test.h264
后期处理
- 后处理文件(post-process-file)选项指定了一个 JSON 文件,用于配置成像管道在相机图像到达应用程序之前对其进行的后处理。可以将其视为传统 raspicam "图像效果 "的替代。
- 后处理是一个大课题,需要使用 OpenCV 和 TensorFlowLite 等第三方软件来分析和处理图像。更多信息,请参阅后处理部分。
- 示例:
libcamera-hello --post-process-file negate.json
静态图片拍摄设置参数
--qiality, -q #设置JPEG图像质量 <0 ~ 100> --exif, -x #添加而外的EXIF标志 --timelapse #延时拍照的时间间隔, 单位是ms --framestart #帧计数的开始数值 --datetime #用日期格式命名输出文件 --timestamp #用系统时间戳命名输出文件 -- restart #设置JPEG重启时间间隔 --keypress, -k # 设置回车按键拍照模式 --signal, -s #设置信号触发拍照 --thumb #设置缩略图参数 <w:h:q> --ebcoding, -e #设置图像编码类型。 jpg / png / bmp / rgb / yuv420 --raw, -r #保存原始图像 --latest #关联符号到最新保存的文件 --autofocus-on-capture #设置在拍照前做一次对焦动作
静态图片拍摄设置参数
--quality, -q # 设置JPEG指令 <0 - 100> --bitrate, -b # 设置H.264比特率 --intra, -g #设置内部帧周期 (只支持H.264) --profile #设置H.264配置 --level #设置H.264等级 --codec #设置编码类型 h264 / mjpeg / yuv420 --keypress, -k #设置回车暂停和录制 --signal, -s #设置信号暂停和录制 --initial #在录制或者暂停状态下启动程序 --split #切割视频并保存到另外的文件 --segment #将视频分割成多个视频段 --circular #将视频写入循环缓冲区中 --inline #在每个I帧中写入数据头(只支持H.264) --listen #等待TCP连接 --frames #设置录制的帧数
Buster系统
拍照
终端执行以下语句即可拍照:
raspistill -o image.jpg
此处 image.jpg 是照片文件名。
摄像
终端执行以下语句即可摄像:
raspivid -o video.h264 -t 10000
其中 -t 10000 表示录制 10 秒,用户各根据自己的需要进行调整。
参考资料
Python 代码控制摄像头
- 可借助picamera库,使python支持摄像头的控制
- 树莓派镜像在Bullseye版本之后,底层的树莓派驱动由Raspicam切换成libcamera。libcamera是一个开源的软件栈(后面会称呼做驱动,方便理解),方便于第三方移植和开发自己的摄像头驱动。当前的libcamera不支持python, 因此树莓派官方还是提供了Raspicam的安装下载的方法。对于切换成libcamera困难,但是又需要用最新系统的用户,请直接移步到Raspicam的使用说明。
预览
- 打开python IDE,如Thonny Python IDE,或打开记事本
- 新建名字为camera.py的python文件,并保存到桌面
- 输入以下代码
from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.start_preview()
sleep(5)
camera.stop_preview()
- 进入终端,执行
python3 Desktop/camera.py
桌面将弹出预览框,实时取景并预览
需要注意的是,预览框仅在直接连接屏幕时有效,而是使用VNC等软件远程连接树莓派桌面,则不会弹出该预览框
如果预览画面是上下颠倒的,则可以通过以下代码旋转180度
camera = PiCamera()
camera.rotation = 180
- 预览画面可旋转90度、180度、270度
- 如果要重置画面,可将画面旋转0度
设置预览框的透明度
camera.start_preview(alpha=100)
alpha的值范围是0-255
拍照
- 在预览代码的中间插入camera.capture()命令
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/image.jpg')
camera.stop_preview()
请注意:必须要执行代码sleep(5),以便给摄像头的传感器留下一定时间调整亮度和白平衡
录像
移除 camera.captue(),并加入camera.start_recording()和camera.stop_recording()
camera.start_preview()
camera.start_recording('/home/pi/Desktop/video.h264')
sleep(5)
camera.stop_recording()
camera.stop_preview()
以上代码执行后,将在桌面生成video.h264的视频,长度为5秒
更多参数
- picamera可以给图片添加很多参数
设置分辨率
- 默认情况下,图片的分辨率等于显示器的分辨率,但最大的图像尺寸不超过2592*1944像素,视频尺寸不超过1920*1080像素;图像和视频的最小尺寸则为64*64像素
- 可使用以下代码设置图像的分辨率
camera.resolution = (2592, 1944)
camera.framerate = 15
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/max.jpg')
camera.stop_preview()
- 请注意,相机的帧数需设置为≤15帧,以支持最大分辨率
给图片加文字
添加文字
camera.start_preview()
camera.annotate_text = "Hello world!"
sleep(5)
camera.capture('/home/pi/Desktop/text.jpg')
camera.stop_preview()
文字大小
camera.annotate_text_size = 50
annotate_text_size的取值范围为6-160,默认值32
文字颜色
camera.start_preview()
camera.annotate_background = Color('blue')
camera.annotate_foreground = Color('yellow')
camera.annotate_text = " Hello world "
sleep(5)
camera.stop_preview()
修改图片的参数
- 亮度
camera.start_preview()
camera.brightness = 70
sleep(5)
camera.capture('/home/pi/Desktop/bright.jpg')
camera.stop_preview()
brightness的取值范围为0-100,默认值50
- 对比度
camera.contrast = 50
contrast的取值范围为0-100,默认值50
- 风格
可通过camera.image_effect,给图片添加特效
有效值:
- none(默认)
- negative
- solarize
- sketch
- denoise
- emboss
- oilpaint
- hatch
- gpen
- pastel
- watercolor
- film
- blur
- saturation
- colorswap
- washedout
- posterise
- colorpoint
- colorbalance
- cartoon
- deinterlace1
- deinterlace2
例如
camera.start_preview()
camera.image_effect = 'colorswap'
sleep(5)
camera.capture('/home/pi/Desktop/colorswap.jpg')
camera.stop_preview()
- 模式
可使用camera.exposure_mode,设置拍照模式(如夜晚、运动、雪地等模式)
有效值:
- off
- auto(默认)
- night
- nightpreview
- backlight
- spotlight
- sports
- snow
- beach
- verylong
- fixedfps
- antishake
- fireworks
例如
camera.start_preview()
camera.exposure_mode = 'beach'
sleep(5)
camera.capture('/home/pi/Desktop/beach.jpg')
camera.stop_preview()
- 白平衡
可使用camera.awb_mode设置白平衡
有效值:
- off
- auto(默认)
- sunlight
- cloudy
- shade
- tungsten
- fluorescent
- incandescent
- flash
- horizon
例如设置白平衡为“白天”
camera.start_preview()
camera.awb_mode = 'sunlight'
sleep(5)
camera.capture('/home/pi/Desktop/sunlight.jpg')
camera.stop_preview()