当前位置:网站首页>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库引用,控件的引入。
边栏推荐
- Devaxpress: range selection control rangecontrol uses
- Mmdetection learning rate and batch_ Size relationship
- Yolov5 advanced nine target tracking example 1
- [engine development] in depth GPU and rendering optimization (basic)
- [graphics] hair simulation in tressfx
- [ue4] material and shader permutation
- 开启 Chrome 和 Edge 浏览器多线程下载
- ASTC texture compression (adaptive scalable texture compression)
- Besides lying flat, what else can a 27 year old do in life?
- How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
猜你喜欢

Série yolov5 (i) - - netron, un outil de visualisation de réseau

零拷贝底层剖析

【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention

【注意力机制】【首篇ViT】DETR,End-to-End Object Detection with Transformers网络的主要组成是CNN和Transformer

Introduction to opengl4.0 tutorial computing shaders

Besides lying flat, what else can a 27 year old do in life?

Zero copy underlying analysis

高并发下之redis锁优化实战
![[graphics] hair simulation in tressfx](/img/41/cef55811463d3a25a29ddab5278af0.jpg)
[graphics] hair simulation in tressfx

Influxdb2 sources add data sources
随机推荐
Global and Chinese market of optical fiber connectors 2022-2028: Research Report on technology, participants, trends, market size and share
Leetcode sword offer find the number I (nine) in the sorted array
Vs+qt application development, set software icon icon
Global and Chinese market of marketing automation 2022-2028: Research Report on technology, participants, trends, market size and share
链表有环,快慢指针走3步可以吗
Web server code parsing - thread pool
The method of parameter estimation of user-defined function in MATLAB
Yolov5系列(一)——网络可视化工具netron
406. 根据身高重建队列
Relationship between truncated random distribution and original distribution
Didi off the shelf! Data security is national security
什么是embedding(把物体编码为一个低维稠密向量),pytorch中nn.Embedding原理及使用
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
开启 Chrome 和 Edge 浏览器多线程下载
Search in the two-dimensional array of leetcode sword offer (10)
Chapter 04_ Logical architecture
什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
Tensor 省略号(三个点)切片
复合类型(自定义类型)
[graphics] efficient target deformation animation based on OpenGL es 3.0