Grabbing multiple frames for marker detection in parallel
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();
while(1){
int threads = get_num_threads(2);
cap >> frame;
marker_detection(frame);
namedWindow(Camera[Thread], CV_WINDOW_NORMAL);
imshow(Camera[Thread], frame);
waitKey(1);
}
}
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.
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.
multithreading should be absolutely forbiden for noobs.
@Der Luftmensch thank you very much for your suggestion will check it out.
@berak true! it is complex. But i have to start at some point. Thank you.
namedWindow() contains the message-loop for the window, you can't have that in a thread.
you should rather empower opencv's builtin multithreading with TBB, openMP, IPP, etc. , than knitting your own, naive threading code around your app.
@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.