Hello,
Trying to achieve a good 30 fps on Pi 3 Model B using the old 5MP camera module 1.3. Recently downloaded OS Bullseye, and using PiCamera2 on Python.
The goal is to achieve:
Using the information given in the previously mentioned docs and links (probably others too that we might not recall right away) we created a code that was able to reach ~14 FPS @1296x972 in still images capture by writing to BytesIO variable in a while loop then saving in a later loop when all frames are captured. However, achieving the intended FPS is still a challenge, as well as syncing the LED flash still seem to have some hit & miss occasions.
To achieve this FPS we had to test a few configurations, resolutions and formats! We noticed, what seems to be strange to us, not to say we are any images format & encoders experts, that capturing using then saving using somehow pushed the FPS to be more efficient!
Below are the three tests we made so far:
Results:
Trying to achieve a good 30 fps on Pi 3 Model B using the old 5MP camera module 1.3. Recently downloaded OS Bullseye, and using PiCamera2 on Python.
The goal is to achieve:
- Good FPS ~30FPS for a 100~200 frames consequent captures
- Synchronise a LED flash at start of each frame
- Do not write each frame to the disk after each capture, as writing is a slow I/O process. Instead write to memory, then write to disk when done. Inspiration came from here Take images in a short time using the Raspberry Pi camera module
- Use threading if possible, although we haven't tried that yet! Inspiration from here https://pyimagesearch.com/2015/12/28/increasing-raspberry-pi-fps-with-python-and-opencv/ although written for PiCamera & openCV libraries and not PiCamera2
- It's a good idea to capture a video rather than still images, as it is much faster and can utilise the full capacity of the camera hardware of different video modes with different FPS options based on resolution
Using the information given in the previously mentioned docs and links (probably others too that we might not recall right away) we created a code that was able to reach ~14 FPS @1296x972 in still images capture by writing to BytesIO variable in a while loop then saving in a later loop when all frames are captured. However, achieving the intended FPS is still a challenge, as well as syncing the LED flash still seem to have some hit & miss occasions.
To achieve this FPS we had to test a few configurations, resolutions and formats! We noticed, what seems to be strange to us, not to say we are any images format & encoders experts, that capturing using
Code:
camera.capture_file(data, format='bmp')
Code:
byte_image.save("file_"+str(k).zfill(2)+".jpg", "JPEG")
Below are the three tests we made so far:
- [1]Capture JPEG, save JPG --> slow fps (~8 fps)
- [2]Capture BMP, save BMP --> much better fps (~14 fps), but very slow write, also larger file size (~3.6MB)
- [3]Capture BMP, save JPG --> faster fps (~14 fps), good file size (~90KB)
Results:
- [1]Capture JPEG, save JPG --> slow fps (~8 fps)
Code:
# CAPTURE JPEG, WRITE JPG# camera.capture_file(data, format='jpeg')# byte_image.save("file_jpg"+str(k).zfill(2)+".jpg", "JPEG")# FPS: 8.296# frame capture time: ~110ms# write speed: ok[0:49:10.294702270] [1722] INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f[0:49:10.342869523] [1723] INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media2 and ISP device /dev/media0[0:49:10.342984934] [1723] INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'[0:49:10.356715810] [1722] INFO Camera camera.cpp:1033 configuring streams: (0) 1296x972-XBGR8888 (1) 1296x972-SGBRG10_CSI2P[0:49:10.357403950] [1723] INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 1296x972-SGBRG10_1X10 - Selected unicam format: 1296x972-pGAACapturing..0 time: 0.162737846374511721 time: 0.11387729644775392 time: 0.120075225830078123 time: 0.115268468856811524 time: 0.114280462265014655 time: 0.116030454635620126 time: 0.11398243904113777 time: 0.114322423934936528 time: 0.115900039672851569 time: 0.114772319793701178.295 fps, 10 imagesSaving..(total 10 images)Finished
- [2]Capture BMP, save BMP much better fps (~14 fps), but very slow write, also larger file size (~3.6MB)
Code:
# CAPTURE BMP, WRITE BMP# camera.capture_file(data, format='bmp')# byte_image.save("file_bmp"+str(k).zfill(2)+".bmp", "BMP")# FPS: 14.327# frame capture time: ~62ms# write speed: SLOW[0:39:10.717184668] [1609] INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f[0:39:10.765629983] [1610] INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media2 and ISP device /dev/media0[0:39:10.765746440] [1610] INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'[0:39:10.779440096] [1609] INFO Camera camera.cpp:1033 configuring streams: (0) 1296x972-XBGR8888 (1) 1296x972-SGBRG10_CSI2P[0:39:10.780266597] [1610] INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 1296x972-SGBRG10_1X10 - Selected unicam format: 1296x972-pGAACapturing..0 time: 0.125857591629028321 time: 0.065351247787475592 time: 0.06050086021423343 time: 0.064319610595703124 time: 0.064846515655517585 time: 0.061897277832031256 time: 0.063296079635620127 time: 0.062747240066528328 time: 0.062753677368164069 time: 0.062362194061279314.327 fps, 10 imagesSaving..(total 10 images)Finished
- [3]Capture BMP, save JPG faster fps (~14 fps), good file size (~90KB)
Code:
# CAPTURE BMP, WRITE JPG# camera.capture_file(data, format='bmp')# byte_image.save("file_jpg"+str(k).zfill(2)+".jpg", "JPEG")# FPS: 14.327# frame capture time: ~62ms# write speed: ok[0:45:49.031581865] [1645] INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f[0:45:49.079437062] [1647] INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media2 and ISP device /dev/media0[0:45:49.079620810] [1647] INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'[0:45:49.093474390] [1645] INFO Camera camera.cpp:1033 configuring streams: (0) 1296x972-XBGR8888 (1) 1296x972-SGBRG10_CSI2P[0:45:49.094166986] [1647] INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 1296x972-SGBRG10_1X10 - Selected unicam format: 1296x972-pGAACapturing..0 time: 0.122169256210327151 time: 0.065165042877197272 time: 0.0624992847442626953 time: 0.065682172775268554 time: 0.068348884582519535 time: 0.061042308807373056 time: 0.064426898956298837 time: 0.06463575363159188 time: 0.061801195144653329 time: 0.0639736652374267614.224 fps, 10 imagesSaving..(total 10 images)Finished
Statistics: Posted by kld555 — Mon Dec 25, 2023 11:29 pm