From 40150505128066eb6fff2c4132bef55f4daacb7e Mon Sep 17 00:00:00 2001 From: Peter Rekdal Sunde Date: Wed, 12 Aug 2015 14:42:30 +0200 Subject: [PATCH] Optimize motion detector by using BitmapMat for Bitmap^ only. --- .../openalpr-net/motiondetector-net.cpp | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/bindings/csharp/openalpr-net/motiondetector-net.cpp b/src/bindings/csharp/openalpr-net/motiondetector-net.cpp index 63721e9..18b9ed6 100644 --- a/src/bindings/csharp/openalpr-net/motiondetector-net.cpp +++ b/src/bindings/csharp/openalpr-net/motiondetector-net.cpp @@ -14,23 +14,20 @@ void AlprMotionDetectionNet::ResetMotionDetection(Bitmap^ bitmap) void AlprMotionDetectionNet::ResetMotionDetection(String^ filename) { - BitmapMat^ wrapper = gcnew BitmapMat(filename); - ResetMotionDetection(wrapper->Value); - delete wrapper; + cv::Mat mat = cv::imread(marshal_as(filename)); + ResetMotionDetection(mat); } void AlprMotionDetectionNet::ResetMotionDetection(MemoryStream^ memoryStream) { - BitmapMat^ wrapper = gcnew BitmapMat(memoryStream); - ResetMotionDetection(wrapper->Value); - delete wrapper; + return ResetMotionDetection(memoryStream->ToArray()); } void AlprMotionDetectionNet::ResetMotionDetection(array^ byteArray) { - BitmapMat^ wrapper = gcnew BitmapMat(byteArray); - ResetMotionDetection(wrapper->Value); - delete wrapper; + std::vector buffer = AlprHelper::ToVector(byteArray); + cv::Mat mat = cv::imdecode(buffer, 1); + ResetMotionDetection(mat); } System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(Bitmap^ bitmap) @@ -43,26 +40,21 @@ System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(Bitmap^ bitmap) System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(String^ filename) { - BitmapMat^ wrapper = gcnew BitmapMat(filename); - System::Drawing::Rectangle motion = MotionDetect(wrapper->Value); - delete wrapper; + cv::Mat mat = cv::imread(marshal_as(filename)); + System::Drawing::Rectangle motion = MotionDetect(mat); return motion; } System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(MemoryStream^ memoryStream) { - BitmapMat^ wrapper = gcnew BitmapMat(memoryStream); - System::Drawing::Rectangle motion = MotionDetect(wrapper->Value); - delete wrapper; - return motion; + return MotionDetect(memoryStream->ToArray()); } System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(array^ byteArray) { - BitmapMat^ wrapper = gcnew BitmapMat(byteArray); - System::Drawing::Rectangle motion = MotionDetect(wrapper->Value); - delete wrapper; - return motion; + std::vector buffer = AlprHelper::ToVector(byteArray); + cv::Mat mat = cv::imdecode(buffer, 1); + return MotionDetect(mat); } void AlprMotionDetectionNet::ResetMotionDetection(cv::Mat mat)