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

Enhancing picamera with new MMAL features

Fri May 15, 2020 7:40 pm

MMAL contains a feature that allows to display Figure of Merit in order to ease focusing of camera lens.
That was recently made available to raspiv̶i̶d̶still ("--focus"/"-fw").

I wanted to use that feature with picamera and was able to do so.
The last line in this snippet enables FoM for the camera.

Code: Select all

...
camera = mo.MMALCamera()
...
camera.outputs[0].framesize = (500, 500)
camera.outputs[0].framerate = 30
camera.outputs[0].commit()

camera.control.params[mmal.MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS] = 1
...

MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS needs to be added to picamera/mmalobj.py:

Code: Select all

...
    mmal.MMAL_PARAMETER_ZOOM:                           mmal.MMAL_PARAMETER_SCALEFACTOR_T,
+   mmal.MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS:       mmal.MMAL_PARAMETER_BOOLEAN_T,
    }
---

In order to make use of the new picamera without overwriting system picamera, sample python scripts making use of changed picamera have to be placed in picamera top level directory, that is all.

More details in this thread:
viewtopic.php?f=43&t=273804

My picamera fork ("This branch is 3 commits ahead of waveform80:master"):
https://github.com/Hermann-SW/picamera

Code: Select all

🍓 python ~/picamera/camera_preview_on_two_displays_with_FoM.py 
results in this:
Image
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

pootle
Posts: 374
Joined: Wed Sep 04, 2013 10:20 am
Location: Staffordshire
Contact: Website

Re: Enhancing picamera with new MMAL features

Sun May 17, 2020 8:03 am

OOh! that's really useful. I've just made a stepper motor based focuser for a canon lens, driven from my pi and I have a python app that drives the camera, auto focus is the next step....

Return to “Python”