Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.textBox1.AppendText("正在训练中,请稍等......\n");

            Application.DoEvents();//C#界面假死导致label不更新解决
            DllInvoke dll             = new DllInvoke(@"../../../../x64/Release/CreateDLL.dll");
            svm_train train_svm_model = (svm_train)dll.Invoke("train_svm", typeof(svm_train));

            if (train_svm_model() == 0)
            {
                this.textBox1.Text = "";
                this.textBox1.AppendText("模型训练完成!\n");
                this.textBox1.AppendText("\n");
                this.textBox1.AppendText("测试结果如下:\n");
                FileStream fs   = new FileStream("svm_result.txt", FileMode.Open, FileAccess.ReadWrite);
                byte[]     buff = new byte[1024];
                int        len  = fs.Read(buff, 0, 1024);
                while (len > 0)
                {
                    string s = Encoding.UTF8.GetString(buff, 0, len);
                    this.textBox1.AppendText(s);
                    len = fs.Read(buff, 0, 1024);
                }
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.label1.Text = "正在处理中,请稍等......";
            Application.DoEvents();
            DllInvoke   dll = new DllInvoke(@"../../../../x64/Release/CreateDLL.dll");
            do_lps_func lps = (do_lps_func)dll.Invoke("do_lps", typeof(do_lps_func));

            //folder_path = @"L:\Users\zc\Desktop\native_test";
            DirectoryInfo TheFolder = new DirectoryInfo(folder_path);

            int jpg_num = 0;

            //遍历文件获取jpg文件个数
            foreach (FileInfo NextFile in TheFolder.GetFiles())
            {
                if (NextFile.Extension == ".jpg")
                {
                    jpg_num++;
                }
            }

            //进度条初始化
            progressBar1.Value   = 0;
            progressBar1.Minimum = 0;
            progressBar1.Maximum = jpg_num;

            //遍历文件
            foreach (FileInfo NextFile in TheFolder.GetFiles())
            {
                if (NextFile.Extension == ".jpg")
                {
                    progressBar1.Value++;

                    int result_num = lps(folder_path + "\\" + NextFile.Name, 5);
                }
            }
            this.label1.Text = "文件夹内所有图片处理完毕,结果请点击下方按钮查看。";
        }
Exemplo n.º 3
0
        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DllInvoke            dll         = new DllInvoke(@"../../../../x64/Release/CreateDLL.dll");
            do_lps_func          lps         = (do_lps_func)dll.Invoke("do_lps", typeof(do_lps_func));
            get_license_str_func get_license = (get_license_str_func)dll.Invoke("get_license_str", typeof(get_license_str_func));
            get_color_str_func   get_color   = (get_color_str_func)dll.Invoke("get_color_str", typeof(get_color_str_func));

            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Title  = "请选择文件";
            fileDialog.Filter = "所有文件(*.*)|*.*";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                Directory.Delete(@"resources/image/interface/show_detect", true);
                Directory.CreateDirectory(@"resources/image/interface/show_detect");
                string file_name = fileDialog.FileName;
                //MessageBox.Show("已选择文件:" + file_name, "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                int result_num = lps(file_name, 2);// 只写结果
                if (result_num == 0)
                {
                    IntPtr license     = get_license();
                    string license_str = Marshal.PtrToStringAnsi(license);
                    IntPtr color       = get_color();
                    string color_str   = Marshal.PtrToStringAnsi(color);
                    string color_CHN;
                    if (color_str == "BLUE")
                    {
                        color_CHN = "蓝牌:";
                    }
                    else if (color_str == "YELLOW")
                    {
                        color_CHN = "黄牌:";
                    }
                    else if (color_str == "GREEN")
                    {
                        color_CHN = "绿牌:";
                    }
                    else
                    {
                        color_CHN = "未知:";
                    }

                    this.textBox1.Text = color_CHN + license_str;

                    FileStream pFileStream0 = new FileStream(@"resources/image/interface/chars_segment/whole.png", FileMode.Open, FileAccess.Read);
                    pictureBox1.Image    = Image.FromStream(pFileStream0);
                    pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
                    pFileStream0.Close();
                    pFileStream0.Dispose();

                    //pictureBox1.Image = Image.FromFile(@"resources/image/interface/chars_segment/whole.png");  //动态添加图片
                    //pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;  //使控件PictureBox的大小适应图片的大小

                    FileStream pFileStream1 = new FileStream(@"resources/image/interface/final_result/plate_0.png", FileMode.Open, FileAccess.Read);
                    pictureBox2.Image    = Image.FromStream(pFileStream1);  //动态添加图片
                    pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage; //使控件PictureBox的大小适应图片的大小
                    pFileStream1.Close();
                    pFileStream1.Dispose();

                    FileStream pFileStream2 = new FileStream(@"resources/image/interface/chars_segment/0.png", FileMode.Open, FileAccess.Read);
                    char0.Image    = Image.FromStream(pFileStream2);  //动态添加图片
                    char0.SizeMode = PictureBoxSizeMode.StretchImage; //使控件PictureBox的大小适应图片的大小
                    pFileStream2.Close();
                    pFileStream2.Dispose();

                    FileStream pFileStream3 = new FileStream(@"resources/image/interface/chars_segment/1.png", FileMode.Open, FileAccess.Read);
                    char1.Image    = Image.FromStream(pFileStream3);  //动态添加图片
                    char1.SizeMode = PictureBoxSizeMode.StretchImage; //使控件PictureBox的大小适应图片的大小
                    pFileStream3.Close();
                    pFileStream3.Dispose();

                    FileStream pFileStream4 = new FileStream(@"resources/image/interface/chars_segment/2.png", FileMode.Open, FileAccess.Read);
                    char2.Image    = Image.FromStream(pFileStream4);  //动态添加图片
                    char2.SizeMode = PictureBoxSizeMode.StretchImage; //使控件PictureBox的大小适应图片的大小
                    pFileStream4.Close();
                    pFileStream4.Dispose();

                    FileStream pFileStream5 = new FileStream(@"resources/image/interface/chars_segment/3.png", FileMode.Open, FileAccess.Read);
                    char3.Image    = Image.FromStream(pFileStream5);  //动态添加图片
                    char3.SizeMode = PictureBoxSizeMode.StretchImage; //使控件PictureBox的大小适应图片的大小
                    pFileStream5.Close();
                    pFileStream5.Dispose();

                    FileStream pFileStream6 = new FileStream(@"resources/image/interface/chars_segment/4.png", FileMode.Open, FileAccess.Read);
                    char4.Image    = Image.FromStream(pFileStream6);  //动态添加图片
                    char4.SizeMode = PictureBoxSizeMode.StretchImage; //使控件PictureBox的大小适应图片的大小
                    pFileStream6.Close();
                    pFileStream6.Dispose();

                    FileStream pFileStream7 = new FileStream(@"resources/image/interface/chars_segment/5.png", FileMode.Open, FileAccess.Read);
                    char5.Image    = Image.FromStream(pFileStream7);  //动态添加图片
                    char5.SizeMode = PictureBoxSizeMode.StretchImage; //使控件PictureBox的大小适应图片的大小
                    pFileStream7.Close();
                    pFileStream7.Dispose();

                    FileStream pFileStream8 = new FileStream(@"resources/image/interface/chars_segment/6.png", FileMode.Open, FileAccess.Read);
                    char6.Image    = Image.FromStream(pFileStream8);  //动态添加图片
                    char6.SizeMode = PictureBoxSizeMode.StretchImage; //使控件PictureBox的大小适应图片的大小
                    pFileStream8.Close();
                    pFileStream8.Dispose();

                    FileStream pFileStream9 = new FileStream(@"resources/image/interface/chars_segment/7.png", FileMode.Open, FileAccess.Read);
                    if (color_str == "GREEN")
                    {
                        char7.Visible = true;
                    }
                    else
                    {
                        char7.Visible = false;
                    }

                    char7.Image    = Image.FromStream(pFileStream9);  //动态添加图片
                    char7.SizeMode = PictureBoxSizeMode.StretchImage; //使控件PictureBox的大小适应图片的大小
                    pFileStream9.Close();
                    pFileStream9.Dispose();
                }
            }
        }
Exemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            DllInvoke            dll         = new DllInvoke(@"../../../../x64/Release/CreateDLL.dll");
            do_lps_func          lps         = (do_lps_func)dll.Invoke("do_lps", typeof(do_lps_func));
            get_license_str_func get_license = (get_license_str_func)dll.Invoke("get_license_str", typeof(get_license_str_func));

            //folder_path = @"L:\Users\zc\Desktop\native_test";
            DirectoryInfo TheFolder = new DirectoryInfo(folder_path);

            int jpg_num = 0;

            //遍历文件获取jpg文件个数
            foreach (FileInfo NextFile in TheFolder.GetFiles())
            {
                if (NextFile.Extension == ".jpg")
                {
                    jpg_num++;
                }
            }

            //进度条初始化
            progressBar1.Value   = 0;
            progressBar1.Minimum = 0;
            progressBar1.Maximum = jpg_num;

            //遍历文件
            foreach (FileInfo NextFile in TheFolder.GetFiles())
            {
                if (NextFile.Extension == ".jpg")
                {
                    progressBar1.Value++;
                    int index = this.dataGridView1.Rows.Add();
                    dataGridView1.Rows[index].Cells[0].Value = index + 1;
                    dataGridView1.Rows[index].Cells[1].Value = NextFile.Name.Replace(".jpg", "");
                    System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                    watch.Start(); //开始计时
                    int result_num = lps(folder_path + "\\" + NextFile.Name, 0);
                    watch.Stop();  //结束计时
                    if (result_num == 0)
                    {
                        IntPtr license     = get_license();
                        string license_str = Marshal.PtrToStringAnsi(license);
                        //第三列检测车牌结果
                        dataGridView1.Rows[index].Cells[2].Value = license_str;
                        //第四列误差
                        dataGridView1.Rows[index].Cells[3].Value = CompareText(license_str, NextFile.Name.Replace(".jpg", ""));
                        if (license_str[0] != NextFile.Name.Replace(".jpg", "")[0])
                        {
                            chinese_error_rate++;
                        }
                        //有误行红色显示
                        if (CompareText(license_str, NextFile.Name.Replace(".jpg", "")) != 0)
                        {
                            dataGridView1.Rows[index].DefaultCellStyle.ForeColor = Color.Red;
                            if (CompareText(license_str, NextFile.Name.Replace(".jpg", "")) == 1)
                            {
                                one_error_rate++;
                            }
                        }
                        else
                        {
                            /*
                             * //测试用,保存true
                             * FileInfo file = new FileInfo(folder_path + "\\" + NextFile.Name);
                             * if (file.Exists)
                             * {
                             *  // true is overwrite
                             *  file.CopyTo(@"L:\Users\zc\Desktop\native_test\" + NextFile.Name, true);
                             * }
                             */
                            zero_error_rate++;
                            one_error_rate++;
                        }
                        //第五列识别时间
                        dataGridView1.Rows[index].Cells[4].Value = watch.ElapsedMilliseconds;
                        if (index == 0)
                        {
                            avg_time = watch.ElapsedMilliseconds;
                        }
                        else
                        {
                            avg_time = (avg_time + watch.ElapsedMilliseconds) / 2;
                        }
                    }
                }
            }
            this.label5.Text = avg_time.ToString();
            this.label6.Text = ((zero_error_rate / jpg_num) * 100).ToString() + "%";
            this.label7.Text = ((one_error_rate / jpg_num) * 100).ToString() + "%";
            this.label8.Text = ((chinese_error_rate / jpg_num) * 100).ToString() + "%";
        }