tool for playing with Raspberry Pi Global Shutter Camera crop values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $# -lt 4 ]]; then echo Format: "$0" width height framerate ms [us]; exit; fi | |
if [[ $# -gt 4 ]]; then SHTR="--shutter"; else SHTR=""; fi | |
for((m=1; m<=5; ++m)) | |
do | |
if media-ctl -d "/dev/media$m" --set-v4l2 "'imx296 10-001a':0 [fmt:SBGGR10_1X10/${1}x$2 crop:($(( (1440 - $1) / 2 )),$(( (1088 - $2) / 2 )))/${1}x$2]" >/dev/null; then echo -e "/dev/media$m\n"; break; fi | |
done | |
libcamera-hello --list-cameras ;echo | |
rm -f /dev/shm/tst.pts | |
libcamera-vid --width "$1" --height "$2" --denoise cdn_off --framerate "$3" --save-pts /dev/shm/tst.pts -t "$4" "$SHTR" "$5" -o /dev/shm/tst.h264 -n ;echo | |
rm -f tstamps.csv && ptsanalyze /dev/shm/tst.pts |
Updated GScrop allows to pass optional shutter time (in microseconds) after video length (in milliseconds), to be used for libcamera-vid video capturing. Also now crop is centered in sensor area (see "...(656, 496)/128x96 crop]" further below):
pi@raspberrypi4B2:~ $ ./GScrop
Format: ./GScrop width height framerate ms [us]
pi@raspberrypi4B2:~ $
pi@raspberrypi4B2:~ $ shellcheck GScrop
pi@raspberrypi4B2:~ $
Sample execution with 29us shutter time, for capturing fast rotating (22,500rpm) RC airplane propeller.
https://forums.raspberrypi.com/viewtopic.php?p=2091003#p2091003
22500/60/536 = 0.70 rotations between successive frames (propeller rotates clockwise, follow one side central reflective marker).
1fps animated .gif shows 20 successive frames from recorded video:
pi@raspberrypi4B2:~ $ ./GScrop 128 96 534 2000 29
/dev/media3
Available cameras
-----------------
0 : imx296 [1456x1088] (/base/soc/i2c0mux/i2c@1/imx296@1a)
Modes: 'SRGGB10_CSI2P' : 1456x1088 [535.91 fps - (656, 496)/128x96 crop]
[28:22:05.521087746] [277565] INFO Camera camera_manager.cpp:299 libcamera v0.0.4+22-923f5d70
[28:22:05.562791538] [277566] INFO RPI raspberrypi.cpp:1476 Registered camera /base/soc/i2c0mux/i2c@1/imx296@1a to Unicam device /dev/media3 and ISP device /dev/media0
Mode selection:
SRGGB10_CSI2P 1456x1088 - Score: 3581.84
[28:22:05.565814553] [277565] INFO Camera camera.cpp:1028 configuring streams: (0) 128x96-YUV420 (1) 1456x1088-SBGGR10_CSI2P
[28:22:05.566060087] [277566] INFO RPI raspberrypi.cpp:851 Sensor: /base/soc/i2c0mux/i2c@1/imx296@1a - Selected sensor format: 128x96-SBGGR10_1X10 - Selected unicam format: 128x96-pBAA
Halting: reached timeout of 2000 milliseconds.
creating tstamps.csv
1054 frames were captured
majority framerate 535fps
frame delta time[us] distribution
1 1861
2 1862
5 1864
17 1865
358 1866
618 1867
40 1868
4 1869
3 1870
1 1871
1 1872
1 1873
> after skip frame indices (middle column)
0 frame skips (0%)
average framerate 536fps
pi@raspberrypi4B2:~ $
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related forum posting:
https://forums.raspberrypi.com/viewtopic.php?p=2090640#p2090640
Script is "shellcheck" clean.
Needs ptsanalyze tool installed somewhere on $PATH:
https://github.com/Hermann-SW/userland/blob/master/tools/ptsanalyze
Usage:
Example capturing with 532fps requested, 128x96 crop, for 3000ms — with proof of success and no frame skips:
Slowed down 10× of captured 536fps video (analog clock second hand):
