Grabbing multiple frames for marker detection in parallel

asked 2016-04-19 13:14:35 -0600

MarKS9 gravatar image

I have a marker detection code which runs fine with a video file and camera stream. I want to modify the code to grab frames from 2 videos in 2 different threads and then process marker detection accordingly. Here is a Psuedo code what i really want to do:

string camera[2] = {"test.avi","test1.avi"};
int main(){
VideoCapture cap();
            int threads = get_num_threads(2);
            cap >> frame;
            namedWindow(Camera[Thread], CV_WINDOW_NORMAL);
            imshow(Camera[Thread], frame);

It is just the pseudo code. I am completely new to multithreading. How do i grab a frame from both the files in parallel and then process marker detection for both the frames simultaneously? Note: i have gui functions like imshow() inside marker detection function.

edit retag flag offensive close merge delete



This really has nothing to do with OpenCV and everything to do with concurrency in C++. I suggest you start by reading C++ Concurrency In Action - Practical Multithreading by Anthony Williams. As a .pdf it is readily found on the web and will teach you everything you want to know and more.

Der Luftmensch gravatar imageDer Luftmensch ( 2016-04-19 19:02:00 -0600 )edit

multithreading should be absolutely forbiden for noobs.

berak gravatar imageberak ( 2016-04-20 01:18:58 -0600 )edit

@Der Luftmensch thank you very much for your suggestion will check it out.

MarKS9 gravatar imageMarKS9 ( 2016-04-20 04:37:57 -0600 )edit

@berak true! it is complex. But i have to start at some point. Thank you.

MarKS9 gravatar imageMarKS9 ( 2016-04-20 04:39:05 -0600 )edit

namedWindow() contains the message-loop for the window, you can't have that in a thread.

berak gravatar imageberak ( 2016-04-20 04:41:02 -0600 )edit

you should rather empower opencv's builtin multithreading with TBB, openMP, IPP, etc. , than knitting your own, naive threading code around your app.

berak gravatar imageberak ( 2016-04-20 04:43:56 -0600 )edit

@berak yes i agree handling GUI's in separate thread is dangerous. I have indeed compiled OpenCV with OpenMP, CUDA, OpenCL and TBB. I just wanted to accomplish this multiple frames capture for marker detection but it seems way too complex. i followed this well written article link text and i managed to implement it for small opencv programs but could'nt for marker detection.

MarKS9 gravatar imageMarKS9 ( 2016-04-20 04:58:54 -0600 )edit