mkhargrove
Posts: 8
Joined: Mon Dec 23, 2019 7:46 pm

8mp camera, class 10 sd, need two shots full res, fast

Mon Dec 23, 2019 7:58 pm

I have researched and unable to find exactly what I need help with. I am trying to capture two max resolution images using python. I need my ultimate output to be jpg.

I have my code set to capture to file1.jpg and then capture to file2.jpg. My quickest elapsed time in the image is about 1 second. I initially changed from 15 fps to 30 fps, and got about a .04 second reduction in elapsed time.

I assume the limitation comes primarily from converting the large image to jpg and writing to the sd card. I desperately need an elapsed time between shots of about .5 seconds.

I've seen a few discussions about writing to RAM drive until both shots are complete, then copy to the SD card, and using the video port, but I am not certain that I've seen one that in the end has the pieces I need to go through the process all the way back to JPG images.

Can anyone help me?
(btw, this is for 100 pi's, networked in a 3d photo booth)

User avatar
HermannSW
Posts: 1874
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: 8mp camera, class 10 sd, need two shots full res, fast

Mon Dec 23, 2019 9:11 pm

You can take full resolution video at 2fps or even 15 fps (66.6ms between frames):
https://www.raspberrypi.org/documentati ... /camera.md

The stored .h264 video can be converted to .jpg frames with ffmpeg in post processing:

Code: Select all

ffmpeg -i tst.h264 frame.%04d.jpg

In case you are interested in timestamps, add "--pts tst.pts" to raspivid command.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

mkhargrove
Posts: 8
Joined: Mon Dec 23, 2019 7:46 pm

Re: 8mp camera, class 10 sd, need two shots full res, fast

Tue Dec 24, 2019 5:32 pm

I'm not certain that I understand.....If I use video, I can capture at the same resolution as an 8mp still, then convert the frames?

Can I adjust the code above and fps to get only 2 capture only two frames?

mkhargrove
Posts: 8
Joined: Mon Dec 23, 2019 7:46 pm

Re: 8mp camera, class 10 sd, need two shots full res, fast

Wed Dec 25, 2019 5:05 am

Sorry for continuing to extend this thread, but I'm a beginner....


Question: would using the 'capture_sequence' command give me an improvement (decreased time between two shots) vs using the 'capture' command twice? It appear to me that the capture command re-initializes camera settings?

ethanol100
Posts: 589
Joined: Wed Oct 02, 2013 12:28 pm

Re: 8mp camera, class 10 sd, need two shots full res, fast

Wed Dec 25, 2019 11:09 am

Capturing h264 video at full resolution is not possible. This is limited to FullHD resolution. The MJPEG encoder can handle full resolution.

Have a look at the picamera documentation. There is an advanced recipe for fast capturing:
https://picamera.readthedocs.io/en/rele ... processing

You can use something similar like:

Code: Select all

import time
import picamera

with picamera.PiCamera() as camera:
    camera.resolution = (3280, 2464)
    camera.framerate = 2
    camera.start_preview()
    time.sleep(2)
    camera.capture_sequence([
        'image1.jpg',
        'image2.jpg',
        ], use_video_port=True)
The images are too big for the normal GPU memory setting. Try to increase the setting gpu_mem=128 to gpu_mem=196 in the file "/boot/config.txt". Reboot and try to execute the python script.

You can have a look at the output of

Code: Select all

ls -la --time-style=full-iso image*.jpg
where you get a precise timestamp of the frames.
The two images should be half a second apart.

User avatar
HermannSW
Posts: 1874
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: 8mp camera, class 10 sd, need two shots full res, fast

Thu Dec 26, 2019 12:44 pm

That is a cool trick for capturing full size images (5MP/8MP) for v1/v2 camera.

I increased framerate requested to 15fps and took 30 images:

Code: Select all

import time
import picamera

with picamera.PiCamera() as camera:
    camera.resolution = (3280, 2464)
    camera.framerate = 15
#    camera.start_preview()
    time.sleep(2)
    camera.capture_sequence([
        'image.01.jpg',
        'image.02.jpg',
        'image.03.jpg',
        'image.04.jpg',
        'image.05.jpg',
        'image.06.jpg',
        'image.07.jpg',
        'image.08.jpg',
        'image.09.jpg',
        'image.10.jpg',
        'image.11.jpg',
        'image.12.jpg',
        'image.13.jpg',
        'image.14.jpg',
        'image.15.jpg',
        'image.16.jpg',
        'image.17.jpg',
        'image.18.jpg',
        'image.19.jpg',
        'image.20.jpg',
        'image.21.jpg',
        'image.22.jpg',
        'image.23.jpg',
        'image.24.jpg',
        'image.25.jpg',
        'image.26.jpg',
        'image.27.jpg',
        'image.28.jpg',
        'image.29.jpg',
        'image.30.jpg',
        ], use_video_port=True)
In order to raise framerate achieved, I commented out preview, and stored in "/dev/shm":

Code: Select all

[email protected]:/dev/shm $ ls
[email protected]:/dev/shm $ time python ~/2fp.py 

real	0m7.988s
user	0m0.728s
sys	0m0.987s
[email protected]:/dev/shm $ df /dev/shm
Filesystem     1K-blocks   Used Available Use% Mounted on
tmpfs             415276 136188    279088  33% /dev/shm
[email protected]:/dev/shm $
Achieved framerate is not 15fps, but slightly more than 6fps.
And you can capture more than 14s in total into /dev/shm:

Code: Select all

[email protected]:/dev/shm $ ls -la --time-style=full-iso image*jpg | head -2
-rw-r--r-- 1 pi pi 4650036 2019-12-23 06:50:26.669999318 +0100 image.01.jpg
-rw-r--r-- 1 pi pi 4648909 2019-12-23 06:50:26.829999318 +0100 image.02.jpg
[email protected]:/dev/shm $ ls -la --time-style=full-iso image*jpg | tail -2
-rw-r--r-- 1 pi pi 4645119 2019-12-23 06:50:31.209999317 +0100 image.29.jpg
-rw-r--r-- 1 pi pi 4645834 2019-12-23 06:50:31.379999317 +0100 image.30.jpg
[email protected]:/dev/shm $ echo "29/(31.379999317-26.669999318)" | bc -ql
6.15711252784652070654
[email protected]:/dev/shm $ 

P.S:
8MP video can be created from the frames easily.
Video size is only half(!) of a single frame size:
https://stamm-wilbrandt.de/en/forum/2fp.6fps.avi

Code: Select all

$ ffmpeg -r 6 -i image.%02d.jpg 2fp.6fps.avi
...
$ ls -l 2fp.6fps.avi 
-rw-rw-r--. 1 stammw stammw 2265020 Dec 26 15:27 2fp.6fps.avi
$ 
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

mkhargrove
Posts: 8
Joined: Mon Dec 23, 2019 7:46 pm

Re: 8mp camera, class 10 sd, need two shots full res, fast

Fri Dec 27, 2019 7:51 pm

I appreciate the help!
Here's what I ended up using:

Code: Select all

import time
import picamera

with picamera.PiCamera() as camera:
    camera.resolution = (3280, 2464)
    camera.shutter_speed = 18000
    camera.framerate = 4
    camera.iso = 100
    camera.brightness = 48
    camera.sharpness = 70
    camera.contrast = -2
    camera.awb_mode = 'off'
    camera.awb_gains = (1.4,1.6)
    time.sleep(1)
    camera.capture_sequence([
        'image1.jpg',
        'image2.jpg',
        ], use_video_port= True
                            )
Here's a shot of a clock showing elapsed time (prior to adding shutter speed and other settings:
elapsedtime.PNG
elapsedtime.PNG (103.6 KiB) Viewed 447 times
One thing that I noticed is a slight difference in the jpg using video=true and video=false
Attachments
vidstill.PNG
vidstill.PNG (91.96 KiB) Viewed 447 times

mkhargrove
Posts: 8
Joined: Mon Dec 23, 2019 7:46 pm

Re: 8mp camera, class 10 sd, need two shots full res, fast

Fri Dec 27, 2019 7:52 pm

fyi.....The split image is video true on the left, false on the right

mkhargrove
Posts: 8
Joined: Mon Dec 23, 2019 7:46 pm

Re: 8mp camera, class 10 sd, need two shots full res, fast

Fri Dec 27, 2019 8:57 pm

note to anyone who might use this method....there's no camera exif info in the images with video=true.
I added another shot sequence with video = true, pulled exif data from that mage, and inserted it into image 1 and image 2. I'm note sure if there is a way to add exif into without doing that

ethanol100
Posts: 589
Joined: Wed Oct 02, 2013 12:28 pm

Re: 8mp camera, class 10 sd, need two shots full res, fast

Fri Dec 27, 2019 9:41 pm

Using the video port disables some advanced image processing steps to speed up the image pipeline. The noise removal is less effective using the video port. The images from the still port will have a higher quality and are less compressed compared to the ones encoded from the video port. You can try to increase the quality of the images by adding higher values to capture_sequence, for example add (....,quality=90). But this will again make it difficult to store the bigger files in time.

The video port is generally is used for creating MJPEG encoded video streams, which are basically just jpegs one after the other. For mjpeg stream EXIF is not used to store metadata and, therefore, no EXIF data is saved and there is no way around this. I don't know the details(not personally using picamera), but the picamera documentation in general is very well done. If you can spare some time, read through the manual.

It is basically a choice between good quality and frame rate. You can chose which one you prefer...

mkhargrove
Posts: 8
Joined: Mon Dec 23, 2019 7:46 pm

Re: 8mp camera, class 10 sd, need two shots full res, fast

Tue Dec 31, 2019 3:57 am

I use these shots for 3d rendering....it will be interesting to see if the photogrammetry software is able to pick up as many landmarks as before. I set my quality to 100 (as in my old shoot sequence), but with the reduced time between shots I was able to drop from iso 200 to 100. I'm assuming the improvement there will offset any lost quality in jpg conversion.

I had the luxury of just adding a third capture to my shoot sequence code, using false for video port. I pull the exif from that image and inject it into the first two which were taken with video port true. Works great.

I really appreciate the help. My old shoot sequence was over 1 second, and people move a lot in 1 second, even when they think they are perfectly still. This reduces my elapsed time enough to minimize problems from movement.

Return to “Camera board”