I am trying to use OpenCV to open a camera. This works great when I open the camera in the main thread, but when I try to open the camera while in the Boost stream, it fails. I could not understand why this is happening. I guess this has something to do with Boost stream permissions.
The following works great:
#include <cv.h> #include <boost/thread.hpp> #include <highgui.h> using namespace cv; void openCamera() { Ptr< VideoCapture > capPtr(new VideoCapture(0)); // open the default camera } int main() { openCamera(); }
And my camera turns on quickly, after which I get the message "Cleaned Camera", as expected.
But when I try to do the same through the Boost thread, it does not open the camera:
#include <cv.h> #include <boost/thread.hpp> #include <highgui.h> #include <iostream> using namespace cv; void openCamera() { std::cout << "confirming that openCamera() was called" << std::endl; Ptr< VideoCapture > capPtr(new VideoCapture(0)); // open the default camera } int main() { boost::thread trackerThread( boost::bind(openCamera) ); }
It prints a "confirmation that openCamera () was called", but the camera never turns on and the message "Cleaned camera" is missing.
Can this be fixed?
Thanks!
source share