Best way to access camera from C


4 posts
by szhorvat » Mon Jun 16, 2014 7:23 pm
There's an (official?) Python API for accessing the camera, and there's raspistill/raspivid/raspiyuv for command line access.

What is the best/recommended way to access the camera from C (or C++)? My priority is ease of learning, which means that I prefer well documented complex stuff to udocumented simple APIs.

My ultimate goal is to access the camera form Mathematica with more flexibility than what raspistill allows. In particular, I would like to avoid shutting down and restarting the camera between taking pictures (which is slow and it takes extra time before the exposure is auto-adjusted) and I need flexibility about when the picture is taken (this rules out time lapse mode). It is easy to extend Mathematica using C/C++, but not Python. Looking for C APIs seems the best way.

So far I've found mentions of:

MMAL -- this seems to be recommended but I can't find much documentation. Is this API documented?

OpenMAX -- https://www.khronos.org/openmax/

There are also higher level APIs made by people: http://robotblogging.blogspot.com/2013/ ... i-for.html and http://www.uco.es/investiga/grupos/ava/node/40
Posts: 22
Joined: Wed Jun 04, 2014 2:07 am
by jamesh » Mon Jun 16, 2014 7:54 pm
I've never had the time to write a C library/API. MMAL is the best best for generic code, but it's a bit of a handful, and undocumented - raspistill/vid are in effect the documentation. Avoid OpenMAX. It's a right PITA to use.

Not sure how well the community based API's have been doing.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 16942
Joined: Sat Jul 30, 2011 7:41 pm
by szhorvat » Mon Jun 16, 2014 7:57 pm
jamesh wrote:I've never had the time to write a C library/API. MMAL is the best best for generic code, but it's a bit of a handful, and undocumented - raspistill/vid are in effect the documentation. Avoid OpenMAX. It's a right PITA to use.

Not sure how well the community based API's have been doing.


So based on the tools you use you suggest to look at the raspistill code and go from there?

I was going to go with OpenMAX (partly based on this sample code), but I'll look at the raspistill sources first then.

Thanks!
Posts: 22
Joined: Wed Jun 04, 2014 2:07 am
by jamesh » Mon Jun 16, 2014 7:58 pm
szhorvat wrote:
jamesh wrote:I've never had the time to write a C library/API. MMAL is the best best for generic code, but it's a bit of a handful, and undocumented - raspistill/vid are in effect the documentation. Avoid OpenMAX. It's a right PITA to use.

Not sure how well the community based API's have been doing.


So based on the tools you use you suggest to look at the raspistill code and go from there?

I was going to go with OpenMAX (partly based on this sample code), but I'll look at the raspistill sources first then.

Thanks!


That is what I would recommend. MMAL was written so people didn't have to use OpenMAX when implementing Android on the Videocore (Note: this was not for the Raspi SoC, but another VC4 based device), so is designed to be much easier to use. And it is.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 16942
Joined: Sat Jul 30, 2011 7:41 pm