Merge pull request #158 from peters/master

.NET binding
This commit is contained in:
Matthew Hill
2015-07-10 17:14:18 -04:00
15 changed files with 1275 additions and 975 deletions

View File

@@ -31,9 +31,9 @@ using namespace System::Security::Permissions;
// You can specify all the value or you can default the Revision and Build Numbers // You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersionAttribute("2.0.1")] [assembly: AssemblyVersionAttribute("2.1.0")]
[assembly: AssemblyFileVersionAttribute("2.0.1")] [assembly: AssemblyFileVersionAttribute("2.1.0")]
[assembly: AssemblyInformationalVersionAttribute("2.0.1")] [assembly: AssemblyInformationalVersionAttribute("2.1.0")]
[assembly:ComVisible(false)]; [assembly:ComVisible(false)];

View File

@@ -0,0 +1,27 @@
#include "stdafx.h"
#include "bitmapmat-net.h"
using namespace openalprnet;
BitmapMat::BitmapMat(array<Byte>^ byteArray)
{
this->m_bitmap = ByteArrayToMat(byteArray);
}
BitmapMat::BitmapMat(Bitmap^ bitmap)
{
this->m_bitmap = BitmapToMat(bitmap);
}
BitmapMat::BitmapMat(MemoryStream^ memoryStream)
{
this->m_bitmap = MemoryStreamBitmapToMat(memoryStream);
}
BitmapMat::BitmapMat(String^ filename)
{
Bitmap^ bitmap = gcnew Bitmap(filename);
this->m_bitmap = BitmapToMat(bitmap);
delete bitmap;
}

View File

@@ -0,0 +1,106 @@
#pragma once
#include "opencv2/imgproc/imgproc.hpp"
using namespace System;
using namespace System::Drawing;
using namespace System::Drawing::Imaging;
using namespace System::IO;
namespace openalprnet {
private ref class BitmapMat : IDisposable
{
private:
cv::Mat* m_bitmap;
bool m_disposed;
public:
BitmapMat(array<Byte>^ byteArray);
BitmapMat(Bitmap^ bitmap);
BitmapMat(MemoryStream^ memoryStream);
BitmapMat(String^ filename);
~BitmapMat()
{
if (this->m_disposed)
{
return;
}
this->!BitmapMat();
this->m_disposed = true;
}
!BitmapMat()
{
delete[] m_bitmap->data;
}
property cv::Mat Value {
cv::Mat get()
{
cv::Mat value = this->m_bitmap->clone();
return value;
}
}
private:
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
);
const int totalBytes = bitmap->Height * bitmapData->Stride;
char *dst = new char[totalBytes];
::memcpy(dst, bitmapData->Scan0.ToPointer(), totalBytes);
cv::Mat* dstMat = new cv::Mat(cv::Size(bitmap->Width, bitmap->Height), CV_8UC(channels), dst);
bitmap->UnlockBits(bitmapData);
return dstMat;
}
static cv::Mat* MemoryStreamBitmapToMat(MemoryStream^ memoryStream)
{
Bitmap^ bitmap = gcnew Bitmap(memoryStream);
cv::Mat* mat = BitmapToMat(bitmap);
delete bitmap;
return mat;
}
static cv::Mat* ByteArrayToMat(array<Byte>^ byteArray)
{
MemoryStream^ ms = gcnew MemoryStream(byteArray);
cv::Mat* mat = MemoryStreamBitmapToMat(ms);
delete ms;
return mat;
}
};
}

View File

@@ -0,0 +1,666 @@
#pragma once
#include "config.h" // alpr
#include "types-net.h"
#include "helper-net.h"
using namespace System;
using namespace openalprnet::types;
namespace openalprnet
{
public ref class AlprConfigNet sealed
{
internal:
AlprConfigNet(Config* config) : m_config(config)
{
}
public:
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 int DetectionStrictness {
int get()
{
return this->m_config->detectionStrictness;
}
void set(int 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)
{
if(String::IsNullOrWhiteSpace(value))
{
this->m_config->prewarp = "";
return;
}
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)
{
if (String::IsNullOrWhiteSpace(value))
{
this->m_config->prewarp = "";
return;
}
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 SetDebug(bool value)
{
this->m_config->setDebug(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;
};
}

View File

@@ -0,0 +1,162 @@
#pragma once
#using <mscorlib.dll>
#include <msclr\marshal_cppstd.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include "alpr.h"
#include "opencv2/imgproc/imgproc.hpp"
#include <vector>
using namespace std;
using namespace alpr;
using namespace msclr::interop;
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Drawing;
using namespace System::Drawing::Imaging;
using namespace System::IO;
using namespace System::Collections::Generic;
namespace openalprnet
{
private ref class AlprHelper sealed
{
public:
static std::vector<char> ToVector(array<char>^ src)
{
std::vector<char> result(src->Length);
pin_ptr<char> pin(&src[0]);
char *first(pin), *last(pin + src->Length);
std::copy(first, last, result.begin());
return result;
}
static std::vector<char> ToVector(array<Byte>^ src)
{
std::vector<char> result(src->Length);
pin_ptr<Byte> pin(&src[0]);
char* pch = reinterpret_cast<char*>(pin);
char *first(pch), *last(pch + src->Length);
std::copy(first, last, result.begin());
return result;
}
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
);
char *src = reinterpret_cast<char*>(bitmapData->Scan0.ToPointer());
pin_ptr<char> 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<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;
for each(System::Drawing::Rectangle^ rect in src)
{
AlprRegionOfInterest roi(rect->X, rect->Y, rect->Width, rect->Height);
result.push_back(roi);
}
return result;
}
static unsigned char* ToCharPtr(array<unsigned char>^ src)
{
//unsigned char* result = (unsigned char*) new unsigned char[src->Length];
pin_ptr<unsigned char> pin(&src[0]);
unsigned char* pc = pin;
return pc;
}
static System::String^ ToManagedString(std::string s)
{
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<char*>(static_cast<void*>(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);
}
static List<System::Drawing::Rectangle>^ ToRectangleList(std::vector<cv::Rect> srcRects)
{
List<System::Drawing::Rectangle>^ rects = gcnew List<System::Drawing::Rectangle>();
for each(cv::Rect rect in srcRects)
{
rects->Add(ToRectangle(rect));
}
return rects;
}
};
};

View File

@@ -0,0 +1,18 @@
#pragma once
using namespace System::Threading;
namespace openalprnet
{
private ref class Lock {
Object^ m_pObject;
public:
Lock(Object ^ pObject) : m_pObject(pObject) {
Monitor::Enter(m_pObject);
}
~Lock() {
Monitor::Exit(m_pObject);
}
};
}

View File

@@ -0,0 +1,79 @@
#include "stdafx.h"
#include "motiondetector-net.h"
#include "lock-net.h"
#include "bitmapmat-net.h"
using namespace openalprnet;
void AlprMotionDetectionNet::ResetMotionDetection(Bitmap^ bitmap)
{
BitmapMat^ wrapper = gcnew BitmapMat(bitmap);
ResetMotionDetection(wrapper->Value);
delete wrapper;
}
void AlprMotionDetectionNet::ResetMotionDetection(String^ filename)
{
BitmapMat^ wrapper = gcnew BitmapMat(filename);
ResetMotionDetection(wrapper->Value);
delete wrapper;
}
void AlprMotionDetectionNet::ResetMotionDetection(MemoryStream^ memoryStream)
{
BitmapMat^ wrapper = gcnew BitmapMat(memoryStream);
ResetMotionDetection(wrapper->Value);
delete wrapper;
}
void AlprMotionDetectionNet::ResetMotionDetection(array<Byte>^ byteArray)
{
BitmapMat^ wrapper = gcnew BitmapMat(byteArray);
ResetMotionDetection(wrapper->Value);
delete wrapper;
}
System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(Bitmap^ bitmap)
{
BitmapMat^ wrapper = gcnew BitmapMat(bitmap);
System::Drawing::Rectangle motion = MotionDetect(wrapper->Value);
delete wrapper;
return motion;
}
System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(String^ filename)
{
BitmapMat^ wrapper = gcnew BitmapMat(filename);
System::Drawing::Rectangle motion = MotionDetect(wrapper->Value);
delete wrapper;
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;
}
System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(array<Byte>^ byteArray)
{
BitmapMat^ wrapper = gcnew BitmapMat(byteArray);
System::Drawing::Rectangle motion = MotionDetect(wrapper->Value);
delete wrapper;
return motion;
}
void AlprMotionDetectionNet::ResetMotionDetection(cv::Mat mat)
{
Lock lock(this);
this->m_motionDetector->ResetMotionDetection(&mat);
}
System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(cv::Mat mat)
{
Lock lock(this);
cv::Rect rect = this->m_motionDetector->MotionDetect(&mat);
return AlprHelper::ToRectangle(rect);
}

View File

@@ -0,0 +1,52 @@
#pragma once
#include "motiondetector.h" // alpr
#include "helper-net.h"
using namespace alpr;
namespace openalprnet
{
public ref class AlprMotionDetectionNet : IDisposable {
public:
AlprMotionDetectionNet() : m_motionDetector(new MotionDetector())
{
}
void AlprMotionDetectionNet::ResetMotionDetection(Bitmap^ bitmap);
void AlprMotionDetectionNet::ResetMotionDetection(String^ filename);
void AlprMotionDetectionNet::ResetMotionDetection(MemoryStream^ memoryStream);
void AlprMotionDetectionNet::ResetMotionDetection(array<Byte>^ byteArray);
System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(Bitmap^ bitmap);
System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(String^ filename);
System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(MemoryStream^ memoryStream);
System::Drawing::Rectangle AlprMotionDetectionNet::MotionDetect(array<Byte>^ byteArray);
private:
~AlprMotionDetectionNet()
{
if (this->m_disposed)
{
return;
}
this->!AlprMotionDetectionNet();
this->m_disposed = true;
}
!AlprMotionDetectionNet()
{
delete m_motionDetector;
}
private:
void ResetMotionDetection(cv::Mat mat);
System::Drawing::Rectangle MotionDetect(cv::Mat mat);
private:
MotionDetector* m_motionDetector;
bool m_disposed;
};
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,21 @@
// openalpr-net.h
#pragma once #pragma once
//using namespace System; #include "alpr.h"
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#using <mscorlib.dll>
#include <msclr\marshal_cppstd.h>
#include "helper-net.h"
#include "bitmapmat-net.h"
#include "motiondetector-net.h"
#include "config-net.h"
namespace openalprnet { namespace openalprnet {

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
@@ -34,9 +34,11 @@
<TesseractVersion>303</TesseractVersion> <TesseractVersion>303</TesseractVersion>
<LeptonicaVersion>170</LeptonicaVersion> <LeptonicaVersion>170</LeptonicaVersion>
<DebugPrefix Condition="'$(Configuration)'=='Debug'">d</DebugPrefix> <DebugPrefix Condition="'$(Configuration)'=='Debug'">d</DebugPrefix>
<DebugPrefix Condition="'$(Configuration)'!='Debug'"></DebugPrefix> <DebugPrefix Condition="'$(Configuration)'!='Debug'">
</DebugPrefix>
<TesseractDebugPrefix Condition="'$(Configuration)'=='Debug'">-debug</TesseractDebugPrefix> <TesseractDebugPrefix Condition="'$(Configuration)'=='Debug'">-debug</TesseractDebugPrefix>
<TesseractDebugPrefix Condition="'$(Configuration)'!='Debug'"></TesseractDebugPrefix> <TesseractDebugPrefix Condition="'$(Configuration)'!='Debug'">
</TesseractDebugPrefix>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -150,12 +152,20 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="bitmapmat-net.h" />
<ClInclude Include="config-net.h" />
<ClInclude Include="helper-net.h" />
<ClInclude Include="lock-net.h" />
<ClInclude Include="motiondetector-net.h" />
<ClInclude Include="openalpr-net.h" /> <ClInclude Include="openalpr-net.h" />
<ClInclude Include="types-net.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="Stdafx.h" /> <ClInclude Include="Stdafx.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="AssemblyInfo.cpp" /> <ClCompile Include="AssemblyInfo.cpp" />
<ClCompile Include="bitmapmat-net.cpp" />
<ClCompile Include="motiondetector-net.cpp" />
<ClCompile Include="openalpr-net.cpp" /> <ClCompile Include="openalpr-net.cpp" />
<ClCompile Include="Stdafx.cpp"> <ClCompile Include="Stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

View File

@@ -24,6 +24,24 @@
<ClInclude Include="resource.h"> <ClInclude Include="resource.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="bitmapmat-net.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="helper-net.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="motiondetectornet-net.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="config-net.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="types-net.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="lock-net.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="openalpr-net.cpp"> <ClCompile Include="openalpr-net.cpp">
@@ -35,6 +53,12 @@
<ClCompile Include="Stdafx.cpp"> <ClCompile Include="Stdafx.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="bitmapmat-net.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="motiondetector-net.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.ico"> <None Include="app.ico">

View File

@@ -0,0 +1,18 @@
#pragma once
#include "alpr.h" // alpr
#include "config.h" // alpr
using namespace alpr;
namespace openalprnet
{
namespace types
{
public enum class AlprDetectorTypeNet : int {
DetectorLbpCpu = alpr::DETECTOR_LBP_CPU,
DetectorLbpGpu = alpr::DETECTOR_LBP_GPU,
DetectorLbpMorphCpu = alpr::DETECTOR_MORPH_CPU
};
}
}

View File

@@ -66,11 +66,11 @@ namespace openalprnet_cli
val => { if (val.Any()) filename = val.First().Trim(); }) val => { if (val.Any()) filename = val.First().Trim(); })
); );
Console.WriteLine("OpenAlpr Version: {0}", AlprNet.getVersion()); Console.WriteLine("OpenAlpr Version: {0}", AlprNet.GetVersion());
var config = Path.Combine(AssemblyDirectory, "openalpr.conf"); var config = Path.Combine(AssemblyDirectory, "openalpr.conf");
var runtime_data = Path.Combine(AssemblyDirectory, "runtime_data"); var runtime_data = Path.Combine(AssemblyDirectory, "runtime_data");
var alpr = new AlprNet(region, config, runtime_data); var alpr = new AlprNet(region, config, runtime_data);
if (!alpr.isLoaded()) if (!alpr.IsLoaded())
{ {
Console.WriteLine("OpenAlpr failed to load!"); Console.WriteLine("OpenAlpr failed to load!");
return; return;
@@ -110,8 +110,7 @@ namespace openalprnet_cli
private static void PerformAlpr(AlprNet alpr, byte[] buffer, bool benchmark, bool writeJson) private static void PerformAlpr(AlprNet alpr, byte[] buffer, bool benchmark, bool writeJson)
{ {
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
sbyte[] signedBuffer = (sbyte[])(Array)buffer; var results = alpr.Recognize(buffer);
var results = alpr.recognize(signedBuffer);
sw.Stop(); sw.Stop();
if (benchmark) if (benchmark)
{ {
@@ -125,14 +124,14 @@ namespace openalprnet_cli
else else
{ {
var i = 0; var i = 0;
foreach (var result in results.plates) foreach (var result in results.Plates)
{ {
Console.WriteLine("Plate {0}: {1} result(s)", i++, result.topNPlates.Count); Console.WriteLine("Plate {0}: {1} result(s)", i++, result.TopNPlates.Count);
Console.WriteLine(" Processing Time: {0} msec(s)", result.processing_time_ms); Console.WriteLine(" Processing Time: {0} msec(s)", result.ProcessingTimeMs);
foreach (var plate in result.topNPlates) foreach (var plate in result.TopNPlates)
{ {
Console.WriteLine(" - {0}\t Confidence: {1}\tMatches Template: {2}", plate.characters, Console.WriteLine(" - {0}\t Confidence: {1}\tMatches Template: {2}", plate.Characters,
plate.overall_confidence, plate.matches_template); plate.OverallConfidence, plate.MatchesTemplate);
} }
} }
} }

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2015 OpenALPR Technology, Inc. * Copyright (c) 2015 OpenALPR Technology, Inc.
* *
* This file is part of OpenALPR. * This file is part of OpenALPR.
@@ -22,6 +22,7 @@ using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using openalprnet; using openalprnet;
@@ -135,7 +136,7 @@ namespace openalprnet_windemo
String runtime_data_dir = Path.Combine(AssemblyDirectory, "runtime_data"); String runtime_data_dir = Path.Combine(AssemblyDirectory, "runtime_data");
using (var alpr = new AlprNet(region, config_file, runtime_data_dir)) using (var alpr = new AlprNet(region, config_file, runtime_data_dir))
{ {
if (!alpr.isLoaded()) if (!alpr.IsLoaded())
{ {
lbxPlates.Items.Add("Error initializing OpenALPR"); lbxPlates.Items.Add("Error initializing OpenALPR");
return; return;
@@ -143,24 +144,24 @@ namespace openalprnet_windemo
picOriginal.ImageLocation = fileName; picOriginal.ImageLocation = fileName;
picOriginal.Load(); picOriginal.Load();
var results = alpr.recognize(fileName); var results = alpr.Recognize(fileName);
var images = new List<Image>(results.plates.Count()); var images = new List<Image>(results.Plates.Count());
var i = 1; var i = 1;
foreach (var result in results.plates) foreach (var result in results.Plates)
{ {
var rect = boundingRectangle(result.plate_points); var rect = boundingRectangle(result.PlatePoints);
var img = Image.FromFile(fileName); var img = Image.FromFile(fileName);
var cropped = cropImage(img, rect); var cropped = cropImage(img, rect);
images.Add(cropped); images.Add(cropped);
lbxPlates.Items.Add("\t\t-- Plate #" + i++ + " --"); lbxPlates.Items.Add("\t\t-- Plate #" + i++ + " --");
foreach (var plate in result.topNPlates) foreach (var plate in result.TopNPlates)
{ {
lbxPlates.Items.Add(string.Format(@"{0} {1}% {2}", lbxPlates.Items.Add(string.Format(@"{0} {1}% {2}",
plate.characters.PadRight(12), plate.Characters.PadRight(12),
plate.overall_confidence.ToString("N1").PadLeft(8), plate.OverallConfidence.ToString("N1").PadLeft(8),
plate.matches_template.ToString().PadLeft(8))); plate.MatchesTemplate.ToString().PadLeft(8)));
} }
} }