multithreading - OpenCV VideoCapture does not block on OS X -
short version: on os x, if call videocapture::read() thread other main() thread, call returns instead of blocking till new frame.
this 1 works expect:
void main() { videocapture vc(0); mat img; while(1) { vc.read( img ); // blocks till new frame arrives } } this 1 not block:
void run( videocapture& vc ) { mat img; while(1) { vc.read( img ); // returns , returns true } } void main() { videocapture vc(0); boost::thread capthread( boost::bind( &run, vc ) ); capthread.join(); } so in second version separate thread grab frames, call videocapture::read(img) returns return value true, , img set current frame, means it'll return many duplicate frames.
it's mentioned here:
problem accessing camera when using boost thread on osx
that:
"the opencv camera functions on mac require access objective-c nsrunloop; don't know how @ 1 new thread though."
anyone know of solution blocking frame grab thread other main() thread? alternatively, there nice way discard duplicate frames?
thanks
opencv doesn't support multi-threading.
let main thread capture frames , whatever need in second thread.
Comments
Post a Comment