当前位置: 首页 > news >正文

C#Halcon二维码识别

      本章节呈现的Demo为通过外放参数可自由设置显示结果,与识别多种二维码的自由切换一种方法

Demo效果

条形码设置

06b79eee204d4b6184efae6562622fd8.png

显示检测结果

198b385a649148a9becb9011fe223801.png

二维码设置

4086231314f64e4097dc63122d99dd98.png

检测结果

0823d63af5264083a1c7d580bd0277b1.png

设置显示效果

90e40c3bdc0e4411bf7a5dd26d8914f9.png

719cfbb20c4f4253ae8455cb01c7583a.png

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ViewControl;
using HalconDotNet;
using System.Reflection.Emit;
using static System.Net.Mime.MediaTypeNames;
using System.Drawing.Text;namespace DeepLearningTest1
{public partial class Form1 : Form{HalconView HW;HObject HIMage = new HObject();HTuple CodeHandle = new HTuple();bool BarCode = false;bool DateCode = false;bool DisXLD = false;bool DisResult = false;string str;public Form1(){InitializeComponent();HW = new HalconView();HW.HWindowControl.BackColor = Color.White;splitContainer1.Panel1.Controls.Add(HW);HW.Dock = DockStyle.Fill;}       /// <summary>/// 加载图像/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button1_Click(object sender, EventArgs e){try{OpenFileDialog openFileDialog = new OpenFileDialog();openFileDialog.Filter = "图片文件(*.bmp;*.jpg;*.gif;*.png;*.tiff;*.tif)|*.bmp;*.jpg;*.gif;*.png;*.tiff;*.tif";openFileDialog.RestoreDirectory = true;openFileDialog.FilterIndex = 1;if (openFileDialog.ShowDialog() == DialogResult.OK){label3.Text = openFileDialog.FileName;HOperatorSet.ReadImage(out HIMage, label3.Text);HW.DispImage(HIMage, true);}}catch (Exception ex){MessageBox.Show("加载图片失败  " + ex.ToString());}}private void button3_Click(object sender, EventArgs e){SetDisplayFont(HW.HalconWindow, tBx_FontSize.Text, "true");}/// <summary>///bool  BarCode/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void checkBox1_CheckedChanged(object sender, EventArgs e){if (checkBox1.Checked){BarCode = true;}else{BarCode = false;}}/// <summary>/// bool   DateCode/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void checkBox2_CheckedChanged(object sender, EventArgs e){if (checkBox2.Checked){DateCode = true;}else{DateCode = false;}}/// <summary>/// bool  DisXLD/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void checkBox3_CheckedChanged(object sender, EventArgs e){if (checkBox3.Checked){DisXLD = true;}else{DisXLD = false;}}/// <summary>/// bool DisResult/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void checkBox4_CheckedChanged(object sender, EventArgs e){if (checkBox4.Checked){DisResult = true;}else{DisResult = false;}}/// <summary>/// 设定二维码类型/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button2_Click(object sender, EventArgs e){if (BarCode && !DateCode){CodeHandle.Dispose();HOperatorSet.CreateBarCodeModel(new HTuple(), new HTuple(), out CodeHandle);MessageBox.Show("已设定一维码");}else if (!BarCode && DateCode){if (comboBox1.Text == "QR Code"){str = "QR Code";CodeHandle.Dispose();HOperatorSet.CreateDataCode2dModel("QR Code", new HTuple(), new HTuple(), out CodeHandle);}if (comboBox1.Text == "Data Matrix ECC 200"){str = "Data Matrix ECC 200";}if (comboBox1.Text == "Micro QR Code"){str = "Micro QR Code";}if (comboBox1.Text == "PDF417"){str = "PDF417";}if (comboBox1.Text == "Aztec Code"){str = "Aztec Code";}if (comboBox1.Text == "DotCode"){str = "DotCode";}if (comboBox1.Text == "GS1 DataMatrix"){str = "GS1 DataMatrix";}if (comboBox1.Text == "GS1 QR Code"){str = "GS1 QR Code";}if (comboBox1.Text == "GS1 Aztec Code"){str = "GS1 Aztec Code";}if (comboBox1.Text == "GS1 DotCode"){str = "GS1 DotCode";}MessageBox.Show("已设定二维码" + str);}else if (BarCode && DateCode){MessageBox.Show("请勿全部选择");}else{MessageBox.Show("请选择条码类型");}}/// <summary>/// 识别二维码/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button4_Click(object sender, EventArgs e){HObject  RegionOrXLD ;HTuple hv_DecodedDataStrings = new HTuple(), hv_ResultHandles = new HTuple();HOperatorSet.GenEmptyObj(out RegionOrXLD);try{if (BarCode){RegionOrXLD.Dispose(); hv_DecodedDataStrings.Dispose();HOperatorSet.FindBarCode(HIMage, out RegionOrXLD, CodeHandle, "auto", out hv_DecodedDataStrings);}}catch (Exception){}try{if (DateCode){RegionOrXLD.Dispose(); hv_ResultHandles.Dispose(); hv_DecodedDataStrings.Dispose();HOperatorSet.FindDataCode2d(HIMage, out RegionOrXLD, CodeHandle,new HTuple(), new HTuple(), out hv_ResultHandles, out hv_DecodedDataStrings);}}catch (Exception){}if (DisXLD){HW.HalconWindow.SetDraw("margin");HW.HalconWindow.SetColor("red");HW.HalconWindow.SetLineWidth(5);HW.DispObject(RegionOrXLD);}if (DisResult){HW.disp_message(hv_DecodedDataStrings, "window", 12, 12, "green", "false", "");}}}
}

 

 


http://www.mrgr.cn/news/83331.html

相关文章:

  • LLaMA-Factory web微调大模型并导出大模型
  • 探索图像编辑的无限可能——Adobe Photoshop全解析
  • 如何 cURL Elasticsearch:进入 Shell
  • linux centos挂载未分配的磁盘空间
  • Python中的asyncio:高效的异步编程模型
  • Ubuntu 下载安装 elasticsearch7.17.9
  • 第十四章 SQL性能分析
  • 【Python】Python之Selenium基础教程+实战demo:提升你的测试+测试数据构造的效率!
  • PySpark广播表连接解决数据倾斜的完整案例
  • 高等数学学习笔记 ☞ 洛必达法则与泰勒公式
  • 【Rust自学】11.5. 在测试中使用Result<T, E>
  • Formality:默认配置文件
  • 【python翻译软件V1.0】
  • 【数据链电台】洛克希德·马丁(Lockheed Martin)
  • P2249 【深基13.例1】查找
  • kubernetes第七天
  • notebook主目录及pip镜像源修改
  • 代码随想录 哈希 test 8
  • 【神经网络中的激活函数如何选择?】
  • 使用 Maxwell 计算母线的电动势
  • 赛车微型配件订销管理系统(源码+lw+部署文档+讲解),源码可白嫖!
  • Formality:工具生成的文件
  • 初学stm32 --- DAC输出
  • 51c~Pytorch~合集4
  • Ansys Fluent Aeroacoustics 应用
  • Java Web开发进阶——Spring Security基础与应用