当前位置:网站首页>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库引用,控件的引入。
边栏推荐
- [transform] [NLP] first proposed transformer. The 2017 paper "attention is all you need" by Google brain team
- Troubleshooting method of CPU surge
- mysql innodb 存储引擎的特性—行锁剖析
- Global and Chinese markets for flexible chips 2022-2028: Research Report on technology, participants, trends, market size and share
- el-switch 赋值后状态不变化
- 高并发下之redis锁优化实战
- Global and Chinese markets for ionization equipment 2022-2028: Research Report on technology, participants, trends, market size and share
- 【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器
- [attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
- Search in the two-dimensional array of leetcode sword offer (10)
猜你喜欢
[probably the most complete in Chinese] pushgateway entry notes
4-24--4-28
Composite type (custom type)
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器
Solve the problem that pushgateway data will be overwritten by multiple push
【微信小程序】WXSS 模板样式
[transformer] Introduction - the original author of Harvard NLP presented the annotated transformer in the form of line by line implementation in early 2018
第04章_逻辑架构
Vs+qt application development, set software icon icon
随机推荐
High quality workplace human beings must use software to recommend, and you certainly don't know the last one
[set theory] inclusion exclusion principle (complex example)
[transformer] Introduction - the original author of Harvard NLP presented the annotated transformer in the form of line by line implementation in early 2018
第04章_逻辑架构
视觉上位系统设计开发(halcon-winform)-6.节点与宫格
Chapter 04_ Logical architecture
什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
Yolov5系列(一)——網絡可視化工具netron
4-20-4-23 concurrent server, TCP state transition;
Redis主从、哨兵、集群模式介绍
【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
Yolov5进阶之八 高低版本格式转换问题
Influxdb2 sources add data sources
CentOS7部署哨兵Redis(带架构图,清晰易懂)
使用JMeter对WebService进行压力测试
Stress test WebService with JMeter
What is machine reading comprehension? What are the applications? Finally someone made it clear
Devaxpress: range selection control rangecontrol uses
[engine development] in depth GPU and rendering optimization (basic)