当前位置:网站首页>Halcon与Winform学习第一节
Halcon与Winform学习第一节
2022-07-03 15:08:00 【11eleven】
学习halcon的HWindowControl控件的使用
文章目录
前言
随着工业自动化的发展视觉检测应用的场景也变得广阔,这就诞生了halcon这样的应用,集成了常见的算子算法,让一般项目可以快速交付,这里是学习的第一节
一、Halcon是什么?
HALCON是目前工业自动化领域广泛使用的软件,可以快速有效的解决图像处理问题的应用软件。
二、使用步骤
1.安装
可去到官方网站上下载安装,安装后可在目录下找到DLL。
2.引入库
代码如下(示例):halcondotnet.dll
using HalconDotNet;
3. 控件使用
引入库后HWindowControl可以直接在winform中使用如图
using HalconDotNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vision.Winform
{
public class MouseOnHalConModel {
public HTuple Row { set; get; }
public HTuple Column { set; get; }
public HTuple PointGray { set; get; }
}
public class HalConHelper
{
public Action<MouseOnHalConModel> mouseMoveAction;
public HalConHelper(HWindowControl hWindowControl)
{
windowID = hWindowControl.HalconWindow;
// windowID = window;
hWindowControl.HMouseWheel += HWindowControl1_HMouseWheel;
hWindowControl.HMouseDown += HWindowControl1_HMouseDown;
hWindowControl.HMouseUp += HWindowControl1_HMouseUp;
hWindowControl.HMouseMove += HWindowControl1_HMouseMove;
}
private void HWindowControl1_HMouseMove(object sender, HMouseEventArgs e)
{
try
{
HTuple row, column, button, pointGray;
HOperatorSet.GetMposition(windowID, out row, out column, out button); //获取当前鼠标的坐标值
if (imageHeight != null && (row > 0 && row < imageHeight) && (column > 0 && column < imageWidth))//设置3个条件项,防止程序崩溃。
{
HOperatorSet.GetGrayval(ho_image, row, column, out pointGray); //获取当前点的灰度值
}
else
{
pointGray = "_";
}
String str = String.Format("Row:{0} Column:{1} Gray:{2}", row, column, pointGray); //格式化字符串
//label1.Text = str;
mouseMoveAction?.Invoke(new MouseOnHalConModel() { Column = column, Row = row, PointGray = pointGray });
}
catch {
}
}
private void HWindowControl1_HMouseUp(object sender, HMouseEventArgs e)
{
try
{
HTuple row1, col1, row2, col2, row, column, button;
HOperatorSet.GetMposition(windowID, out row, out column, out button);
double rowMove = row - rowDown; //鼠标弹起时的行坐标减去按下时的行坐标,得到行坐标的移动值
double colMove = column - colDown;//鼠标弹起时的列坐标减去按下时的列坐标,得到列坐标的移动值
HOperatorSet.GetPart(windowID, out row1, out col1, out row2, out col2);//得到当前的窗口坐标
HOperatorSet.SetPart(windowID, row1 - rowMove, col1 - colMove, row2 - rowMove, col2 - colMove);//这里可能有些不好理解。以左上角原点为参考点
HOperatorSet.ClearWindow(windowID);
if (imageHeight != null)
{
HOperatorSet.DispObj(ho_image, windowID);
}
else
{
MyMessageBox.ShowAlert("请先加载一张图像");
}
}
catch {
}
}
private void HWindowControl1_HMouseDown(object sender, HMouseEventArgs e)
{
HTuple row, column, button;
HOperatorSet.GetMposition(windowID, out row, out column, out button);
rowDown = row; //鼠标按下时的行坐标
colDown = column; //鼠标按下时的列坐标
}
public HTuple windowID, imageWidth, imageHeight;
private double rowDown;//鼠标按下时的行坐标
private double colDown;//鼠标按下时的列坐标
public HObject ho_image; //图像变量
private void HWindowControl1_HMouseWheel(object sender, HMouseEventArgs e)
{
HTuple zoom, row, col, button;
HTuple row0, column0, row00, column00, ht, wt, r1, c1, r2, c2;
if (e.Delta > 0)
{
zoom = 1.5;
}
else
{
zoom = 0.5;
}
HOperatorSet.GetMposition(windowID, out row, out col, out button);
HOperatorSet.GetPart(windowID, out row0, out column0, out row00, out column00);
ht = row00 - row0;
wt = column00 - column0;
if (ht * wt < 32000 * 32000 || zoom == 1.5)//普通版halcon能处理的图像最大尺寸是32K*32K。如果无限缩小原图像,导致显示的图像超出限制,则会造成程序崩溃
{
r1 = (row0 + ((1 - (1.0 / zoom)) * (row - row0)));
c1 = (column0 + ((1 - (1.0 / zoom)) * (col - column0)));
r2 = r1 + (ht / zoom);
c2 = c1 + (wt / zoom);
HOperatorSet.SetPart(windowID, r1, c1, r2, c2);
HOperatorSet.ClearWindow(windowID);
HOperatorSet.DispObj(ho_image, windowID);
}
}
}
}
总结
以上就是halcon入门的第一节了,安装与dll库引用,控件的引入。
边栏推荐
- 官网MapReduce实例代码详细批注
- 开启 Chrome 和 Edge 浏览器多线程下载
- How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
- Finally, someone explained the financial risk management clearly
- Apache ant extension tutorial
- 使用JMeter对WebService进行压力测试
- Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)
- 4-33--4-35
- Solve the problem that pushgateway data will be overwritten by multiple push
- [graphics] real shading in Unreal Engine 4
猜你喜欢
Kubernetes带你从头到尾捋一遍
[graphics] real shading in Unreal Engine 4
"Seven weapons" in the "treasure chest" of machine learning: Zhou Zhihua leads the publication of the new book "machine learning theory guide"
[ue4] Niagara's indirect draw
QT - draw something else
What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry
mysql innodb 存储引擎的特性—行锁剖析
[graphics] hair simulation in tressfx
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
【pytorch学习笔记】Datasets and Dataloaders
随机推荐
"Seven weapons" in the "treasure chest" of machine learning: Zhou Zhihua leads the publication of the new book "machine learning theory guide"
Byte practice surface longitude
Global and Chinese markets for transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share
[ue4] HISM large scale vegetation rendering solution
[transformer] Introduction - the original author of Harvard NLP presented the annotated transformer in the form of line by line implementation in early 2018
Introduction to opengl4.0 tutorial computing shaders
Kubernetes带你从头到尾捋一遍
Leetcode the smallest number of the rotation array of the offer of the sword (11)
什么是embedding(把物体编码为一个低维稠密向量),pytorch中nn.Embedding原理及使用
第04章_逻辑架构
B2020 points candy
5.4-5.5
【可能是全中文网最全】pushgateway入门笔记
Relationship between truncated random distribution and original distribution
C # realizes the login interface, and the password asterisk is displayed (hide the input password)
Redis主从、哨兵、集群模式介绍
SQL server安装位置改不了
4-24--4-28
What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry
[pytorch learning notes] transforms