您的位置:首页 > 科技 > 能源 > C# OpenCvSharp 车牌颜色识别

C# OpenCvSharp 车牌颜色识别

2024/10/5 19:17:56 来源:https://blog.csdn.net/lw112190/article/details/139769668  浏览:    关键词:C# OpenCvSharp 车牌颜色识别

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();}}
}

下载

源码下载

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com