资源简介
VS平台使用c#联合halcon编程,根据鼠标获取当前图像某点灰度值的小程序
代码片段和文件信息
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 HalconDotNet;
namespace mouse_move
{
public partial class Form1 : Form
{
string adr; //储存图片路径
public Form1()
{
InitializeComponent();
}
bool flag = false;
private void button1_Click(object sender EventArgs e)
{
Hobject image;
HOperatorSet.ReadImage(out image @“E:/c#学习/gray_lena.bmp“);
HOperatorSet.DispObj(image hWindowControl1.HalconWindow);
flag = true;
adr = @“E:/c#学习/gray_lena.bmp“;
}
private void hWindowControl1_HMouseMove(object sender HMouseEventArgs e)
{
if (flag)
{
HTuple X = new HTuple();
HTuple Y = new HTuple();
Hobject image;
HTuple row = new HTuple();
HTuple col = new HTuple();
HTuple grayval = new HTuple();
HOperatorSet.ReadImage(out image adr);
HOperatorSet.GetImageSize(image out X out Y);
hWindowControl1.Size = new System.Drawing.Size(X Y);
hWindowControl1.ImagePart = new System.Drawing.Rectangle(0 0 X Y);
row = (int)e.X;
col = (int)e.Y;
HOperatorSet.GetGrayval(image col row out grayval);
textBox1.Text = row.ToString();
textBox2.Text = col.ToString();
textBox3.Text = grayval.ToString();
}
}
private void button2_Click(object sender EventArgs e)
{
HTuple X = new HTuple();
HTuple Y = new HTuple();
try
{
OpenFileDialog file = new OpenFileDialog();
file.Filter = “|*.bmp; *.png; *.jpg“;
if (file.ShowDialog() == DialogResult.OK)
{
adr = file.FileName;
Hobject image;
HOperatorSet.ReadImage(out image adr);
HOperatorSet.GetImageSize(image out X out Y);
hWindowControl1.Size = new System.Drawing.Size(XY);
hWindowControl1.ImagePart = new System.Drawing.Rectangle(0 0 X Y);
HOperatorSet.DispObj(image hWindowControl1.HalconWindow);
flag = true;
}
}
catch (Exception)
{
throw;
}
}
private void button3_Click(object sender EventArgs e)
{
HOperatorSet.ClearWindow(hWindowControl1.HalconWindow);
flag = false;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 263222 2017-09-07 15:59 mouse_move\gray_lena.bmp
文件 786486 2017-07-19 15:34 mouse_move\lena.BMP
文件 187 2017-09-07 14:05 mouse_move\mouse_move\App.config
文件 1413776 2017-05-25 20:27 mouse_move\mouse_move\bin\Debug\halcondotnet.dll
文件 4361570 2017-05-25 16:41 mouse_move\mouse_move\bin\Debug\halcondotnet.xm
文件 12288 2017-09-08 11:18 mouse_move\mouse_move\bin\Debug\mouse_move.exe
文件 187 2017-09-07 14:05 mouse_move\mouse_move\bin\Debug\mouse_move.exe.config
文件 26112 2017-09-08 11:18 mouse_move\mouse_move\bin\Debug\mouse_move.pdb
文件 24224 2017-09-08 11:23 mouse_move\mouse_move\bin\Debug\mouse_move.vshost.exe
文件 187 2017-09-07 14:05 mouse_move\mouse_move\bin\Debug\mouse_move.vshost.exe.config
文件 490 2010-03-17 22:39 mouse_move\mouse_move\bin\Debug\mouse_move.vshost.exe.manifest
文件 4031 2017-09-08 11:21 mouse_move\mouse_move\Form1.cs
文件 7610 2017-09-08 10:10 mouse_move\mouse_move\Form1.Designer.cs
文件 6225 2017-09-08 10:10 mouse_move\mouse_move\Form1.resx
文件 3926 2017-09-07 15:16 mouse_move\mouse_move\mouse_move.csproj
文件 10381 2017-09-07 14:05 mouse_move\mouse_move\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6900 2017-09-07 14:05 mouse_move\mouse_move\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 769 2017-09-08 11:23 mouse_move\mouse_move\obj\Debug\mouse_move.csproj.FileListAbsolute.txt
文件 977 2017-09-08 10:10 mouse_move\mouse_move\obj\Debug\mouse_move.csproj.GenerateResource.Cache
文件 11111 2017-09-07 15:16 mouse_move\mouse_move\obj\Debug\mouse_move.csprojResolveAssemblyReference.cache
文件 12288 2017-09-08 11:18 mouse_move\mouse_move\obj\Debug\mouse_move.exe
文件 180 2017-09-08 10:10 mouse_move\mouse_move\obj\Debug\mouse_move.Form1.resources
文件 26112 2017-09-08 11:18 mouse_move\mouse_move\obj\Debug\mouse_move.pdb
文件 180 2017-09-07 15:16 mouse_move\mouse_move\obj\Debug\mouse_move.Properties.Resources.resources
文件 0 2017-09-07 14:05 mouse_move\mouse_move\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2017-09-07 14:05 mouse_move\mouse_move\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2017-09-07 14:05 mouse_move\mouse_move\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
文件 522 2017-09-07 14:05 mouse_move\mouse_move\Program.cs
文件 1344 2017-09-07 14:05 mouse_move\mouse_move\Properties\AssemblyInfo.cs
文件 2872 2017-09-07 14:05 mouse_move\mouse_move\Properties\Resources.Designer.cs
............此处省略16个文件信息
- 上一篇:C#图像特征点提取与同名像点匹配
- 下一篇:基于C#的管理系统
评论
共有 条评论