基本信息
源码名称:基于halcon的二维码识别实例
源码大小:2.34M
文件格式:.rar
开发语言:C#
更新时间:2019-09-22
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
基于halcon的二维码识别实例
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HalconDotNet;
using System.IO;
namespace Halcon2
{
public partial class Form1 : Form
{
HDevelop HD = new HDevelop();
bool Add = false;
public Form1()
{
InitializeComponent();
}
private void btn_Disp_Click(object sender, EventArgs e)
{
string Fname = null;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
double P_Heigth = 0.00;
double P_Width = 0.00;
Fname = openFileDialog1.FileName;
bool falg = HD.ImageReadShow(hWindowControl1.HalconWindow, Fname, out P_Heigth, out P_Width);
txt_higth.Text = P_Heigth.ToString();
txt_width.Text = P_Width.ToString();
Add = true;
this.btn_pro.Enabled = true;
this.btn_save.Enabled = false;
}
else
{
MessageBox.Show("请选择正确的图片格式!");
}
}
private void btn_pro_Click(object sender, EventArgs e)
{
if (Add)
{
HTuple QR = "";
bool falg1 = HD.ImagePro(out QR);
if (falg1)
{
lab_QR.Text = QR;
this.btn_pro.Enabled = false;
this.btn_save.Enabled = true;
}
else
{
MessageBox.Show("识别失败!");
}
}
else
{
MessageBox.Show("请先加载图片!");
}
}
private void btn_save_Click(object sender, EventArgs e)
{
if (Add)
{
SaveFileDialog SaveNew = new SaveFileDialog();
SaveNew.Filter = "JPEG文件|*.jpg*|BMP文件|*.bmp*|TIFF文件|*.tiff*";
if (SaveNew.ShowDialog() == DialogResult.OK)
{
string Npath = SaveNew.FileName;
HD.ImageSave(Npath);
MessageBox.Show("保存成功!");
Add = false;
this.btn_pro.Enabled = false;
}
}
else
{
MessageBox.Show("请先加载图片!");
}
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
this.btn_pro.Enabled = false;
this.btn_save.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
this.lab_time.Text = DateTime.Now.ToString("HH:mm:ss");
}
}
public partial class HDevelop
{
HObject ho_image, ho_ImagereGray,ho_result;
public HTuple hv_wihandle;
public HTuple hlBarCodeHandle=null, hResultHandle=null;
public HTuple szChar = "";
public bool ImageReadShow(HTuple Window, string path, out double P_Heigth, out double P_Width)
{
hv_wihandle = Window;
HTuple hv_Width = null, hv_Heigth = null;
HOperatorSet.ReadImage(out ho_image, path);
HOperatorSet.GetImageSize(ho_image, out hv_Width, out hv_Heigth);
P_Heigth = hv_Heigth;
P_Width = hv_Width;
HOperatorSet.SetPart(hv_wihandle, 0, 0, hv_Heigth 1, hv_Width 1);
HOperatorSet.DispObj(ho_image, hv_wihandle);
return true;
}
public bool ImagePro(out HTuple szChar)
{
szChar="";
HOperatorSet.Rgb1ToGray(ho_image, out ho_ImagereGray);
//HOperatorSet.Emphasize(ho_image, out ho_ImagereGray,7,7,5.0);
//HOperatorSet.Threshold(ho_ImagereGray, out ho_result, 2, 8);
HOperatorSet.DispObj(ho_ImagereGray, hv_wihandle);
for (int i = 0; i < 15; i )
{
HOperatorSet.CreateDataCode2dModel("QR Code", "default_parameters", "maximum_recognition", out hv_wihandle);
HOperatorSet.FindDataCode2d(ho_ImagereGray, out ho_result, hv_wihandle, "train", "all", out hResultHandle, out szChar);
//MessageBox.Show(szChar);
}
if(szChar.Length == 0)
{
return false;
ho_image.Dispose();
ho_ImagereGray.Dispose();
}
else
{
return true;
}
}
public void ImageSave(string filename)
{
HOperatorSet.WriteImage(ho_ImagereGray,"jpg",0,filename);
ho_image.Dispose();
ho_ImagereGray.Dispose();
}
}
}