opencv callback

Hello Im programming a machine vision application and I need to
capture every single frame from the camera.

Is there a way to define a callback function that gets invoked with
every single frame?

I had been searching the internet but founf nothing so far.

Regards
Frank

@frank

what exactly do you mean by a callback function…??

Hello

As far as I see in the opencv examples, to acquire frames from a
webcam i need to do a loop calling cvQueryFrame.

This is highly inefficient because y need to use a hardware triggered
camera that only takes a shoot once in a while when a sensor is
activated.

I need to find a way that an event in triggered inside the application
when a frame is acquired and not constantly polling with cvQueryFrame.

Regards
Frank

If you want performance, just use video4linux directly. It's not really that difficult if you're only working with a specific camera.

But I can define a callback function with video4linux?

I cant be constantly polling the frame buffer, I need perfect synchro
with the camera.

Thanks
Frank

It doesn't work like that, because that isn't the best solution. But you could always write a wrapper to behave that way if it makes you happier.

It uses a ring buffer of buffers and lets you know when the last one was filled with data, and then lets you tell it when a buffer is free for filling again.

It is the linux driver interface anyway: it's what opencv or any other library has to use, so it by definition is the fastest possible interface.

There's a whole lot of documentation about it and examples a mere search away.

frank

Why dont u try putting CvQueryFrame in a conditional block. the condition should be based on the input from the sensor.

Ankit

Im doing a software for PET bottle inspection

The bottles go as fast as hell in the conveyor. 30 bottles per second
in front of the optical sensor. You can't even see them

The polling method is not fast enough, the only way is a hardware
trigger thats take the shot in the camera and inform the software.

If anybody has working on machine vision applications knows what Im
talking about.

All professional (and super-expensive) frame grabbers and image
capture softwares relies on callback functions invoked directly from
the hardware driver, very close to the metal.

Its the only way, if you loose a microsecond, then you cant capture
the fast moving bottle.

I was trying to achieve this but I think its not possible with linux.
One point to Microsoft.

Thanks
Frank

Frank,
     Although using V4L rather than OpenCV, I have found the following example useful in capturing every frame from my camera at up to 30fps using the memory mapped method.

http://free-electrons.com/kerneldoc/latest/DocBook/media_api/capture-example.html

HTH,

Dave.

Hello,

Yes I guess this example is as close to the hardware driver as possible.
Its impossible go below in the system architecture.

This could be fast, can you explain me how to use and compile?
Im new to linux.

Now, I have a question, if anybody knows, all that fighter jets, and
tanks, they have running computers controlling all the weapons.
What operating system are they using? Some kind of realtime OS I think?

Because they need to be really real-time, I guess a missile in pursuit
of a plane can't afford to loose a nanosecond in polling a buffer
because it would miss the target.

Anybody could to run a realtime OS in the beaglebone or beagleboard?
This is what I might need for the bottle-inspection system.

Thanks
Frank

Probably VxWorks for the RTOS if it's something military grade.

The BeagleBone has support for StarterWare, a 'c'-based realtime "no-OS". There is also the BeagleBone with PREEMPT-RT extensions to the Linux kernel, or a Xenomai-patched Linux kernel for dual kernel RTOS functionaklity. The general consensus seems to be that Xenomai has the best realtime performance.

I think you would still have to have a framebuffer that could capture 30-60fps in hardware with compression though. Maybe a custom CMOS or CCD imager with a CPLD, the CoolRunner II CPLD cape might be an option for your project.

Hey your example is working!

It turns on my webcam and display a progress, but where are the images acquired?
I guess the images were recorded somewhere in the disk?

Regards
Frank

I thought you were just using a usb webcam, not a 'high performance' frame grabber?

Callbacks are just an implementation detail.

And you must realise that the kernel internally does all this (using hardware interrupts - as indeed drivers on microsoft do too) - the whole point of the ring buffer is that it wont drop frames unless it really just can't keep up.

And if you think microsoft is a better fit, why aren't you using it?

I'm not sure what you're trying to achieve - the hardware should be able to take photos that fast, but you probably wont be able to do much with them at that speed on a beagleboard.

Hello,

Yes I guess this example is as close to the hardware driver as possible.
Its impossible go below in the system architecture.

This could be fast, can you explain me how to use and compile?
Im new to linux.

Now, I have a question, if anybody knows, all that fighter jets, and
tanks, they have running computers controlling all the weapons.
What operating system are they using? Some kind of realtime OS I think?

Because they need to be really real-time, I guess a missile in pursuit
of a plane can’t afford to loose a nanosecond in polling a buffer
because it would miss the target.

Anybody could to run a realtime OS in the beaglebone or beagleboard?
This is what I might need for the bottle-inspection system.

Although I haven’t used it, Xenomai is supposed to be a good choice for realtime on Linux, and it was designed for embedded systems.

  • Grant

Hey your example is working!

It turns on my webcam and display a progress, but where are the images acquired?
I guess the images were recorded somewhere in the disk?

No, the images are ephemeral, just passed as the void pointer "p" to the dummy procedure "process_image". You need to replace this with your code.

Dave.

Frank,

I am not very learned in the project u talk about.

Regarding RTOS on beagle board… Texas Instruments provides a list of all RTOS that are ported to the beagleboard. I am attaching the link below…

http://www.ti.com/lsds/ti/tools-software/rtos.page

If u have beagleboard then u have 6 options. if you have BB xM then u have 4 options.,

personally i have BB xM and i am using QNX Neutrino/ QNX 6. latency is in micro seconds.

Go ahead and read the link…

Ankit Mishra

Frank,

When it comes to grabbing frames at a fast rate, multiple factors come into picture…

1 - camera - how fast can ur camera work/capture

2 - Query - How fast is your processor calling the function to capture. The processor should be able to work at a speed fast enough to execute the instructions and handle all that data that comes inb via the camera.

3 - OS - how fast is your OS switching between task, to respond. The OS should switch between tasks at a lag which is lesser than the needed speed/frequency.

I hope this makes sense. This is on what i think. I am also doing a project on Image processing + Beagleboard xM…

Ankit Mishra

But how you capture the images?

In a loop or using hardware interrups?

In a loop… but i have not progressed enough to talk about the speed/rate of capture…
even i struggled a while to decide on OS with minimum delay and booting it…

Realized that using an RTOS should minimize the delay…