当前位置:网站首页>Halcon and WinForm study section 1
Halcon and WinForm study section 1
2022-07-03 15:18:00 【11eleven】
Study halcon Of HWindowControl Use of control
List of articles
- List of articles
- Preface
- One 、Halcon What is it? ?
- Two 、 Use steps
Preface
With the development of industrial automation, the scene of visual inspection application has also become broad , This is the birth of halcon Such an application , It integrates common operator algorithms , So that general projects can be delivered quickly , Here is the first section of study
One 、Halcon What is it? ?
HALCON yes Software widely used in the field of industrial automation , Application software that can quickly and effectively solve image processing problems .
Two 、 Use steps
1. install
Go to the official website to download and install , After installation, you can find it in the directory DLL.
2. Import and stock in
The code is as follows ( Example ):halcondotnet.dll
using HalconDotNet;
3. Control use
After importing the library HWindowControl Can be directly in winform As shown in the figure

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); // Get the coordinate value of the current mouse
if (imageHeight != null && (row > 0 && row < imageHeight) && (column > 0 && column < imageWidth))// Set up 3 Conditions , Prevent the program from crashing .
{
HOperatorSet.GetGrayval(ho_image, row, column, out pointGray); // Get the gray value of the current point
}
else
{
pointGray = "_";
}
String str = String.Format("Row:{0} Column:{1} Gray:{2}", row, column, pointGray); // Formatted string
//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; // The line coordinates when the mouse is up minus the line coordinates when the mouse is down , Get the moving value of the row coordinates
double colMove = column - colDown;// The column coordinates when the mouse is up minus the column coordinates when the mouse is down , Get the movement value of column coordinates
HOperatorSet.GetPart(windowID, out row1, out col1, out row2, out col2);// Get the current window coordinates
HOperatorSet.SetPart(windowID, row1 - rowMove, col1 - colMove, row2 - rowMove, col2 - colMove);// There may be something difficult to understand . Take the origin of the upper left corner as the reference point
HOperatorSet.ClearWindow(windowID);
if (imageHeight != null)
{
HOperatorSet.DispObj(ho_image, windowID);
}
else
{
MyMessageBox.ShowAlert(" Please load an image first ");
}
}
catch {
}
}
private void HWindowControl1_HMouseDown(object sender, HMouseEventArgs e)
{
HTuple row, column, button;
HOperatorSet.GetMposition(windowID, out row, out column, out button);
rowDown = row; // Row coordinates when the mouse is pressed
colDown = column; // Column coordinates when the mouse is pressed
}
public HTuple windowID, imageWidth, imageHeight;
private double rowDown;// Row coordinates when the mouse is pressed
private double colDown;// Column coordinates when the mouse is pressed
public HObject ho_image; // Image variables
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)// Normal version halcon The maximum size of the image that can be processed is 32K*32K. If you infinitely reduce the original image , Cause the displayed image to exceed the limit , Will cause the program to crash
{
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);
}
}
}
}
summary
That's all halcon The first section of the introduction , Installation and dll Library reference , Control .
边栏推荐
- Mmdetection learning rate and batch_ Size relationship
- Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)
- 【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器
- Tensorflow realizes verification code recognition (I)
- Using TCL (tool command language) to manage Tornado (for VxWorks) can start the project
- Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)
- 高并发下之redis锁优化实战
- Jvm-02-class loading subsystem
- Idea does not specify an output path for the module
- Redis lock Optimization Practice issued by gaobingfa
猜你喜欢

GCC cannot find the library file after specifying the link library path

Redis lock Optimization Practice issued by gaobingfa

mysql innodb 存储引擎的特性—行锁剖析

Unity hierarchical bounding box AABB tree
![[cloud native training camp] module VIII kubernetes life cycle management and service discovery](/img/87/92638402820b32a15383f19f6f8b91.png)
[cloud native training camp] module VIII kubernetes life cycle management and service discovery

百度智能云助力石嘴山市升级“互联网+养老服务”智慧康养新模式

Jvm-09 byte code introduction

Redis主从、哨兵、集群模式介绍

第04章_逻辑架构

Incluxdb2 buckets create database
随机推荐
redis单线程问题强制梳理门外汉扫盲
Chapter 04_ Logical architecture
[pytorch learning notes] datasets and dataloaders
Analysis of development mode process based on SVN branch
Global and Chinese market of trimethylamine 2022-2028: Research Report on technology, participants, trends, market size and share
解决pushgateway数据多次推送会覆盖的问题
Qt常用语句备忘
Kubernetes advanced training camp pod Foundation
Kubernetes will show you from beginning to end
redis缓存穿透,缓存击穿,缓存雪崩解决方案
【云原生训练营】模块八 Kubernetes 生命周期管理和服务发现
Redis主从、哨兵、集群模式介绍
Jvm-05-object, direct memory, string constant pool
XWiki Installation Tips
Tensor ellipsis (three points) slice
Global and Chinese markets for sterile packaging 2022-2028: Research Report on technology, participants, trends, market size and share
There are links in the linked list. Can you walk three steps faster or slower
[combinatorics] permutation and combination (set permutation, step-by-step processing example)
开启 Chrome 和 Edge 浏览器多线程下载
Functional modules and application scenarios covered by the productization of user portraits