当前位置:网站首页>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 .
边栏推荐
- Tensorflow realizes verification code recognition (I)
- socket.io搭建分布式Web推送服务器
- [combinatorics] permutation and combination (set permutation, step-by-step processing example)
- 视觉上位系统设计开发(halcon-winform)-2.全局变量设计
- Finally, someone explained the financial risk management clearly
- [transform] [NLP] first proposed transformer. The 2017 paper "attention is all you need" by Google brain team
- Detailed comments on MapReduce instance code on the official website
- 视觉上位系统设计开发(halcon-winform)-5.相机
- Search in the two-dimensional array of leetcode sword offer (10)
- Summary of JVM knowledge points
猜你喜欢
The state does not change after the assignment of El switch
求字符串函数和长度不受限制的字符串函数的详解
qt使用QZxing生成二维码
【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器
Popular understanding of linear regression (I)
Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)
Incluxdb2 buckets create database
"Seven weapons" in the "treasure chest" of machine learning: Zhou Zhihua leads the publication of the new book "machine learning theory guide"
什么是one-hot encoding?Pytorch中,将label变成one hot编码的两种方式
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
随机推荐
Global and Chinese market of postal automation systems 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
What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
开启 Chrome 和 Edge 浏览器多线程下载
Popular understanding of gradient descent
Redis cache penetration, cache breakdown, cache avalanche solution
Global and Chinese markets for transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for infrared solutions (for industrial, civil, national defense and security applications) 2022-2028: Research Report on technology, participants, trends, market size and sh
Yolov5 advanced seven target tracking latest environment construction (II)
PyTorch crop images differentiablly
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
Functional modules and application scenarios covered by the productization of user portraits
Global and Chinese market of air cargo logistics 2022-2028: Research Report on technology, participants, trends, market size and share
Kubernetes帶你從頭到尾捋一遍
Redis lock Optimization Practice issued by gaobingfa
[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University
mysql innodb 存储引擎的特性—行锁剖析
Didi off the shelf! Data security is national security
Enable multi-threaded download of chrome and edge browsers
Introduction, use and principle of synchronized