当前位置:网站首页>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库引用,控件的引入。
边栏推荐
- Remote server background hangs nohup
- Relationship between truncated random distribution and original distribution
- "Seven weapons" in the "treasure chest" of machine learning: Zhou Zhihua leads the publication of the new book "machine learning theory guide"
- Global and Chinese markets for transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share
- 运维体系的构建
- Besides lying flat, what else can a 27 year old do in life?
- 【可能是全中文网最全】pushgateway入门笔记
- redis缓存穿透,缓存击穿,缓存雪崩解决方案
- Zero copy underlying analysis
- Yolov5 advanced 8 format conversion between high and low versions
猜你喜欢

5.2-5.3

Zero copy underlying analysis

【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》

CentOS7部署哨兵Redis(带架构图,清晰易懂)

Incluxdb2 buckets create database
![Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)](/img/cd/2e4f5884d034ff704809f476bda288.png)
Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)

Série yolov5 (i) - - netron, un outil de visualisation de réseau
![[engine development] rendering architecture and advanced graphics programming](/img/a4/3526a4e0f68e49c1aa5ce23b578781.jpg)
[engine development] rendering architecture and advanced graphics programming
![[transform] [NLP] first proposed transformer. The 2017 paper](/img/33/f639ab527d5adedfdc39f8d8117c3e.png)
[transform] [NLP] first proposed transformer. The 2017 paper "attention is all you need" by Google brain team

Tencent internship interview sorting
随机推荐
【注意力机制】【首篇ViT】DETR,End-to-End Object Detection with Transformers网络的主要组成是CNN和Transformer
SQL server installation location cannot be changed
Troubleshooting method of CPU surge
[engine development] in depth GPU and rendering optimization (basic)
官网MapReduce实例代码详细批注
. Net six design principles personal vernacular understanding, please correct if there is any error
Explanation of time complexity and space complexity
4-29——4.32
[wechat applet] wxss template style
Open under vs2019 UI file QT designer flash back problem
Mmdetection learning rate and batch_ Size relationship
Pytoch deep learning and target detection practice notes
什么是one-hot encoding?Pytorch中,将label变成one hot编码的两种方式
什么是embedding(把物体编码为一个低维稠密向量),pytorch中nn.Embedding原理及使用
基础SQL教程
Construction of operation and maintenance system
Global and Chinese market of trimethylamine 2022-2028: Research Report on technology, participants, trends, market size and share
开启 Chrome 和 Edge 浏览器多线程下载
Neon global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share