Bugfix: Motion detector is not thread safe.

This commit is contained in:
Peter Rekdal Sunde
2015-07-09 23:07:17 +02:00
parent 87d5cb5009
commit d9f6571e17

View File

@@ -39,10 +39,21 @@ using namespace System::Drawing;
using namespace System::Drawing::Imaging;
using namespace System::IO;
using namespace alpr;
using namespace System::Threading;
namespace openalprnet {
private ref class AlprHelper sealed
private ref class Lock {
Object^ m_pObject;
public:
Lock(Object ^ pObject) : m_pObject(pObject) {
Monitor::Enter(m_pObject);
}
~Lock() {
Monitor::Exit(m_pObject);
}
};
private ref class BitmapMat : IDisposable
{
private:
@@ -360,11 +371,13 @@ namespace openalprnet {
private:
void ResetMotionDetection(cv::Mat mat)
{
Lock lock(this);
this->m_motionDetector->ResetMotionDetection(&mat);
}
System::Drawing::Rectangle MotionDetect(cv::Mat mat)
{
Lock lock(this);
cv::Rect rect = this->m_motionDetector->MotionDetect(&mat);
return AlprHelper::ToRectangle(rect);
}