I saw some problems when OpenCV is executed from a secondary thread, and it is difficult to determine the origin of the problem when the behavior is incompatible on all platforms.
For example, your source code worked fine with OpenCV 2.3.0 on Mac OS X 10.7.2 . I don’t know which platform you use, but the fact that it worked on my computer indicates that there are some problems with the implementation of the platform you are using in OpenCV.
Now, if you cannot move the OpenCV code to the main thread, you can start thinking about creating a second program to handle all the tasks associated with OpenCV, and use some kind of IPC mechanism to allow this program to communicate with your main application.
source share