Librem5 OpenCV Example?

Hello all. New user here. Recently received my new L5 phone. I hope I have picked the right forum category.

Simple question/request: does someone have a working example of using OpenCV to access/take pictures with either of the L5 cameras?

Thanks!

Do you know what interface is used by OpenCV to access cameras?

It can use USB cameras for sure, but it’s going to be useless here. If it can use Raspberry Pi cameras, I think it might be possible to connect.

OpenCV provides V4L/V4L2 interfacing https://github.com/opencv/opencv/blob/master/modules/videoio/src/cap_v4l.cpp so it is compatible at least with low level /dev/video0 and /dev/video2 kernel drivers of Librem 5 integrated cameras. But problem is that these SoC cameras are complex and direct parameters control is complicated and you need to find actual hierarchy of input chip control, its mux and then imx8m video capture interface. So for real control libcamera would be useful, but I am not sure how mature is its interoperability with OpenCV and if Librem 5 camera kernel support is ready enough. The device parameters should be controlled over /dev/mediaW… It seems that original hacks in Millipixels with calling I2C transfer to control parameters has been replaced in January. You can use media-ctl --print-topology to obtain more idea about setup.

It seems that in actual Millipixel source https://source.puri.sm/Librem5/millipixels the exposure and gain are controlled over IOCTLs but focus is controlled with help of media-ctl calls. @dcz can confirm that, I think.

So you can use/reimplement functions found in Millipixels or you can use Millipixels or media-ctl to setup parameters and then use /dev/videoX directly from OpenCV with correctly/matching defined format. You can try to contact Pavel Machek who works on autofocus and other goodies for multiple phones in his spare time right now.

Some more information about media-ctl at http://trac.gateworks.com/wiki/linux/media

This was done for simplicity, but it will change with the transition to libcamera.

4 Likes