C# OpenCvSharp 车牌颜色识别
目录
效果
项目
代码
using OpenCvSharp;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace OpenCvSharp_Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string fileFilter = "图片|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
string image_path = "";
Mat image;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = fileFilter;
ofd.InitialDirectory = Application.StartupPath + "\\test_img";
if (ofd.ShowDialog() != DialogResult.OK) return;
pictureBox1.Image = null;
image_path = ofd.FileName;
pictureBox1.Image = new Bitmap(image_path);
textBox1.Text = "";
image = new Mat(image_path);
}
private void Form1_Load(object sender, EventArgs e)
{
image_path = "test_img/1.jpg";
pictureBox1.Image = new Bitmap(image_path);
image = new Mat(image_path);
}
PlateColorCls plateColorCls = new PlateColorCls();
private void button3_Click(object sender, EventArgs e)
{
if (image_path == "")
{
return;
}
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
string plateColor = plateColorCls.GetPlateColor(image);
stopwatch.Stop();
textBox1.Text = "耗时:\t\t" + stopwatch.ElapsedMilliseconds + "ms\r\n";
textBox1.Text += "号牌颜色:\t" + plateColor + "\r\n";
textBox1.Text += "-----------------------------\r\n";
textBox1.Text += plateColorCls.GetPixelCountInfo();
}
}
}
using OpenCvSharp;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace OpenCvSharp_Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string fileFilter = "图片|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
string image_path = "";
Mat image;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = fileFilter;
ofd.InitialDirectory = Application.StartupPath + "\\test_img";
if (ofd.ShowDialog() != DialogResult.OK) return;
pictureBox1.Image = null;
image_path = ofd.FileName;
pictureBox1.Image = new Bitmap(image_path);
textBox1.Text = "";
image = new Mat(image_path);
}
private void Form1_Load(object sender, EventArgs e)
{
image_path = "test_img/1.jpg";
pictureBox1.Image = new Bitmap(image_path);
image = new Mat(image_path);
}
PlateColorCls plateColorCls = new PlateColorCls();
private void button3_Click(object sender, EventArgs e)
{
if (image_path == "")
{
return;
}
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
string plateColor = plateColorCls.GetPlateColor(image);
stopwatch.Stop();
textBox1.Text = "耗时:\t\t" + stopwatch.ElapsedMilliseconds + "ms\r\n";
textBox1.Text += "号牌颜色:\t" + plateColor + "\r\n";
textBox1.Text += "-----------------------------\r\n";
textBox1.Text += plateColorCls.GetPixelCountInfo();
}
}
}