From 349df763c0bbe5f225933ee900ac3ecc0ddf1e04 Mon Sep 17 00:00:00 2001 From: Peter Rekdal Sunde Date: Wed, 8 Jul 2015 13:07:32 +0200 Subject: [PATCH] Add motion detector. --- .../csharp/openalpr-net/openalpr-net.cpp | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/src/bindings/csharp/openalpr-net/openalpr-net.cpp b/src/bindings/csharp/openalpr-net/openalpr-net.cpp index 8a1bafa..2a7c21f 100644 --- a/src/bindings/csharp/openalpr-net/openalpr-net.cpp +++ b/src/bindings/csharp/openalpr-net/openalpr-net.cpp @@ -20,6 +20,7 @@ #include "openalpr-net.h" #include "alpr.h" #include "config.h" // alpr +#include "motiondetector.h" // alpr #include #include #include @@ -187,6 +188,89 @@ namespace openalprnet { }; + public enum class OpenCVMatType { + Unchanged = CV_LOAD_IMAGE_UNCHANGED, + Grayscale = CV_LOAD_IMAGE_GRAYSCALE, + Color = CV_LOAD_IMAGE_COLOR, + AnyDepth = CV_LOAD_IMAGE_ANYDEPTH, + AnyColor = CV_LOAD_IMAGE_ANYCOLOR + }; + + public ref class AlprMotionDetectionNet : IDisposable { + public: + AlprMotionDetectionNet() + { + m_motionDetector = new MotionDetector(); + } + + void ResetMotionDetection(Bitmap^ bitmap) + { + ResetMotionDetection(Mat(bitmap)); + } + + void ResetMotionDetection(String^ filename, OpenCVMatType matType) + { + return ResetMotionDetection(Mat(filename, matType)); + } + + System::Drawing::Rectangle MotionDetect(Bitmap^ bitmap) + { + return MotionDetect(Mat(bitmap)); + } + + System::Drawing::Rectangle MotionDetect(String^ filename, OpenCVMatType matType) + { + return MotionDetect(Mat(filename, matType)); + } + + private: + void ResetMotionDetection(cv::Mat mat) + { + this->m_motionDetector->ResetMotionDetection(&mat); + } + + System::Drawing::Rectangle MotionDetect(cv::Mat mat) + { + cv::Rect rect = this->m_motionDetector->MotionDetect(&mat); + return AlprHelper::ToRectangle(rect); + } + + cv::Mat Mat(String^ filename, OpenCVMatType matType) + { + cv::Mat mat = cv::imread(AlprHelper::ToStlString(filename), static_cast(matType)); + return mat; + } + + cv::Mat Mat(Bitmap^ bitmap) + { + cv::Mat mat = AlprHelper::BitmapToMat(bitmap); + return mat; + } + + private: + + ~AlprMotionDetectionNet() + { + if(this->m_Disposed) + { + return; + } + + this->!AlprMotionDetectionNet(); + this->m_Disposed = true; + } + + !AlprMotionDetectionNet() + { + delete m_motionDetector; + } + + private: + MotionDetector* m_motionDetector; + bool m_Disposed; + }; + + public enum class AlprDetectorTypeNet : int { DetectorLbpCpu = alpr::DETECTOR_LBP_CPU, DetectorLbpGpu = alpr::DETECTOR_LBP_GPU,