mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 06:30:58 +08:00
Bugfix: Motion detector is not thread safe.
This commit is contained in:
@@ -39,10 +39,21 @@ using namespace System::Drawing;
|
|||||||
using namespace System::Drawing::Imaging;
|
using namespace System::Drawing::Imaging;
|
||||||
using namespace System::IO;
|
using namespace System::IO;
|
||||||
using namespace alpr;
|
using namespace alpr;
|
||||||
|
using namespace System::Threading;
|
||||||
|
|
||||||
namespace openalprnet {
|
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 ref class BitmapMat : IDisposable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -360,11 +371,13 @@ namespace openalprnet {
|
|||||||
private:
|
private:
|
||||||
void ResetMotionDetection(cv::Mat mat)
|
void ResetMotionDetection(cv::Mat mat)
|
||||||
{
|
{
|
||||||
|
Lock lock(this);
|
||||||
this->m_motionDetector->ResetMotionDetection(&mat);
|
this->m_motionDetector->ResetMotionDetection(&mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
System::Drawing::Rectangle MotionDetect(cv::Mat mat)
|
System::Drawing::Rectangle MotionDetect(cv::Mat mat)
|
||||||
{
|
{
|
||||||
|
Lock lock(this);
|
||||||
cv::Rect rect = this->m_motionDetector->MotionDetect(&mat);
|
cv::Rect rect = this->m_motionDetector->MotionDetect(&mat);
|
||||||
return AlprHelper::ToRectangle(rect);
|
return AlprHelper::ToRectangle(rect);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user