当前位置:网站首页>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库引用,控件的引入。
边栏推荐
- Vs+qt application development, set software icon icon
- 视觉上位系统设计开发(halcon-winform)-6.节点与宫格
- 什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
- 【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
- [graphics] hair simulation in tressfx
- Relationship between truncated random distribution and original distribution
- Kubernetes 进阶训练营 Pod基础
- Zero copy underlying analysis
- 在MapReduce中利用MultipleOutputs输出多个文件
- Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Yolov5系列(一)——網絡可視化工具netron

Vs+qt application development, set software icon icon
![[engine development] rendering architecture and advanced graphics programming](/img/a4/3526a4e0f68e49c1aa5ce23b578781.jpg)
[engine development] rendering architecture and advanced graphics programming

远程服务器后台挂起 nohup

Tencent internship interview sorting

Kubernetes 进阶训练营 Pod基础

【可能是全中文网最全】pushgateway入门笔记

High quality workplace human beings must use software to recommend, and you certainly don't know the last one

Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)

CentOS7部署哨兵Redis(带架构图,清晰易懂)
随机推荐
Vs+qt application development, set software icon icon
"Seven weapons" in the "treasure chest" of machine learning: Zhou Zhihua leads the publication of the new book "machine learning theory guide"
Leetcode sword offer find the number I (nine) in the sorted array
406. 根据身高重建队列
【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
Leetcode the smallest number of the rotation array of the offer of the sword (11)
Kubernetes带你从头到尾捋一遍
Web server code parsing - thread pool
Global and Chinese market of air cargo logistics 2022-2028: Research Report on technology, participants, trends, market size and share
SQL server installation location cannot be changed
TPS61170QDRVRQ1
[set theory] inclusion exclusion principle (complex example)
视觉上位系统设计开发(halcon-winform)-2.全局变量设计
How does vs+qt set the software version copyright, obtain the software version and display the version number?
[ue4] HISM large scale vegetation rendering solution
[graphics] adaptive shadow map
Functional modules and application scenarios covered by the productization of user portraits
Yolov5系列(一)——网络可视化工具netron
基础SQL教程