mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 11:30:55 +08:00
Merge branch 'master' of https://github.com/peters/openalpr into dotNetFixes
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
#include "stdafx.h"
|
||||
#include "openalpr-net.h"
|
||||
#include "alpr.h"
|
||||
#include "config.h" // alpr
|
||||
#include "motiondetector.h" // alpr
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
@@ -34,6 +36,8 @@ using namespace msclr::interop;
|
||||
using namespace System::Collections::Generic;
|
||||
using namespace System::Runtime::InteropServices;
|
||||
using namespace System::Drawing;
|
||||
using namespace System::Drawing::Imaging;
|
||||
using namespace System::IO;
|
||||
using namespace alpr;
|
||||
|
||||
namespace openalprnet {
|
||||
@@ -41,6 +45,7 @@ namespace openalprnet {
|
||||
private ref class AlprHelper sealed
|
||||
{
|
||||
public:
|
||||
|
||||
static std::vector<char> ToVector(array<char>^ src)
|
||||
{
|
||||
std::vector<char> result(src->Length);
|
||||
@@ -50,6 +55,94 @@ namespace openalprnet {
|
||||
return result;
|
||||
}
|
||||
|
||||
static cv::Mat BitmapToMat(Bitmap^ bitmap)
|
||||
{
|
||||
int channels = 0;
|
||||
|
||||
switch(bitmap->PixelFormat)
|
||||
{
|
||||
case PixelFormat::Format8bppIndexed:
|
||||
case PixelFormat::Format1bppIndexed:
|
||||
channels = 1;
|
||||
break;
|
||||
case PixelFormat::Format24bppRgb:
|
||||
channels = 3;
|
||||
break;
|
||||
case PixelFormat::Format32bppRgb:
|
||||
case PixelFormat::Format32bppArgb:
|
||||
case PixelFormat::Format32bppPArgb:
|
||||
channels = 4;
|
||||
break;
|
||||
default:
|
||||
throw gcnew NotImplementedException();
|
||||
}
|
||||
|
||||
BitmapData^ bitmapData = bitmap->LockBits(
|
||||
System::Drawing::Rectangle(0, 0, bitmap->Width, bitmap->Height),
|
||||
ImageLockMode::ReadOnly,
|
||||
bitmap->PixelFormat
|
||||
);
|
||||
|
||||
cv::Mat dstMat(cv::Size(bitmap->Width, bitmap->Height), CV_8UC(channels), reinterpret_cast<char*>(bitmapData->Scan0.ToPointer()));
|
||||
|
||||
bitmap->UnlockBits(bitmapData);
|
||||
|
||||
return dstMat;
|
||||
}
|
||||
|
||||
static Bitmap^ MatToBitmap(cv::Mat mat)
|
||||
{
|
||||
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<void*>(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
|
||||
);
|
||||
|
||||
::memcpy(bitmapData->Scan0.ToPointer(), 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<char> MemoryStreamToVector(MemoryStream^ ms)
|
||||
{
|
||||
unsigned char* byteArray = ToCharPtr(ms->ToArray());
|
||||
std::vector<char> result(byteArray, byteArray + ms->Length);
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::vector<AlprRegionOfInterest> ToVector(List<System::Drawing::Rectangle>^ src)
|
||||
{
|
||||
std::vector<AlprRegionOfInterest> result;
|
||||
@@ -87,6 +180,744 @@ namespace openalprnet {
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
static System::Drawing::Rectangle ToRectangle(cv::Rect rect)
|
||||
{
|
||||
return System::Drawing::Rectangle(rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
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<int>(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,
|
||||
DetectorLbpMorphCpu = alpr::DETECTOR_MORPH_CPU
|
||||
};
|
||||
|
||||
public ref class AlprConfigNet sealed
|
||||
{
|
||||
public:
|
||||
|
||||
AlprConfigNet(Config* config) : m_config (config)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
property bool IsLoaded {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->loaded;
|
||||
}
|
||||
}
|
||||
|
||||
property AlprDetectorTypeNet Detector {
|
||||
AlprDetectorTypeNet get() {
|
||||
return static_cast<AlprDetectorTypeNet>(this->m_config->detector);
|
||||
}
|
||||
void set(AlprDetectorTypeNet value)
|
||||
{
|
||||
this->m_config->detector = static_cast<int>(value);
|
||||
}
|
||||
}
|
||||
|
||||
property float DetectionIterationIncrease {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->detection_iteration_increase;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->detection_iteration_increase = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float DetectionStrictness {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->detectionStrictness;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->detectionStrictness = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float MaxPlateWidthPercent {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->maxPlateWidthPercent;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->maxPlateWidthPercent = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float MaxPlateHeightPercent {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->maxPlateHeightPercent;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->maxPlateHeightPercent = value;
|
||||
}
|
||||
}
|
||||
|
||||
property int MaxDetectionInputWidth {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->maxDetectionInputWidth;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->maxDetectionInputWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
property int MaxDetectionInputHeight {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->maxDetectionInputHeight;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->maxDetectionInputHeight = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool SkipDetection {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->skipDetection;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->skipDetection = true;
|
||||
}
|
||||
}
|
||||
|
||||
property String^ PreWarp {
|
||||
String^ get()
|
||||
{
|
||||
return AlprHelper::ToManagedString(this->m_config->prewarp);
|
||||
}
|
||||
void set(String^ value)
|
||||
{
|
||||
this->m_config->prewarp = marshal_as<std::string>(value);
|
||||
}
|
||||
}
|
||||
|
||||
property int MaxPlateAngleDegrees {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->maxPlateAngleDegrees;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->maxPlateAngleDegrees = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float MinPlateSizeWidthPx {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->minPlateSizeWidthPx;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->minPlateSizeWidthPx = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float minPlateSizeHeightPx {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->minPlateSizeHeightPx;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->minPlateSizeHeightPx = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool Multiline {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->multiline;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->multiline = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float PlateWidthMM {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->plateWidthMM;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->plateWidthMM = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float PlateHeightMM {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->plateHeightMM;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->plateHeightMM = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float CharHeightMM {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->charHeightMM;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->charHeightMM = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float CharWidthMM {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->charWidthMM;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->charWidthMM = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float CharWhitespaceTopMM {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->charWhitespaceTopMM;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->charWhitespaceTopMM = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float CharWhitespaceBotMM {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->charWhitespaceBotMM;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->charWhitespaceBotMM = value;
|
||||
}
|
||||
}
|
||||
|
||||
property int TemplateWidthPx {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->templateWidthPx;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->templateWidthPx = value;
|
||||
}
|
||||
}
|
||||
|
||||
property int TemplateHeightPx {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->templateHeightPx;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->templateHeightPx = value;
|
||||
}
|
||||
}
|
||||
|
||||
property int OcrImageWidthPx {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->ocrImageWidthPx;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->ocrImageWidthPx = value;
|
||||
}
|
||||
}
|
||||
|
||||
property int OcrImageHeightPx {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->ocrImageHeightPx;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->ocrImageHeightPx = value;
|
||||
}
|
||||
}
|
||||
|
||||
property int StateIdImageWidthPx {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->stateIdImageWidthPx;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->stateIdImageWidthPx = value;
|
||||
}
|
||||
}
|
||||
|
||||
property int StateIdimageHeightPx {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->stateIdimageHeightPx;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->stateIdimageHeightPx = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float CharAnalysisMinPercent {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->charAnalysisMinPercent;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->charAnalysisMinPercent = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float CharAnalysisHeightRange {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->charAnalysisHeightRange;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->charAnalysisHeightRange = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float CharAnalysisHeightStepSize {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->charAnalysisHeightStepSize;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->charAnalysisHeightStepSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
property int CharAnalysisNumSteps {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->charAnalysisNumSteps;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->charAnalysisNumSteps = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float PlateLinesSensitivityVertical {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->plateLinesSensitivityVertical;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->plateLinesSensitivityVertical = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float PlateLinesSensitivityHorizontal {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->plateLinesSensitivityHorizontal;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->plateLinesSensitivityHorizontal = value;
|
||||
}
|
||||
}
|
||||
|
||||
property int SegmentationMinBoxWidthPx {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->segmentationMinBoxWidthPx;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->segmentationMinBoxWidthPx = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float SegmentationMinCharHeightPercent {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->segmentationMinCharHeightPercent;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->segmentationMinCharHeightPercent = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float SegmentationMaxCharWidthvsAverage {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->segmentationMaxCharWidthvsAverage;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->segmentationMaxCharWidthvsAverage = value;
|
||||
}
|
||||
}
|
||||
|
||||
property String^ OcrLanguage {
|
||||
String^ get()
|
||||
{
|
||||
return AlprHelper::ToManagedString(this->m_config->ocrLanguage);
|
||||
}
|
||||
void set(String^ value)
|
||||
{
|
||||
this->m_config->ocrLanguage = marshal_as<std::string>(value);
|
||||
}
|
||||
}
|
||||
|
||||
property int OcrMinFontSize {
|
||||
int get()
|
||||
{
|
||||
return this->m_config->ocrMinFontSize;
|
||||
}
|
||||
void set(int value)
|
||||
{
|
||||
this->m_config->ocrMinFontSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float PostProcessMinConfidence {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->postProcessMinConfidence;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->postProcessMinConfidence = value;
|
||||
}
|
||||
}
|
||||
|
||||
property float PostProcessConfidenceSkipLevel {
|
||||
float get()
|
||||
{
|
||||
return this->m_config->postProcessConfidenceSkipLevel;
|
||||
}
|
||||
void set(float value)
|
||||
{
|
||||
this->m_config->postProcessConfidenceSkipLevel = value;
|
||||
}
|
||||
}
|
||||
|
||||
property unsigned int PostProcessMinCharacters {
|
||||
unsigned int get()
|
||||
{
|
||||
return this->m_config->postProcessMinCharacters;
|
||||
}
|
||||
void set(unsigned int value)
|
||||
{
|
||||
this->m_config->postProcessMinCharacters = value;
|
||||
}
|
||||
}
|
||||
|
||||
property unsigned int PostProcessMaxCharacters {
|
||||
unsigned int get()
|
||||
{
|
||||
return this->m_config->postProcessMaxCharacters;
|
||||
}
|
||||
void set(unsigned int value)
|
||||
{
|
||||
this->m_config->postProcessMaxCharacters = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugGeneral {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugGeneral;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugGeneral = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugTiming {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugTiming;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugTiming = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugPrewarp {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugPrewarp;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugPrewarp = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugDetector {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugDetector;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugDetector = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugStateId {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugStateId;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugStateId = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugPlateLines {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugPlateLines;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugPlateLines = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugPlateCorners {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugPlateCorners;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugPlateCorners = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugCharSegmenter {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugCharSegmenter;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugCharSegmenter = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugCharAnalysis {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugCharAnalysis;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugCharAnalysis = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugColorFiler {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugColorFiler;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugColorFiler = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugOcr {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugOcr;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugOcr = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugPostProcess {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugPostProcess;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugPostProcess = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugShowImages {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugShowImages;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugShowImages = value;
|
||||
}
|
||||
}
|
||||
|
||||
property bool DebugPauseOnFrame {
|
||||
bool get()
|
||||
{
|
||||
return this->m_config->debugPauseOnFrame;
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
this->m_config->debugPauseOnFrame = value;
|
||||
}
|
||||
}
|
||||
|
||||
void DebugOff(bool value)
|
||||
{
|
||||
this->m_config->debugOff(value);
|
||||
}
|
||||
|
||||
String^ GetKeypointsRuntimeDir()
|
||||
{
|
||||
return AlprHelper::ToManagedString(this->m_config->getKeypointsRuntimeDir());
|
||||
}
|
||||
|
||||
String^ GetCascadeRuntimeDir()
|
||||
{
|
||||
return AlprHelper::ToManagedString(this->m_config->getCascadeRuntimeDir());
|
||||
}
|
||||
|
||||
String^ GetPostProcessRuntimeDir()
|
||||
{
|
||||
return AlprHelper::ToManagedString(this->m_config->getPostProcessRuntimeDir());
|
||||
}
|
||||
|
||||
String^ GetTessdataPrefix()
|
||||
{
|
||||
return AlprHelper::ToManagedString(this->m_config->getTessdataPrefix());
|
||||
}
|
||||
|
||||
~AlprConfigNet()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
private:
|
||||
Config *m_config;
|
||||
};
|
||||
|
||||
public ref class AlprPlateNet sealed
|
||||
@@ -334,15 +1165,30 @@ namespace openalprnet {
|
||||
bool m_cancel;
|
||||
};
|
||||
|
||||
public ref class AlprNet sealed
|
||||
public ref class AlprNet sealed : IDisposable
|
||||
{
|
||||
public:
|
||||
// Allocate the native object on the C++ Heap via a constructor
|
||||
AlprNet(System::String^ country, System::String^ configFile, System::String^ runtimeDir) : m_Impl( new Alpr(marshal_as<std::string>(country), marshal_as<std::string>(configFile), marshal_as<std::string>(runtimeDir)) ) { }
|
||||
AlprNet(System::String^ country, System::String^ configFile, System::String^ runtimeDir) : m_Impl( new Alpr(marshal_as<std::string>(country), marshal_as<std::string>(configFile), marshal_as<std::string>(runtimeDir)) )
|
||||
{
|
||||
this->m_config = gcnew AlprConfigNet(this->m_Impl->getConfig());
|
||||
}
|
||||
|
||||
// Deallocate the native object on a destructor
|
||||
~AlprNet(){
|
||||
delete m_Impl;
|
||||
~AlprNet() {
|
||||
if(this->m_Disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->!AlprNet();
|
||||
this->m_Disposed = true;
|
||||
}
|
||||
|
||||
property AlprConfigNet^ Configuration {
|
||||
AlprConfigNet^ get()
|
||||
{
|
||||
return this->m_config;
|
||||
}
|
||||
}
|
||||
|
||||
property int TopN {
|
||||
@@ -426,6 +1272,38 @@ namespace openalprnet {
|
||||
return gcnew AlprResultsNet(results);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recognize from a bitmap
|
||||
/// </summary>
|
||||
AlprResultsNet^ recognize(Bitmap^ bitmap, List<System::Drawing::Rectangle>^ regionsOfInterest)
|
||||
{
|
||||
cv::Mat frame = AlprHelper::BitmapToMat(bitmap);
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recognize from a bitmap
|
||||
/// </summary>
|
||||
AlprResultsNet^ recognize(Bitmap^ bitmap)
|
||||
{
|
||||
cv::Mat frame = AlprHelper::BitmapToMat(bitmap);
|
||||
std::vector<AlprRegionOfInterest> rois;
|
||||
AlprResults results = m_Impl->recognize(frame.data, frame.elemSize(), frame.cols, frame.rows, rois);
|
||||
return gcnew AlprResultsNet(results);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recognize from MemoryStream representing an encoded image (e.g., BMP, PNG, JPG, GIF etc).
|
||||
/// </summary>
|
||||
AlprResultsNet^ recognize(MemoryStream^ memoryStream)
|
||||
{
|
||||
std::vector<char> p = AlprHelper::MemoryStreamToVector(memoryStream);
|
||||
AlprResults results = m_Impl->recognize(p);
|
||||
return gcnew AlprResultsNet(results);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recognize from byte data representing an encoded image (e.g., BMP, PNG, JPG, GIF etc).
|
||||
/// </summary>
|
||||
@@ -459,12 +1337,15 @@ namespace openalprnet {
|
||||
// Deallocate the native object on the finalizer just in case no destructor is called
|
||||
!AlprNet() {
|
||||
delete m_Impl;
|
||||
delete m_config;
|
||||
}
|
||||
|
||||
private:
|
||||
Alpr * m_Impl;
|
||||
AlprConfigNet^ m_config;
|
||||
int m_topN;
|
||||
bool m_detectRegion;
|
||||
System::String^ m_defaultRegion;
|
||||
bool m_Disposed;
|
||||
};
|
||||
}
|
||||
|
@@ -23,7 +23,8 @@
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<Keyword>ManagedCProj</Keyword>
|
||||
<RootNamespace>openalprnet</RootNamespace>
|
||||
<OpenALPRVersion>2.0.1</OpenALPRVersion>
|
||||
<OpenALPRVersion>2.1.0</OpenALPRVersion>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<OpenALPRWindowsDir>..\..\..\..\windows</OpenALPRWindowsDir>
|
||||
<OpenALPRDistDir>$(OpenALPRWindowsDir)\build\dist\$(OpenALPRVersion)\$(PlatformToolset)\$(Configuration)\$(Platform)</OpenALPRDistDir>
|
||||
<OpenCVVersion>248</OpenCVVersion>
|
||||
@@ -93,7 +94,7 @@
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<AdditionalIncludeDirectories>$(OpenALPRWindowsDir)\tesseract-ocr\src\api;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccstruct;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccmain;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccutil;$(OpenALPRWindowsDir)\opencv;$(OpenALPRWindowsDir)\opencv\include;$(OpenALPRWindowsDir)\opencv\include\opencv;$(OpenALPRWindowsDir)\opencv\modules\core\include;$(OpenALPRWindowsDir)\opencv\modules\flann\include;$(OpenALPRWindowsDir)\opencv\modules\imgproc\include;$(OpenALPRWindowsDir)\opencv\modules\highgui\include;$(OpenALPRWindowsDir)\opencv\modules\features2d\include;$(OpenALPRWindowsDir)\opencv\modules\calib3d\include;$(OpenALPRWindowsDir)\opencv\modules\ml\include;$(OpenALPRWindowsDir)\opencv\modules\video\include;$(OpenALPRWindowsDir)\opencv\modules\legacy\include;$(OpenALPRWindowsDir)\opencv\modules\objdetect\include;$(OpenALPRWindowsDir)\opencv\modules\photo\include;$(OpenALPRWindowsDir)\opencv\modules\gpu\include;$(OpenALPRWindowsDir)\opencv\modules\ocl\include;$(OpenALPRWindowsDir)\opencv\modules\nonfree\include;$(OpenALPRWindowsDir)\opencv\modules\contrib\include;$(OpenALPRWindowsDir)\opencv\modules\stitching\include;$(OpenALPRWindowsDir)\opencv\modules\superres\include;$(OpenALPRWindowsDir)\opencv\modules\ts\include;$(OpenALPRWindowsDir)\opencv\modules\videostab\include;$(OpenALPRWindowsDir)\..\src\openalpr;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
@@ -106,7 +107,7 @@
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<AdditionalIncludeDirectories>$(OpenALPRWindowsDir)\tesseract-ocr\src\api;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccstruct;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccmain;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccutil;$(OpenALPRWindowsDir)\opencv;$(OpenALPRWindowsDir)\opencv\include;$(OpenALPRWindowsDir)\opencv\include\opencv;$(OpenALPRWindowsDir)\opencv\modules\core\include;$(OpenALPRWindowsDir)\opencv\modules\flann\include;$(OpenALPRWindowsDir)\opencv\modules\imgproc\include;$(OpenALPRWindowsDir)\opencv\modules\highgui\include;$(OpenALPRWindowsDir)\opencv\modules\features2d\include;$(OpenALPRWindowsDir)\opencv\modules\calib3d\include;$(OpenALPRWindowsDir)\opencv\modules\ml\include;$(OpenALPRWindowsDir)\opencv\modules\video\include;$(OpenALPRWindowsDir)\opencv\modules\legacy\include;$(OpenALPRWindowsDir)\opencv\modules\objdetect\include;$(OpenALPRWindowsDir)\opencv\modules\photo\include;$(OpenALPRWindowsDir)\opencv\modules\gpu\include;$(OpenALPRWindowsDir)\opencv\modules\ocl\include;$(OpenALPRWindowsDir)\opencv\modules\nonfree\include;$(OpenALPRWindowsDir)\opencv\modules\contrib\include;$(OpenALPRWindowsDir)\opencv\modules\stitching\include;$(OpenALPRWindowsDir)\opencv\modules\superres\include;$(OpenALPRWindowsDir)\opencv\modules\ts\include;$(OpenALPRWindowsDir)\opencv\modules\videostab\include;$(OpenALPRWindowsDir)\..\src\openalpr;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
@@ -118,7 +119,7 @@
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<AdditionalIncludeDirectories>$(OpenALPRWindowsDir)\tesseract-ocr\src\api;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccstruct;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccmain;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccutil;$(OpenALPRWindowsDir)\opencv;$(OpenALPRWindowsDir)\opencv\include;$(OpenALPRWindowsDir)\opencv\include\opencv;$(OpenALPRWindowsDir)\opencv\modules\core\include;$(OpenALPRWindowsDir)\opencv\modules\flann\include;$(OpenALPRWindowsDir)\opencv\modules\imgproc\include;$(OpenALPRWindowsDir)\opencv\modules\highgui\include;$(OpenALPRWindowsDir)\opencv\modules\features2d\include;$(OpenALPRWindowsDir)\opencv\modules\calib3d\include;$(OpenALPRWindowsDir)\opencv\modules\ml\include;$(OpenALPRWindowsDir)\opencv\modules\video\include;$(OpenALPRWindowsDir)\opencv\modules\legacy\include;$(OpenALPRWindowsDir)\opencv\modules\objdetect\include;$(OpenALPRWindowsDir)\opencv\modules\photo\include;$(OpenALPRWindowsDir)\opencv\modules\gpu\include;$(OpenALPRWindowsDir)\opencv\modules\ocl\include;$(OpenALPRWindowsDir)\opencv\modules\nonfree\include;$(OpenALPRWindowsDir)\opencv\modules\contrib\include;$(OpenALPRWindowsDir)\opencv\modules\stitching\include;$(OpenALPRWindowsDir)\opencv\modules\superres\include;$(OpenALPRWindowsDir)\opencv\modules\ts\include;$(OpenALPRWindowsDir)\opencv\modules\videostab\include;$(OpenALPRWindowsDir)\..\src\openalpr;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
@@ -130,7 +131,7 @@
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<AdditionalIncludeDirectories>$(OpenALPRWindowsDir)\tesseract-ocr\src\api;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccstruct;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccmain;$(OpenALPRWindowsDir)\tesseract-ocr\src\ccutil;$(OpenALPRWindowsDir)\opencv;$(OpenALPRWindowsDir)\opencv\include;$(OpenALPRWindowsDir)\opencv\include\opencv;$(OpenALPRWindowsDir)\opencv\modules\core\include;$(OpenALPRWindowsDir)\opencv\modules\flann\include;$(OpenALPRWindowsDir)\opencv\modules\imgproc\include;$(OpenALPRWindowsDir)\opencv\modules\highgui\include;$(OpenALPRWindowsDir)\opencv\modules\features2d\include;$(OpenALPRWindowsDir)\opencv\modules\calib3d\include;$(OpenALPRWindowsDir)\opencv\modules\ml\include;$(OpenALPRWindowsDir)\opencv\modules\video\include;$(OpenALPRWindowsDir)\opencv\modules\legacy\include;$(OpenALPRWindowsDir)\opencv\modules\objdetect\include;$(OpenALPRWindowsDir)\opencv\modules\photo\include;$(OpenALPRWindowsDir)\opencv\modules\gpu\include;$(OpenALPRWindowsDir)\opencv\modules\ocl\include;$(OpenALPRWindowsDir)\opencv\modules\nonfree\include;$(OpenALPRWindowsDir)\opencv\modules\contrib\include;$(OpenALPRWindowsDir)\opencv\modules\stitching\include;$(OpenALPRWindowsDir)\opencv\modules\superres\include;$(OpenALPRWindowsDir)\opencv\modules\ts\include;$(OpenALPRWindowsDir)\opencv\modules\videostab\include;$(OpenALPRWindowsDir)\..\src\openalpr;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
|
@@ -67,6 +67,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
@@ -108,5 +108,8 @@ namespace alpr
|
||||
return AlprImpl::getVersion();
|
||||
}
|
||||
|
||||
|
||||
Config* Alpr::getConfig()
|
||||
{
|
||||
return impl->config;
|
||||
}
|
||||
}
|
@@ -116,6 +116,7 @@ namespace alpr
|
||||
};
|
||||
|
||||
|
||||
class Config;
|
||||
class AlprImpl;
|
||||
class Alpr
|
||||
{
|
||||
@@ -145,6 +146,8 @@ namespace alpr
|
||||
|
||||
static std::string getVersion();
|
||||
|
||||
Config* getConfig();
|
||||
|
||||
private:
|
||||
AlprImpl* impl;
|
||||
};
|
||||
|
@@ -241,19 +241,19 @@ namespace alpr
|
||||
|
||||
}
|
||||
|
||||
void Config::debugOff()
|
||||
void Config::debugOff(bool value)
|
||||
{
|
||||
debugGeneral = false;
|
||||
debugTiming = false;
|
||||
debugStateId = false;
|
||||
debugPlateLines = false;
|
||||
debugPlateCorners = false;
|
||||
debugCharSegmenter = false;
|
||||
debugCharAnalysis = false;
|
||||
debugColorFiler = false;
|
||||
debugOcr = false;
|
||||
debugPostProcess = false;
|
||||
debugPauseOnFrame = false;
|
||||
debugGeneral = !value;
|
||||
debugTiming = !value;
|
||||
debugStateId = !value;
|
||||
debugPlateLines = !value;
|
||||
debugPlateCorners = !value;
|
||||
debugCharSegmenter = !value;
|
||||
debugCharAnalysis = !value;
|
||||
debugColorFiler = !value;
|
||||
debugOcr = !value;
|
||||
debugPostProcess = !value;
|
||||
debugPauseOnFrame = !value;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -119,7 +119,7 @@ namespace alpr
|
||||
bool debugShowImages;
|
||||
bool debugPauseOnFrame;
|
||||
|
||||
void debugOff();
|
||||
void debugOff(bool value);
|
||||
|
||||
std::string getKeypointsRuntimeDir();
|
||||
std::string getCascadeRuntimeDir();
|
||||
|
Reference in New Issue
Block a user