I invoke the following OpenCV method (Emgu CV wrapper), which detects faces, in several threads simultaneously:
IntPtr objects = CvInvoke.cvHaarDetectObjects(
img.Ptr,
haarObj.Ptr,
stor.Ptr,
scaleFactor,
minNeighbors,
flag,
minSize);
I get AccessViolationException. The standard .NET lock is unacceptable here since this method takes almost all a thread lifetime. Any ideas how to make this method work concurrently?
The solution is to use an internal multithreading in OpenCV. For that to work, OpenCV must be built with Intel TBB. Then when the Detect method is called, it uses multiple threads internally.