mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-05 07:27:24 +08:00
Replaced .NET binding with a simpler version
This commit is contained in:
132
src/bindings/csharp/AlprNetGuiTest/AlprNetGuiTest.csproj
Normal file
132
src/bindings/csharp/AlprNetGuiTest/AlprNetGuiTest.csproj
Normal file
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{C7863A14-55D2-4389-9072-04AA6E30AAD1}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>AlprNetGuiTest</RootNamespace>
|
||||
<AssemblyName>AlprNetGuiTest</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<CodeAnalysisLogFile>bin\Debug\openalprnet-windemo.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<CodeAnalysisLogFile>bin\Release\openalprnet-windemo.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>appicon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<None Include="app.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="appicon.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\alprnet\AlprNet.csproj">
|
||||
<Project>{f6106c0e-0e89-4d2e-89e6-19742d54b9f6}</Project>
|
||||
<Name>AlprNet</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
192
src/bindings/csharp/AlprNetGuiTest/Form1.Designer.cs
generated
Normal file
192
src/bindings/csharp/AlprNetGuiTest/Form1.Designer.cs
generated
Normal file
@@ -0,0 +1,192 @@
|
||||
namespace AlprNetGuiTest
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.btnDetect = new System.Windows.Forms.Button();
|
||||
this.picLicensePlate = new System.Windows.Forms.PictureBox();
|
||||
this.picOriginal = new System.Windows.Forms.PictureBox();
|
||||
this.lbxPlates = new System.Windows.Forms.ListBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.rbUSA = new System.Windows.Forms.RadioButton();
|
||||
this.rbEU = new System.Windows.Forms.RadioButton();
|
||||
((System.ComponentModel.ISupportInitialize)(this.picLicensePlate)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.picOriginal)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnDetect
|
||||
//
|
||||
this.btnDetect.Location = new System.Drawing.Point(830, 25);
|
||||
this.btnDetect.Name = "btnDetect";
|
||||
this.btnDetect.Size = new System.Drawing.Size(291, 37);
|
||||
this.btnDetect.TabIndex = 0;
|
||||
this.btnDetect.Text = "Detect License Plate";
|
||||
this.btnDetect.UseVisualStyleBackColor = true;
|
||||
this.btnDetect.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// picLicensePlate
|
||||
//
|
||||
this.picLicensePlate.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.picLicensePlate.Location = new System.Drawing.Point(827, 403);
|
||||
this.picLicensePlate.Name = "picLicensePlate";
|
||||
this.picLicensePlate.Size = new System.Drawing.Size(294, 123);
|
||||
this.picLicensePlate.TabIndex = 1;
|
||||
this.picLicensePlate.TabStop = false;
|
||||
//
|
||||
// picOriginal
|
||||
//
|
||||
this.picOriginal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.picOriginal.Location = new System.Drawing.Point(12, 25);
|
||||
this.picOriginal.Name = "picOriginal";
|
||||
this.picOriginal.Size = new System.Drawing.Size(809, 501);
|
||||
this.picOriginal.TabIndex = 2;
|
||||
this.picOriginal.TabStop = false;
|
||||
//
|
||||
// lbxPlates
|
||||
//
|
||||
this.lbxPlates.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.lbxPlates.FormattingEnabled = true;
|
||||
this.lbxPlates.Location = new System.Drawing.Point(827, 81);
|
||||
this.lbxPlates.Name = "lbxPlates";
|
||||
this.lbxPlates.Size = new System.Drawing.Size(294, 303);
|
||||
this.lbxPlates.TabIndex = 3;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(12, 9);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(76, 13);
|
||||
this.label1.TabIndex = 4;
|
||||
this.label1.Text = "Source Image:";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(827, 387);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(96, 13);
|
||||
this.label2.TabIndex = 5;
|
||||
this.label2.Text = "License Plate ROI:";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(827, 65);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(124, 13);
|
||||
this.label3.TabIndex = 6;
|
||||
this.label3.Text = "Matched License Plates:";
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
this.openFileDialog.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif;" +
|
||||
" *.png|All files (*.*)|*.*";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(827, 9);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(44, 13);
|
||||
this.label4.TabIndex = 7;
|
||||
this.label4.Text = "Region:";
|
||||
//
|
||||
// rbUSA
|
||||
//
|
||||
this.rbUSA.AutoSize = true;
|
||||
this.rbUSA.Checked = true;
|
||||
this.rbUSA.Location = new System.Drawing.Point(878, 7);
|
||||
this.rbUSA.Name = "rbUSA";
|
||||
this.rbUSA.Size = new System.Drawing.Size(40, 17);
|
||||
this.rbUSA.TabIndex = 8;
|
||||
this.rbUSA.TabStop = true;
|
||||
this.rbUSA.Text = "US";
|
||||
this.rbUSA.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// rbEU
|
||||
//
|
||||
this.rbEU.AutoSize = true;
|
||||
this.rbEU.Location = new System.Drawing.Point(924, 7);
|
||||
this.rbEU.Name = "rbEU";
|
||||
this.rbEU.Size = new System.Drawing.Size(40, 17);
|
||||
this.rbEU.TabIndex = 9;
|
||||
this.rbEU.Text = "EU";
|
||||
this.rbEU.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.White;
|
||||
this.ClientSize = new System.Drawing.Size(1128, 538);
|
||||
this.Controls.Add(this.rbEU);
|
||||
this.Controls.Add(this.rbUSA);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.lbxPlates);
|
||||
this.Controls.Add(this.picOriginal);
|
||||
this.Controls.Add(this.picLicensePlate);
|
||||
this.Controls.Add(this.btnDetect);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "Form1";
|
||||
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "OpenALPR-Net Demo";
|
||||
this.Load += new System.EventHandler(this.Form1_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.picLicensePlate)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.picOriginal)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button btnDetect;
|
||||
private System.Windows.Forms.PictureBox picLicensePlate;
|
||||
private System.Windows.Forms.PictureBox picOriginal;
|
||||
private System.Windows.Forms.ListBox lbxPlates;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.OpenFileDialog openFileDialog;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.RadioButton rbUSA;
|
||||
private System.Windows.Forms.RadioButton rbEU;
|
||||
}
|
||||
}
|
||||
|
193
src/bindings/csharp/AlprNetGuiTest/Form1.cs
Normal file
193
src/bindings/csharp/AlprNetGuiTest/Form1.cs
Normal file
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2015 OpenALPR Technology, Inc.
|
||||
*
|
||||
* This file is part of OpenALPR.
|
||||
*
|
||||
* OpenALPR is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License
|
||||
* version 3 as published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using AlprNet;
|
||||
using AlprNet.Models;
|
||||
|
||||
namespace AlprNetGuiTest
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public static string AssemblyDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
var codeBase = Assembly.GetExecutingAssembly().CodeBase;
|
||||
var uri = new UriBuilder(codeBase);
|
||||
var path = Uri.UnescapeDataString(uri.Path);
|
||||
return Path.GetDirectoryName(path);
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle boundingRectangle(List<Point> points)
|
||||
{
|
||||
// Add checks here, if necessary, to make sure that points is not null,
|
||||
// and that it contains at least one (or perhaps two?) elements
|
||||
|
||||
var minX = points.Min(p => p.X);
|
||||
var minY = points.Min(p => p.Y);
|
||||
var maxX = points.Max(p => p.X);
|
||||
var maxY = points.Max(p => p.Y);
|
||||
|
||||
return new Rectangle(new Point(minX, minY), new Size(maxX - minX, maxY - minY));
|
||||
}
|
||||
|
||||
private static Image cropImage(Image img, Rectangle cropArea)
|
||||
{
|
||||
var bmpImage = new Bitmap(img);
|
||||
return bmpImage.Clone(cropArea, bmpImage.PixelFormat);
|
||||
}
|
||||
|
||||
public static Bitmap combineImages(List<Image> images)
|
||||
{
|
||||
//read all images into memory
|
||||
Bitmap finalImage = null;
|
||||
|
||||
try
|
||||
{
|
||||
var width = 0;
|
||||
var height = 0;
|
||||
|
||||
foreach (var bmp in images)
|
||||
{
|
||||
width += bmp.Width;
|
||||
height = bmp.Height > height ? bmp.Height : height;
|
||||
}
|
||||
|
||||
//create a bitmap to hold the combined image
|
||||
finalImage = new Bitmap(width, height);
|
||||
|
||||
//get a graphics object from the image so we can draw on it
|
||||
using (var g = Graphics.FromImage(finalImage))
|
||||
{
|
||||
//set background color
|
||||
g.Clear(Color.Black);
|
||||
|
||||
//go through each image and draw it on the final image
|
||||
var offset = 0;
|
||||
foreach (Bitmap image in images)
|
||||
{
|
||||
g.DrawImage(image,
|
||||
new Rectangle(offset, 0, image.Width, image.Height));
|
||||
offset += image.Width;
|
||||
}
|
||||
}
|
||||
|
||||
return finalImage;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (finalImage != null)
|
||||
finalImage.Dispose();
|
||||
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
//clean up memory
|
||||
foreach (var image in images)
|
||||
{
|
||||
image.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
processImageFile(openFileDialog.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void processImageFile(string fileName)
|
||||
{
|
||||
resetControls();
|
||||
var region = rbUSA.Checked ? "us" : "eu";
|
||||
String config_file = Path.Combine(AssemblyDirectory, "openalpr.conf");
|
||||
String runtime_data_dir = Path.Combine(AssemblyDirectory, "runtime_data");
|
||||
using (var alpr = new Alpr(region, config_file, runtime_data_dir))
|
||||
{
|
||||
alpr.Initialize();
|
||||
|
||||
if (!alpr.IsLoaded())
|
||||
{
|
||||
lbxPlates.Items.Add("Error initializing OpenALPR");
|
||||
return;
|
||||
}
|
||||
picOriginal.ImageLocation = fileName;
|
||||
picOriginal.Load();
|
||||
|
||||
var results = alpr.Recognize(fileName);
|
||||
|
||||
var images = new List<Image>(results.results.Count());
|
||||
var i = 1;
|
||||
foreach (var result in results.results)
|
||||
{
|
||||
List<Point> points = new List<Point>();
|
||||
foreach (Coordinate c in result.coordinates)
|
||||
points.Add(new Point(c.x, c.y));
|
||||
|
||||
var rect = boundingRectangle(points);
|
||||
var img = Image.FromFile(fileName);
|
||||
var cropped = cropImage(img, rect);
|
||||
images.Add(cropped);
|
||||
|
||||
lbxPlates.Items.Add("\t\t-- Plate #" + i++ + " --");
|
||||
foreach (var plate in result.candidates)
|
||||
{
|
||||
lbxPlates.Items.Add(string.Format(@"{0} {1}% {2}",
|
||||
plate.plate.PadRight(12),
|
||||
plate.confidence.ToString("N1").PadLeft(8),
|
||||
plate.matches_template.ToString().PadLeft(8)));
|
||||
}
|
||||
}
|
||||
|
||||
if (images.Any())
|
||||
{
|
||||
picLicensePlate.Image = combineImages(images);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resetControls()
|
||||
{
|
||||
picOriginal.Image = null;
|
||||
picLicensePlate.Image = null;
|
||||
lbxPlates.Items.Clear();
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
resetControls();
|
||||
}
|
||||
}
|
||||
}
|
123
src/bindings/csharp/AlprNetGuiTest/Form1.resx
Normal file
123
src/bindings/csharp/AlprNetGuiTest/Form1.resx
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
39
src/bindings/csharp/AlprNetGuiTest/Program.cs
Normal file
39
src/bindings/csharp/AlprNetGuiTest/Program.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2015 OpenALPR Technology, Inc.
|
||||
*
|
||||
* This file is part of OpenALPR.
|
||||
*
|
||||
* OpenALPR is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License
|
||||
* version 3 as published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AlprNetGuiTest
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("openalprnet-windemo")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("openalprnet-windemo")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("b1ab96ca-afe9-497d-9aa0-74ace195dfca")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
63
src/bindings/csharp/AlprNetGuiTest/Properties/Resources.Designer.cs
generated
Normal file
63
src/bindings/csharp/AlprNetGuiTest/Properties/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace AlprNetGuiTest.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AlprNetGuiTest.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
117
src/bindings/csharp/AlprNetGuiTest/Properties/Resources.resx
Normal file
117
src/bindings/csharp/AlprNetGuiTest/Properties/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
26
src/bindings/csharp/AlprNetGuiTest/Properties/Settings.Designer.cs
generated
Normal file
26
src/bindings/csharp/AlprNetGuiTest/Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace AlprNetGuiTest.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
3
src/bindings/csharp/AlprNetGuiTest/app.config
Normal file
3
src/bindings/csharp/AlprNetGuiTest/app.config
Normal file
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup></configuration>
|
BIN
src/bindings/csharp/AlprNetGuiTest/appicon.ico
Normal file
BIN
src/bindings/csharp/AlprNetGuiTest/appicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
src/bindings/csharp/AlprNetGuiTest/appicon.png
Normal file
BIN
src/bindings/csharp/AlprNetGuiTest/appicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 285 B |
83
src/bindings/csharp/AlprNetTest/AlprNetTest.csproj
Normal file
83
src/bindings/csharp/AlprNetTest/AlprNetTest.csproj
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>AlprNetTest</RootNamespace>
|
||||
<AssemblyName>AlprNetTest</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\alprnet\AlprNet.csproj">
|
||||
<Project>{f6106c0e-0e89-4d2e-89e6-19742d54b9f6}</Project>
|
||||
<Name>AlprNet</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
6
src/bindings/csharp/AlprNetTest/App.config
Normal file
6
src/bindings/csharp/AlprNetTest/App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
|
||||
<supportedRuntime version="v2.0.50727"/></startup>
|
||||
</configuration>
|
49
src/bindings/csharp/AlprNetTest/Program.cs
Normal file
49
src/bindings/csharp/AlprNetTest/Program.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
|
||||
|
||||
namespace AlprNetTest
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
// Create the object
|
||||
AlprNet.Alpr alpr = new AlprNet.Alpr("us");
|
||||
|
||||
// Initialize the OpenALPR runtime data. This must be called only once, and may take a few seconds to initialize
|
||||
bool success = alpr.Initialize();
|
||||
|
||||
if (!success || !alpr.IsLoaded())
|
||||
{
|
||||
Console.WriteLine("OpenALPR was not properly initialized. Exiting");
|
||||
alpr.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
alpr.setTopN(10);
|
||||
|
||||
AlprNet.Models.AlprResponse response = alpr.Recognize(@"c:\projects\openalpr-commercial\image.jpg");
|
||||
|
||||
Console.WriteLine("Analyzed an image that is {0}x{1} pixels", response.img_width, response.img_height);
|
||||
Console.WriteLine("Detected {0} plates", response.results.Count);
|
||||
|
||||
foreach (AlprNet.Models.AlprResult result in response.results)
|
||||
{
|
||||
Console.WriteLine(" - {0} ({1}%)", result.plate, result.confidence);
|
||||
|
||||
Console.WriteLine(" Top N candidates:");
|
||||
foreach (AlprNet.Models.Candidate candidate in result.candidates)
|
||||
{
|
||||
Console.WriteLine(" - {0} ({1}%)", candidate.plate, candidate.confidence);
|
||||
}
|
||||
}
|
||||
|
||||
// Free the OpenALPR instance's memory.
|
||||
alpr.Dispose();
|
||||
|
||||
Console.WriteLine("\nPress any key to continue...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
36
src/bindings/csharp/AlprNetTest/Properties/AssemblyInfo.cs
Normal file
36
src/bindings/csharp/AlprNetTest/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("AlprNetTest")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("AlprNetTest")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("ba97fa53-9f76-42fd-90a4-e3bdba3b66c3")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
342
src/bindings/csharp/alprnet/Alpr.cs
Normal file
342
src/bindings/csharp/alprnet/Alpr.cs
Normal file
@@ -0,0 +1,342 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using AlprNet.Models;
|
||||
|
||||
namespace AlprNet
|
||||
{
|
||||
public class Alpr : IDisposable
|
||||
{
|
||||
private const int REALLY_BIG_PIXEL_WIDTH = 999999999;
|
||||
private bool is_initialized = false;
|
||||
private string country;
|
||||
private string config_file;
|
||||
private string runtime_dir;
|
||||
private IntPtr native_instance;
|
||||
|
||||
/// <summary>
|
||||
/// OpenALPR library constructor. The object must be initialized separately with a call to Initialize()
|
||||
/// </summary>
|
||||
/// <param name="country">Country used for recognition. It may be a single country (e.g., "us") or a comma separated list</param>
|
||||
/// <param name="config_file">The path to the openalpr.conf file. Leave it blank to use the file in the current directory.</param>
|
||||
/// <param name="runtime_dir">The path to the runtime_data directory. Leave it blank to use the runtime_data in the current directory</param>
|
||||
public Alpr(string country, string config_file = "", string runtime_dir = "")
|
||||
{
|
||||
this.country = country;
|
||||
this.config_file = config_file;
|
||||
this.runtime_dir = runtime_dir;
|
||||
}
|
||||
|
||||
~Alpr()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release the memory associated with OpenALPR when you are done using it
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
|
||||
// Deinitialize the library
|
||||
if (this.is_initialized)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Destroy the native obj
|
||||
openalpr_cleanup(native_instance);
|
||||
}
|
||||
catch (System.DllNotFoundException)
|
||||
{
|
||||
// Ignore. The library couldn't possibly be loaded anyway
|
||||
}
|
||||
}
|
||||
this.is_initialized = false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Load the OpenALPR recognition data into memory.
|
||||
/// Initialization may take several seconds to load all of the various LP recognition data into memory
|
||||
/// </summary>
|
||||
/// <returns>True if successful, false otherwise</returns>
|
||||
public bool Initialize()
|
||||
{
|
||||
// Initialize the library
|
||||
|
||||
if (is_initialized)
|
||||
{
|
||||
// Idempotent behavior
|
||||
return true;
|
||||
}
|
||||
|
||||
this.is_initialized = true;
|
||||
|
||||
try
|
||||
{
|
||||
native_instance = openalpr_init(country, config_file, runtime_dir);
|
||||
}
|
||||
catch (System.DllNotFoundException)
|
||||
{
|
||||
Console.WriteLine("Could not find/load native library (libopenalprc.dll)");
|
||||
return false;
|
||||
}
|
||||
|
||||
return IsLoaded();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the OpenALPR library has been initialized
|
||||
/// </summary>
|
||||
/// <returns>true if the library is ready to use, false if it has not been initialized to read plates</returns>
|
||||
public bool IsLoaded()
|
||||
{
|
||||
if (!this.is_initialized)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
return openalpr_is_loaded(this.native_instance) != 0;
|
||||
}
|
||||
catch (System.DllNotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Checks if the instance can receive commands (e.g., is initialized)
|
||||
// If not, it throws an exception
|
||||
private void check_initialization()
|
||||
{
|
||||
if (!IsLoaded())
|
||||
throw new InvalidOperationException("OpenALPR Library cannot execute this request since it has not been initialized.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recognizes an encoded image (e.g., JPG, PNG, etc) from a file on disk
|
||||
/// </summary>
|
||||
/// <param name="filepath">The path to the image file</param>
|
||||
/// <returns>An AlprResponse object that contains the results of the recognition</returns>
|
||||
/// <exception cref="InvalidOperationException">Thrown when the library has not been initialized</exception>
|
||||
public AlprResponse Recognize(string filepath)
|
||||
{
|
||||
return Recognize(System.IO.File.ReadAllBytes(filepath));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recognizes an encoded image (e.g., JPG, PNG, etc) provided as an array of bytes
|
||||
/// </summary>
|
||||
/// <param name="image_bytes">The raw bytes that compose the image</param>
|
||||
/// <returns>An AlprResponse object that contains the results of the recognition</returns>
|
||||
/// <exception cref="InvalidOperationException">Thrown when the library has not been initialized</exception>
|
||||
public AlprResponse Recognize(byte[] image_bytes)
|
||||
{
|
||||
check_initialization();
|
||||
|
||||
NativeROI roi;
|
||||
roi.x = 0;
|
||||
roi.y = 0;
|
||||
roi.width = REALLY_BIG_PIXEL_WIDTH;
|
||||
roi.height = REALLY_BIG_PIXEL_WIDTH;
|
||||
|
||||
IntPtr unmanagedArray = Marshal.AllocHGlobal(image_bytes.Length);
|
||||
Marshal.Copy(image_bytes, 0, unmanagedArray, image_bytes.Length);
|
||||
|
||||
IntPtr resp_ptr = openalpr_recognize_encodedimage(this.native_instance, unmanagedArray, image_bytes.Length, roi);
|
||||
|
||||
Marshal.FreeHGlobal(unmanagedArray);
|
||||
|
||||
// Commented out test JSON string
|
||||
//string json = @"{""version"":2,""data_type"":""alpr_results"",""epoch_time"":1476716853320,""img_width"":600,""img_height"":600,""processing_time_ms"":116.557533,""regions_of_interest"":[{""x"":0,""y"":0,""width"":600,""height"":600}],""results"":[{""plate"":""627WWI"",""confidence"":94.338623,""matches_template"":1,""plate_index"":0,""region"":""wa"",""region_confidence"":82,""processing_time_ms"":50.445648,""requested_topn"":10,""coordinates"":[{""x"":242,""y"":360},{""x"":358,""y"":362},{""x"":359,""y"":412},{""x"":241,""y"":408}],""candidates"":[{""plate"":""627WWI"",""confidence"":94.338623,""matches_template"":1},{""plate"":""627WKI"",""confidence"":80.588486,""matches_template"":1},{""plate"":""627WI"",""confidence"":79.943542,""matches_template"":0},{""plate"":""627WVI"",""confidence"":79.348930,""matches_template"":1},{""plate"":""627WRI"",""confidence"":79.196785,""matches_template"":1},{""plate"":""627WNI"",""confidence"":79.165802,""matches_template"":1}]}]}";
|
||||
|
||||
string json = Marshal.PtrToStringAnsi(resp_ptr);
|
||||
AlprResponse response = JsonConvert.DeserializeObject<AlprResponse>(json);
|
||||
openalpr_free_response_string(resp_ptr);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recognizes an image from a .NET Bitmap object
|
||||
/// </summary>
|
||||
/// <param name="bitmap">The .NET Bitmap object to recognize</param>
|
||||
/// <returns>An AlprResponse object that contains the results of the recognition</returns>
|
||||
/// <exception cref="InvalidOperationException">Thrown when the library has not been initialized</exception>
|
||||
public AlprResponse Recognize(System.Drawing.Image image)
|
||||
{
|
||||
check_initialization();
|
||||
|
||||
System.Drawing.Bitmap clone = new System.Drawing.Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
|
||||
using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(clone))
|
||||
{
|
||||
gr.DrawImage(image, new System.Drawing.Rectangle(0, 0, clone.Width, clone.Height));
|
||||
}
|
||||
|
||||
System.Drawing.Imaging.BitmapData locked_bmp = clone.LockBits(new System.Drawing.Rectangle(0, 0, clone.Width, clone.Height),
|
||||
System.Drawing.Imaging.ImageLockMode.ReadWrite, clone.PixelFormat);
|
||||
byte[] raw_bytes = new byte[locked_bmp.Stride * locked_bmp.Height];
|
||||
System.Runtime.InteropServices.Marshal.Copy(locked_bmp.Scan0, raw_bytes, 0, raw_bytes.Length);
|
||||
clone.UnlockBits(locked_bmp);
|
||||
|
||||
int bytes_per_pixel = System.Drawing.Image.GetPixelFormatSize(clone.PixelFormat) / 8;
|
||||
|
||||
NativeROI roi;
|
||||
roi.x = 0;
|
||||
roi.y = 0;
|
||||
roi.width = image.Width;
|
||||
roi.height = image.Height;
|
||||
|
||||
IntPtr unmanagedArray = Marshal.AllocHGlobal(raw_bytes.Length);
|
||||
Marshal.Copy(raw_bytes, 0, unmanagedArray, raw_bytes.Length);
|
||||
|
||||
IntPtr resp_ptr = openalpr_recognize_rawimage(this.native_instance, unmanagedArray, bytes_per_pixel, image.Width, image.Height, roi);
|
||||
|
||||
Marshal.FreeHGlobal(unmanagedArray);
|
||||
|
||||
string json = Marshal.PtrToStringAnsi(resp_ptr);
|
||||
|
||||
AlprResponse response = JsonConvert.DeserializeObject<AlprResponse>(json);
|
||||
|
||||
openalpr_free_response_string(resp_ptr);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change the country used for analyzing plate data. This will load the new training data automatically
|
||||
/// </summary>
|
||||
/// <param name="country">Country used for Recognition (e.g., "us", "eu", "au", etc). Multiple values may be provided as comma-separated</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown when the library has not been initialized</exception>
|
||||
public void SetCountry(string country)
|
||||
{
|
||||
check_initialization();
|
||||
|
||||
openalpr_set_country(this.native_instance, country);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a new prewarp configuration to this instance
|
||||
/// </summary>
|
||||
/// <param name="prewarp">A prewarp configuration string generated from the OpenALPR calibration utility</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown when the library has not been initialized</exception>
|
||||
public void SetPrewarp(string prewarp)
|
||||
{
|
||||
openalpr_set_prewarp(this.native_instance, prewarp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the detection mask used by OpenALPR. Areas within the mask will be scanned for plates, areas outside the mask will be ignored
|
||||
/// </summary>
|
||||
/// <param name="mask">
|
||||
/// Provide a black and white image that contains white areas that should be scanned, and black areas that should be ignored.
|
||||
/// The width and height should match the image dimensions used for recognition.
|
||||
/// </param>
|
||||
/// <exception cref="InvalidOperationException">Thrown when the library has not been initialized</exception>
|
||||
public void SetDetectionMask(System.Drawing.Image mask)
|
||||
{
|
||||
check_initialization();
|
||||
|
||||
System.Drawing.Bitmap clone = new System.Drawing.Bitmap(mask.Width, mask.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
|
||||
using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(clone))
|
||||
{
|
||||
gr.DrawImage(mask, new System.Drawing.Rectangle(0, 0, clone.Width, clone.Height));
|
||||
}
|
||||
|
||||
System.Drawing.Imaging.BitmapData locked_bmp = clone.LockBits(new System.Drawing.Rectangle(0, 0, clone.Width, clone.Height),
|
||||
System.Drawing.Imaging.ImageLockMode.ReadWrite, clone.PixelFormat);
|
||||
byte[] raw_bytes = new byte[locked_bmp.Stride * locked_bmp.Height];
|
||||
System.Runtime.InteropServices.Marshal.Copy(locked_bmp.Scan0, raw_bytes, 0, raw_bytes.Length);
|
||||
clone.UnlockBits(locked_bmp);
|
||||
|
||||
int bytes_per_pixel = System.Drawing.Image.GetPixelFormatSize(clone.PixelFormat) / 8;
|
||||
|
||||
|
||||
IntPtr unmanagedArray = Marshal.AllocHGlobal(raw_bytes.Length);
|
||||
Marshal.Copy(raw_bytes, 0, unmanagedArray, raw_bytes.Length);
|
||||
|
||||
openalpr_set_mask(this.native_instance, unmanagedArray, bytes_per_pixel, mask.Width, mask.Height);
|
||||
|
||||
Marshal.FreeHGlobal(unmanagedArray);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the maximum number of results for OpenALPR to return with each recognition task
|
||||
/// </summary>
|
||||
/// <param name="top_n">An integer describing the maximum number of results to return</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown when the library has not been initialized</exception>
|
||||
public void setTopN(int top_n)
|
||||
{
|
||||
check_initialization();
|
||||
|
||||
openalpr_set_topn(this.native_instance, top_n);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the region used by OpenALPR for pattern matching. For example, "md" in the US would match plates matching that pattern.
|
||||
/// </summary>
|
||||
/// <param name="region">A two-letter code for the region/country to use as the default pattern</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown when the library has not been initialized</exception>
|
||||
public void setDefaultRegion(string region)
|
||||
{
|
||||
check_initialization();
|
||||
|
||||
openalpr_set_default_region(this.native_instance, region);
|
||||
}
|
||||
|
||||
// Enumerate the native methods. Handle the plumbing internally
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct NativeROI
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
public int width;
|
||||
public int height;
|
||||
}
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern IntPtr openalpr_init([MarshalAs(UnmanagedType.LPStr)] string country, [MarshalAs(UnmanagedType.LPStr)] string configFile, [MarshalAs(UnmanagedType.LPStr)] string runtimeDir);
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern int openalpr_is_loaded(IntPtr instance);
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern void openalpr_cleanup(IntPtr instance);
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern void openalpr_set_country(IntPtr instance, [MarshalAs(UnmanagedType.LPStr)] string country);
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern void openalpr_set_prewarp(IntPtr instance, [MarshalAs(UnmanagedType.LPStr)] string prewarp_config);
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern void openalpr_set_mask(IntPtr instance, IntPtr pixelData, int bytesPerPixel, int imgWidth, int imgHeight);
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern void openalpr_set_detect_region(IntPtr instance, int detectRegion);
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern void openalpr_set_topn(IntPtr instance, int topN);
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern void openalpr_set_default_region(IntPtr instance, [MarshalAs(UnmanagedType.LPStr)] string region);
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern IntPtr openalpr_recognize_rawimage(IntPtr instance, IntPtr pixelData, int bytesPerPixel, int imgWidth, int imgHeight, NativeROI roi);
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern IntPtr openalpr_recognize_encodedimage(IntPtr instance, IntPtr bytes, long length, NativeROI roi);
|
||||
|
||||
[DllImport("libopenalprc.dll")]
|
||||
private static extern void openalpr_free_response_string(IntPtr response);
|
||||
|
||||
|
||||
}
|
||||
}
|
81
src/bindings/csharp/alprnet/AlprNet.csproj
Normal file
81
src/bindings/csharp/alprnet/AlprNet.csproj
Normal file
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>alprnet</RootNamespace>
|
||||
<AssemblyName>alprnet</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Newtonsoft.Json.8.0.3\lib\net20\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Models\AlprResponse.cs" />
|
||||
<Compile Include="Alpr.cs" />
|
||||
<Compile Include="Models\AlprResult.cs" />
|
||||
<Compile Include="Models\Candidate.cs" />
|
||||
<Compile Include="Models\Coordinate.cs" />
|
||||
<Compile Include="Models\RegionOfInterest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
16
src/bindings/csharp/alprnet/Models/AlprResponse.cs
Normal file
16
src/bindings/csharp/alprnet/Models/AlprResponse.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AlprNet.Models
|
||||
{
|
||||
public class AlprResponse
|
||||
{
|
||||
public int version { get; set; }
|
||||
public string data_type { get; set; }
|
||||
public long epoch_time { get; set; }
|
||||
public int img_width { get; set; }
|
||||
public int img_height { get; set; }
|
||||
public float processing_time_ms { get; set; }
|
||||
public RegionOfInterest region_of_interest { get; set; }
|
||||
public IList<AlprResult> results { get; set; }
|
||||
}
|
||||
}
|
19
src/bindings/csharp/alprnet/Models/AlprResult.cs
Normal file
19
src/bindings/csharp/alprnet/Models/AlprResult.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace AlprNet.Models
|
||||
{
|
||||
public class AlprResult
|
||||
{
|
||||
public string plate { get; set; }
|
||||
public float confidence { get; set; }
|
||||
public bool matches_template { get; set; }
|
||||
public int plate_index { get; set; }
|
||||
public string region { get; set; }
|
||||
public float region_confidence { get; set; }
|
||||
public float processing_time_ms { get; set; }
|
||||
public int requested_topn { get; set; }
|
||||
public IList<Coordinate> coordinates { get; set; }
|
||||
public IList<Candidate> candidates { get; set; }
|
||||
}
|
||||
}
|
11
src/bindings/csharp/alprnet/Models/Candidate.cs
Normal file
11
src/bindings/csharp/alprnet/Models/Candidate.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
namespace AlprNet.Models
|
||||
{
|
||||
public class Candidate
|
||||
{
|
||||
public string plate { get; set; }
|
||||
public float confidence { get; set; }
|
||||
public bool matches_template { get; set; }
|
||||
}
|
||||
}
|
10
src/bindings/csharp/alprnet/Models/Coordinate.cs
Normal file
10
src/bindings/csharp/alprnet/Models/Coordinate.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
namespace AlprNet.Models
|
||||
{
|
||||
public class Coordinate
|
||||
{
|
||||
public int x { get; set; }
|
||||
public int y { get; set; }
|
||||
}
|
||||
}
|
12
src/bindings/csharp/alprnet/Models/RegionOfInterest.cs
Normal file
12
src/bindings/csharp/alprnet/Models/RegionOfInterest.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
namespace AlprNet.Models
|
||||
{
|
||||
public class RegionOfInterest
|
||||
{
|
||||
public int x { get; set; }
|
||||
public int y { get; set; }
|
||||
public int width { get; set; }
|
||||
public int height { get; set; }
|
||||
}
|
||||
}
|
36
src/bindings/csharp/alprnet/Properties/AssemblyInfo.cs
Normal file
36
src/bindings/csharp/alprnet/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("alprnet")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("alprnet")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f6106c0e-0e89-4d2e-89e6-19742d54b9f6")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
60
src/bindings/csharp/alprnet/alprnet.sln
Normal file
60
src/bindings/csharp/alprnet/alprnet.sln
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlprNet", "AlprNet.csproj", "{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlprNetTest", "..\AlprNetTest\AlprNetTest.csproj", "{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlprNetGuiTest", "..\AlprNetGuiTest\AlprNetGuiTest.csproj", "{C7863A14-55D2-4389-9072-04AA6E30AAD1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Debug|x64.Build.0 = Debug|x64
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Release|x64.ActiveCfg = Release|x64
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Release|x64.Build.0 = Release|x64
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{F6106C0E-0E89-4D2E-89E6-19742D54B9F6}.Release|x86.Build.0 = Release|Any CPU
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Debug|x64.Build.0 = Debug|x64
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Release|x64.ActiveCfg = Release|x64
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Release|x64.Build.0 = Release|x64
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{BA97FA53-9F76-42FD-90A4-E3BDBA3B66C3}.Release|x86.Build.0 = Release|Any CPU
|
||||
{C7863A14-55D2-4389-9072-04AA6E30AAD1}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{C7863A14-55D2-4389-9072-04AA6E30AAD1}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{C7863A14-55D2-4389-9072-04AA6E30AAD1}.Debug|x64.Build.0 = Debug|x64
|
||||
{C7863A14-55D2-4389-9072-04AA6E30AAD1}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{C7863A14-55D2-4389-9072-04AA6E30AAD1}.Debug|x86.Build.0 = Debug|x86
|
||||
{C7863A14-55D2-4389-9072-04AA6E30AAD1}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{C7863A14-55D2-4389-9072-04AA6E30AAD1}.Release|x64.ActiveCfg = Release|x64
|
||||
{C7863A14-55D2-4389-9072-04AA6E30AAD1}.Release|x64.Build.0 = Release|x64
|
||||
{C7863A14-55D2-4389-9072-04AA6E30AAD1}.Release|x86.ActiveCfg = Release|x86
|
||||
{C7863A14-55D2-4389-9072-04AA6E30AAD1}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
4
src/bindings/csharp/alprnet/packages.config
Normal file
4
src/bindings/csharp/alprnet/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net20" />
|
||||
</packages>
|
13
src/bindings/csharp/readme.md
Normal file
13
src/bindings/csharp/readme.md
Normal file
@@ -0,0 +1,13 @@
|
||||
OpenALPR C# Binding
|
||||
======================
|
||||
|
||||
This .NET binding enables OpenALPR to be used directly from C#. The binding uses the libopenalprc.dll produced from the native OpenALPR project.
|
||||
|
||||
Code samples are available in the AlprNetTest and AlprNetGui project. You must compile the program to match the native library version of OpenALPR. Usually this is 64-bit.
|
||||
|
||||
To install, you must include all native DLLs along with the openalpr.conf and runtime_data directory in a location accessible by the .NET program.
|
||||
|
||||
Troubleshooting
|
||||
-----------------
|
||||
|
||||
The most common issue is that the native OpenALPR DLLs are not available to .NET. The "Dependency Walker" program is very helpful for spotting missing DLLs. Load the libopenalprc.dll into your project to detect if all the other native DLLs are available.
|
Reference in New Issue
Block a user