基本信息
源码名称:C#与Halcon通用检测工程实例
源码大小:14.22M
文件格式:.zip
开发语言:C#
更新时间:2018-06-11
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
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 vision
{
public partial class Form1 : Form
{
int camnum = 2;
int CurrentCam = 1;
string path = Application.StartupPath;
string curpath;
int curindex = 0;
List<string> allim;
HObject curimage;
public Form1()
{
InitializeComponent();
HOperatorSet.GenEmptyObj(out curimage);
}
private void button1_Click(object sender, EventArgs e)
{
if (CurrentCam > 1)
{
CurrentCam--;
label1.Text = "相机" CurrentCam.ToString();
curpath = path @"\CCD" CurrentCam.ToString();
getallim();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (CurrentCam < camnum)
{
CurrentCam ;
label1.Text = "相机" CurrentCam.ToString();
curpath = path @"\CCD" CurrentCam.ToString();
getallim();
}
}
private void Form1_Load(object sender, EventArgs e)
{
curpath = path @"\CCD1";
allim = new List<string>();
curpath = path @"\CCD" CurrentCam.ToString();
getallim();
}
void getallim()
{
//获取当前文件夹下bmp的数量和路径
allim.Clear();
DirectoryInfo Dir = new DirectoryInfo(curpath);
foreach (FileInfo FI in Dir.GetFiles())
{
// 这里写文件格式
if (System.IO.Path.GetExtension(FI.Name) == ".bmp")
{
allim.Add(FI.DirectoryName @"\" FI.Name);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
if (curindex - 1 > 0)
{
HOperatorSet.ReadImage(out curimage, allim[curindex - 1]);
HTuple width, height;
HOperatorSet.GetImageSize(curimage, out width, out height);
HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, height - 1, width - 1);
hWindowControl1.HalconWindow.DispObj(curimage);
curindex--;
button4.Enabled = true;
}
else if (curindex - 1 == 0)
{
HOperatorSet.ReadImage(out curimage, allim[curindex - 1]);
HTuple width, height;
HOperatorSet.GetImageSize(curimage, out width, out height);
HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, height - 1, width - 1);
hWindowControl1.HalconWindow.DispObj(curimage);
curindex--;
button3.Enabled = false;
}
else
{
}
if (mytool != null && curimage != null)
{
mytool.image = curimage;
mytool.method();
}
}
private void button4_Click(object sender, EventArgs e)
{
if (curindex 1 < allim.Count - 1)
{
HOperatorSet.ReadImage(out curimage, allim[curindex 1]);
HTuple width, height;
HOperatorSet.GetImageSize(curimage, out width, out height);
HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, height - 1, width - 1);
hWindowControl1.HalconWindow.DispObj(curimage);
curindex ;
button3.Enabled = true;
}
else if (curindex 1 == allim.Count - 1)
{
HOperatorSet.ReadImage(out curimage, allim[curindex 1]);
HTuple width, height;
HOperatorSet.GetImageSize(curimage, out width, out height);
HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, height - 1, width - 1);
hWindowControl1.HalconWindow.DispObj(curimage);
curindex ;
button4.Enabled = false;
}
else
{
}
if (mytool != null && curimage != null)
{
mytool.image = curimage;
mytool.method();
}
}
ImageTool mytool;
private void button5_Click(object sender, EventArgs e)
{
hWindowControl1.Focus();
//imtool = new tool1();
//imtool.hwin = hWindowControl1.HalconWindow;
//imtool.image = curimage;
//imtool.draw();
//imtool.init();
//imtool.method();
areatool tool = new areatool();
tool.hwin = hWindowControl1.HalconWindow;
tool.image = curimage;
tool.draw();
tool.init();
tool.method();
mytool = tool;
}
}
}