Merge pull request #184 from peters/master

.NET gardening part #3
This commit is contained in:
Matthew Hill
2015-08-13 16:03:18 -04:00

View File

@@ -368,10 +368,8 @@ namespace openalprnet {
/// Recognize from an image on disk /// Recognize from an image on disk
/// </summary> /// </summary>
AlprResultsNet^ Recognize(System::String^ filepath, List<System::Drawing::Rectangle>^ regionsOfInterest) { AlprResultsNet^ Recognize(System::String^ filepath, List<System::Drawing::Rectangle>^ regionsOfInterest) {
cv::Mat frame = cv::imread( marshal_as<std::string>(filepath) ); array<Byte>^ byteArray = File::ReadAllBytes(filepath);
std::vector<AlprRegionOfInterest> rois = AlprHelper::ToVector(regionsOfInterest); return Recognize(byteArray, regionsOfInterest);
AlprResults results = m_Impl->recognize(frame.data, frame.elemSize(), frame.cols, frame.rows, rois );
return gcnew AlprResultsNet(results);
} }
/// <summary> /// <summary>
@@ -382,19 +380,6 @@ namespace openalprnet {
return Recognize(bitmap, gcnew List<System::Drawing::Rectangle>()); return Recognize(bitmap, gcnew List<System::Drawing::Rectangle>());
} }
/// <summary>
/// Recognize from a bitmap
/// </summary>
AlprResultsNet^ Recognize(Bitmap^ bitmap, List<System::Drawing::Rectangle>^ regionsOfInterest)
{
BitmapMat^ wrapper = gcnew BitmapMat(bitmap);
cv::Mat frame = wrapper->Value;
std::vector<AlprRegionOfInterest> rois = AlprHelper::ToVector(regionsOfInterest);
AlprResults results = m_Impl->recognize(frame.data, frame.elemSize(), frame.cols, frame.rows, rois);
delete wrapper;
return gcnew AlprResultsNet(results);
}
/// <summary> /// <summary>
/// Recognize from MemoryStream representing an encoded image (e.g., BMP, PNG, JPG, GIF etc). /// Recognize from MemoryStream representing an encoded image (e.g., BMP, PNG, JPG, GIF etc).
/// </summary> /// </summary>
@@ -414,38 +399,29 @@ namespace openalprnet {
/// <summary> /// <summary>
/// Recognize from byte data representing an encoded image (e.g., BMP, PNG, JPG, GIF etc). /// Recognize from byte data representing an encoded image (e.g., BMP, PNG, JPG, GIF etc).
/// </summary> /// </summary>
/// <param name="imageBuffer">Bytes representing image data</param>
AlprResultsNet^ Recognize(array<Byte>^ imageBuffer) { AlprResultsNet^ Recognize(array<Byte>^ imageBuffer) {
return Recognize(imageBuffer, gcnew List<System::Drawing::Rectangle>()); return Recognize(imageBuffer, gcnew List<System::Drawing::Rectangle>());
} }
/// <summary>
/// Recognize from a bitmap
/// </summary>
AlprResultsNet^ Recognize(Bitmap^ bitmap, List<System::Drawing::Rectangle>^ regionsOfInterest)
{
BitmapMat^ wrapper = gcnew BitmapMat(bitmap);
AlprResultsNet^ results = Recognize(wrapper, regionsOfInterest);
delete wrapper;
return results;
}
/// <summary> /// <summary>
/// Recognize from byte data representing an encoded image (e.g., BMP, PNG, JPG, GIF etc). /// Recognize from byte data representing an encoded image (e.g., BMP, PNG, JPG, GIF etc).
/// </summary> /// </summary>
/// <param name="imageBuffer">Bytes representing image data</param>
AlprResultsNet^ Recognize(array<Byte>^ imageBuffer, List<System::Drawing::Rectangle>^ regionsOfInterest) { AlprResultsNet^ Recognize(array<Byte>^ imageBuffer, List<System::Drawing::Rectangle>^ regionsOfInterest) {
std::vector<char> buffer = AlprHelper::ToVector(imageBuffer); BitmapMat^ wrapper = gcnew BitmapMat(imageBuffer);
std::vector<AlprRegionOfInterest> rois = AlprHelper::ToVector(regionsOfInterest); AlprResultsNet^ results = Recognize(wrapper, regionsOfInterest);
AlprResults results = m_Impl->recognize(buffer, rois); delete wrapper;
return gcnew AlprResultsNet(results); return results;
}
/// <summary>
/// Recognize from raw pixel data
/// </summary>
AlprResultsNet^ Recognize(array<Byte>^ imageBuffer, int bytesPerPixel, int imgWidth, int imgHeight) {
return Recognize(imageBuffer, bytesPerPixel, imgWidth, imgHeight, gcnew List<System::Drawing::Rectangle>());
}
/// <summary>
/// Recognize from raw pixel data
/// </summary>
AlprResultsNet^ Recognize(array<Byte>^ imageBuffer, int bytesPerPixel, int imgWidth, int imgHeight, List<System::Drawing::Rectangle>^ regionsOfInterest) {
unsigned char* p = AlprHelper::ToCharPtr(imageBuffer);
std::vector<AlprRegionOfInterest> rois = AlprHelper::ToVector(regionsOfInterest);
AlprResults results = m_Impl->recognize(p, bytesPerPixel, imgWidth, imgHeight, rois);
free(p); // ?? memory leak?
return gcnew AlprResultsNet(results);
} }
/// <summary> /// <summary>
@@ -483,6 +459,14 @@ namespace openalprnet {
} }
protected: protected:
AlprResultsNet^ Recognize(BitmapMat^ bitmapMat, List<System::Drawing::Rectangle>^ regionsOfInterest) {
cv::Mat frame = bitmapMat->Value;
std::vector<AlprRegionOfInterest> rois = AlprHelper::ToVector(regionsOfInterest);
AlprResults results = m_Impl->recognize(frame.data, frame.elemSize(), frame.cols, frame.rows, rois);
return gcnew AlprResultsNet(results);
}
// Deallocate the native object on the finalizer just in case no destructor is called // Deallocate the native object on the finalizer just in case no destructor is called
!AlprNet() { !AlprNet() {
delete m_Impl; delete m_Impl;