From 0987f6858a0b2b517b59c6cd364e68e3ae38a2ff Mon Sep 17 00:00:00 2001 From: Peter Rekdal Sunde Date: Thu, 9 Jul 2015 17:23:37 +0200 Subject: [PATCH] Use c++/cli type Byte instead of char so you don't have to cast C# byte[] array to unsigned byte array. --- src/bindings/csharp/openalpr-net/openalpr-net.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/bindings/csharp/openalpr-net/openalpr-net.cpp b/src/bindings/csharp/openalpr-net/openalpr-net.cpp index 2849380..38a8ebb 100644 --- a/src/bindings/csharp/openalpr-net/openalpr-net.cpp +++ b/src/bindings/csharp/openalpr-net/openalpr-net.cpp @@ -55,6 +55,16 @@ namespace openalprnet { return result; } + static std::vector ToVector(array^ src) + { + std::vector result(src->Length); + pin_ptr pin(&src[0]); + char* pch = reinterpret_cast(pin); + char *first(pch), *last(pch + src->Length); + std::copy(first, last, result.begin()); + return result; + } + static cv::Mat BitmapToMat(Bitmap^ bitmap) { int channels = 0; @@ -1308,7 +1318,7 @@ namespace openalprnet { /// Recognize from byte data representing an encoded image (e.g., BMP, PNG, JPG, GIF etc). /// /// Bytes representing image data - AlprResultsNet^ recognize(cli::array^ imageBuffer) { + AlprResultsNet^ recognize(cli::array^ imageBuffer) { std::vector p = AlprHelper::ToVector(imageBuffer); AlprResults results = m_Impl->recognize(p); return gcnew AlprResultsNet(results); @@ -1317,7 +1327,7 @@ namespace openalprnet { /// /// Recognize from raw pixel data /// - AlprResultsNet^ recognize(cli::array^ pixelData, int bytesPerPixel, int imgWidth, int imgHeight, List^ regionsOfInterest) { + AlprResultsNet^ recognize(cli::array^ pixelData, int bytesPerPixel, int imgWidth, int imgHeight, List^ regionsOfInterest) { unsigned char* p = AlprHelper::ToCharPtr(pixelData); std::vector rois = AlprHelper::ToVector(regionsOfInterest); AlprResults results = m_Impl->recognize(p, bytesPerPixel, imgWidth, imgHeight, rois);