diff --git a/src/bindings/csharp/openalpr-net/helper-net.h b/src/bindings/csharp/openalpr-net/helper-net.h index 806ace0..c4716e0 100644 --- a/src/bindings/csharp/openalpr-net/helper-net.h +++ b/src/bindings/csharp/openalpr-net/helper-net.h @@ -48,67 +48,6 @@ namespace openalprnet return result; } - static Bitmap^ MatToBitmap(cv::Mat mat) - { - if (mat.empty()) - { - return nullptr; - } - - const int width = mat.size().width; - const int height = mat.size().height; - const int channels = mat.channels(); - const int totalSize = mat.total(); - void* data = reinterpret_cast(mat.data); - Bitmap ^bitmap; - - if (channels == 1) - { - bitmap = gcnew Bitmap(width, height, PixelFormat::Format8bppIndexed); - - ColorPalette ^palette = bitmap->Palette; - for (int i = 0; i < 256; i++) - { - palette->Entries[i] = Color::FromArgb(i, i, i); - } - - bitmap->Palette = palette; - } - else - { - bitmap = gcnew Bitmap(width, height, PixelFormat::Format24bppRgb); - } - - System::Drawing::Imaging::BitmapData ^bitmapData = bitmap->LockBits( - System::Drawing::Rectangle(0, 0, bitmap->Width, bitmap->Height), - System::Drawing::Imaging::ImageLockMode::ReadWrite, - bitmap->PixelFormat - ); - - char *src = reinterpret_cast(bitmapData->Scan0.ToPointer()); - pin_ptr pin(&src[0]); - - ::memcpy(pin, data, totalSize); - - bitmap->UnlockBits(bitmapData); - - return bitmap; - } - - static MemoryStream^ BitmapToMemoryStream(Bitmap^ bitmap, ImageFormat^ imageFormat) - { - MemoryStream^ ms = gcnew System::IO::MemoryStream(); - bitmap->Save(ms, imageFormat); - return ms; - } - - static std::vector MemoryStreamToVector(MemoryStream^ ms) - { - unsigned char* byteArray = ToCharPtr(ms->ToArray()); - std::vector result(byteArray, byteArray + ms->Length); - return result; - } - static std::vector ToVector(List^ src) { std::vector result; @@ -135,18 +74,6 @@ namespace openalprnet return gcnew String(s.c_str()); } - static std::string ToStlString(System::String^ s) - { - IntPtr ptr = Marshal::StringToHGlobalAnsi(s); - if (ptr != IntPtr::Zero) - { - std::string tmp(reinterpret_cast(static_cast(ptr))); - Marshal::FreeHGlobal(ptr); - return tmp; - } - return std::string(); - } - static System::Drawing::Rectangle ToRectangle(cv::Rect rect) { return System::Drawing::Rectangle(rect.x, rect.y, rect.width, rect.height); diff --git a/src/bindings/csharp/openalpr-net/openalpr-net.cpp b/src/bindings/csharp/openalpr-net/openalpr-net.cpp index fb9183b..79239d8 100644 --- a/src/bindings/csharp/openalpr-net/openalpr-net.cpp +++ b/src/bindings/csharp/openalpr-net/openalpr-net.cpp @@ -408,10 +408,7 @@ namespace openalprnet { /// AlprResultsNet^ Recognize(MemoryStream^ memoryStream, List^ regionsOfInterest) { - std::vector buffer = AlprHelper::MemoryStreamToVector(memoryStream); - std::vector rois = AlprHelper::ToVector(regionsOfInterest); - AlprResults results = m_Impl->recognize(buffer, rois); - return gcnew AlprResultsNet(results); + return Recognize(memoryStream->ToArray(), regionsOfInterest); } ///