jwatte
Posts: 203
Joined: Sat Aug 13, 2011 7:28 pm

What is the right API for camera access?

Sat Dec 27, 2014 5:35 pm

I want to access the Pi camera with as little CPU overhead as possible.
This is because I want to try a bit of real-time image detection/processing.
The camera doesn't expose a /dev/video* device. What's wrong with Video4Linux2?

Looking around, I found the userland tools (now open source,) followed by the picam "library" (which doesn't build a linkable library, but can be cannibalized.)
That seems to use a media access library called MMAL. That, in turn, seems to, perhaps, use the media access standard OpenMAX -- but it also makes reference to videocore APIs. Documentation seems to get very scarce here. Do the VideoCore libraries actually implement the IL or DL layer of the OpenMAX specification?

Poking around in userland-master, I find a directory called vcinterface/ but that contains just three files, and they make reference to include files that aren't included with the distribution (such as "vc/intrinsics.h")

Is it the case that the MMAL API is actually the lowest-accessible layer for accessing the Pi camera?
Googling for "what is linux mmal" finds nothing, really, except a bunch of RPi related use cases, so this library seems quite narrow in focus.
Which makes me wonder: Why MMAL? If VC is intended to be OpenMAX, then what's wrong with the AL of OpenMAX?
Am I missing something, or should I assume MMAL is the lowest-available layer, and documentation is largely "read the source, and the generic MMAL Doxygen on the MMAL 'My Project draft version 0.1' web site"?
http://www.jvcref.com/files/PI/documentation/html/

Note that I'm not complaining, I'm just expressing confusion about what the right starting point is.

DirkS
Posts: 10362
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: What is the right API for camera access?

Sat Dec 27, 2014 6:05 pm

The camera doesn't expose a /dev/video* device. What's wrong with Video4Linux2?
Did you activate the 'official' v4l2 driver?
See http://www.raspberrypi.org/forums/viewtopic.php?t=62364 (make sure you read the first line!)

Gr.
Dirk.

jwatte
Posts: 203
Joined: Sat Aug 13, 2011 7:28 pm

Re: What is the right API for camera access?

Sat Dec 27, 2014 8:08 pm

Thanks for the pointer!
What's the reasoning behind "activate raspberry pi camera" in the raspiconfig not actually adding this modprobe to boot?

Separately -- are there known differences in efficiency when using v4l2 versus mmal?

DirkS
Posts: 10362
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: What is the right API for camera access?

Sat Dec 27, 2014 8:48 pm

jwatte wrote:Thanks for the pointer!
What's the reasoning behind "activate raspberry pi camera" in the raspiconfig not actually adding this modprobe to boot?
No idea. At a guess I would say that it's because not everybody wants / needs it. Could also be nobody thought adding it.

Gr.
Dirk.

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: What is the right API for camera access?

Sun Dec 28, 2014 11:43 am

DirkS wrote:
jwatte wrote:Thanks for the pointer!
What's the reasoning behind "activate raspberry pi camera" in the raspiconfig not actually adding this modprobe to boot?
No idea. At a guess I would say that it's because not everybody wants / needs it. Could also be nobody thought adding it.

Gr.
Dirk.
I have three RPis but only one camera. I don't want kernel modules loaded in systems that don't have the hardware.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: What is the right API for camera access?

Sun Dec 28, 2014 12:09 pm

The point is that raspi-config does enable camera support
in the GPU if requested , but does not load the kernel
module at the same time (still at user request).

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26659
Joined: Sat Jul 30, 2011 7:41 pm

Re: What is the right API for camera access?

Sun Dec 28, 2014 12:43 pm

jwatte wrote:Thanks for the pointer!
What's the reasoning behind "activate raspberry pi camera" in the raspiconfig not actually adding this modprobe to boot?

Separately -- are there known differences in efficiency when using v4l2 versus mmal?
MMAL is slightly faster, and provide more facilities than V4L. In fact V4L is built on top of MMAL IIRC.

You can also use raw OpenMAX if that way inclined, MMAL is a replacement for OMX IL that is easier to use than the standard one, OMX is a right PITA. There are some third party example OMX programs out there on github, https://github.com/tjormola/rpi-openmax-demos.

Note that the MAL camera demo apps have always been open source, which I think was incorrectly referenced in the OP. I tried to make them as simple as possible to make them self documenting, but they are still not for 'beginners',

There is also a very good Python library, picamera, which works well.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

jwatte
Posts: 203
Joined: Sat Aug 13, 2011 7:28 pm

Re: What is the right API for camera access?

Sun Dec 28, 2014 10:30 pm

Thanks for the info! I may go with MMAL then.

Python is not something I'm looking at anymore, because I'm looking to avoid additional overhead.
As an example: I once wrote a remote control application on top of Python and D-Bus and PyGame, with a 1280x800 display for a 800 MHZ Model B. It ran at about 17 fps, and occasionally paused for seconds at a time.
I re-wrote on top of C++ and OpenGL and local sockets, and it runs at a silky smooth 60 fps with 20% CPU load.
(I similarly see 10x improvements in performance when moving compute bound web services from Python to C++ at work, so that's hardly surprising :-)

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: What is the right API for camera access?

Mon Dec 29, 2014 10:41 am

This might be interesting for you :
http://www.raspberrypi.org/forums/viewtopic.php?t=72523


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

jwatte
Posts: 203
Joined: Sat Aug 13, 2011 7:28 pm

Re: What is the right API for camera access?

Mon Dec 29, 2014 5:30 pm

If the library works, that looks interesting!

The drama in the thread was a little rich for my stomach this early in the morning when on my first cup of coffee, though :-)

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26659
Joined: Sat Jul 30, 2011 7:41 pm

Re: What is the right API for camera access?

Mon Dec 29, 2014 8:17 pm

jwatte wrote:If the library works, that looks interesting!

The drama in the thread was a little rich for my stomach this early in the morning when on my first cup of coffee, though :-)
It's an old one, people have moved on! The open source zealotry (everything must be OSS or I'll throw my dummy out of the pram) has given may to a more sane pragmatism for most people. i.e It does what I want, so it's OK.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

Return to “Advanced users”