coder9
coder9

Reputation: 1549

Using Threads for Multiple marker detection in OpenCV

I'm working on an Augmented Reality project in which I have to do "multiple marker detection + identification" using OpenCV. I'm on Windows, Visual C++ 2008. I have done up to the Single threaded part.

I was wondering if there are any Threading mechanisms already available in OpenCV for doing a similar task. Else what are other methods I can consider?

I'm also hoping to use the rotation and translation matrices generated for each marker (using OpenCV) when overlaying 3D models. Is there a better way to organize/keep these data?

EDIT:

This is for an academic project where efficiency and other matters are not that important. It's perfectly fine as long as it's a working solution.

Upvotes: 2

Views: 954

Answers (1)

NeViXa
NeViXa

Reputation: 81

What you could do is using the Boost library in combination with a concurrent queue. Here you can find a concurrent queue that I made working together with boost threading and OpenCV.

To use the concurrent queue with OpenCV you could thread it something like this:

    boost::thread_group frame_workers;   
    concurrent_queue<IplImage* > frame_queue(&frame_workers);

    boost::thread * frame_thread = new boost::thread(frame_grabber, &frame_queue);
    boost::thread * marker_thread = new boost::thread(marker_handler, &frame_queue);

    frame_workers.add_thread(frame_thread);
    frame_workers.add_thread(marker_thread);

In the frame_grabber function you can grab frames and push them into the frame_queue. When doing this, the marker_thread is notified that there is a frame waiting in the queue (with wait_and_pop). A short example for the grabbing part can be something like this:

 void frame_grabber(concurrent_queue<IplImage* > * frame_queue) {
     frame = cvQueryFrame(input_video);
     frame_copy = cvCreateImage(cvGetSize(frame), 8, 3);
     cvCopy(frame, frame_copy);
     frame_queue->push(frame);
 }

Upvotes: 1

Related Questions