当前位置:网站首页>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 .
边栏推荐
- Global and Chinese market of postal automation systems 2022-2028: Research Report on technology, participants, trends, market size and share
- 【pytorch学习笔记】Transforms
- There are links in the linked list. Can you walk three steps faster or slower
- What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry
- 百度智能云助力石嘴山市升级“互联网+养老服务”智慧康养新模式
- 解决pushgateway数据多次推送会覆盖的问题
- . Net six design principles personal vernacular understanding, please correct if there is any error
- 函数栈帧的创建和销毁
- Solve the problem that pushgateway data will be overwritten by multiple push
- Kubernetes will show you from beginning to end
猜你喜欢
Tensorflow realizes verification code recognition (I)
Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)
视觉上位系统设计开发(halcon-winform)-5.相机
MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)
Jvm-06-execution engine
Concurrency-02-visibility, atomicity, orderliness, volatile, CAS, atomic class, unsafe
第04章_逻辑架构
[cloud native training camp] module VIII kubernetes life cycle management and service discovery
[pytorch learning notes] datasets and dataloaders
Pytoch deep learning and target detection practice notes
随机推荐
Global and Chinese market of lighting control components 2022-2028: Research Report on technology, participants, trends, market size and share
Introduction, use and principle of synchronized
基础SQL教程
There are links in the linked list. Can you walk three steps faster or slower
Global and Chinese market of Bus HVAC systems 2022-2028: Research Report on technology, participants, trends, market size and share
Jvm-04-runtime data area heap, method area
Kubernetes vous emmène du début à la fin
Using Tengine to solve the session problem of load balancing
Kubernetes带你从头到尾捋一遍
Kubernetes advanced training camp pod Foundation
Jvm-09 byte code introduction
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
socket.io搭建分布式Web推送服务器
Global and Chinese market of trimethylamine 2022-2028: Research Report on technology, participants, trends, market size and share
Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)
【pytorch学习笔记】Transforms
Yolov5 series (I) -- network visualization tool netron
Nppexec get process return code
求字符串函数和长度不受限制的字符串函数的详解
什么是one-hot encoding?Pytorch中,将label变成one hot编码的两种方式