当前位置:网站首页>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 .
边栏推荐
- Functional modules and application scenarios covered by the productization of user portraits
- [transform] [NLP] first proposed transformer. The 2017 paper "attention is all you need" by Google brain team
- SQL server安装位置改不了
- What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry
- 【pytorch学习笔记】Transforms
- Using multipleoutputs to output multiple files in MapReduce
- 函数栈帧的创建和销毁
- qt使用QZxing生成二维码
- Composite type (custom type)
- Global and Chinese market of marketing automation 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
基础SQL教程
Introduction, use and principle of synchronized
北京共有产权房出租新规实施的租赁案例
Besides lying flat, what else can a 27 year old do in life?
Idea does not specify an output path for the module
Chapter 04_ Logical architecture
【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
Finally, someone explained the financial risk management clearly
Didi off the shelf! Data security is national security
随机推荐
Yolov5 series (I) -- network visualization tool netron
视觉上位系统设计开发(halcon-winform)
Using TCL (tool command language) to manage Tornado (for VxWorks) can start the project
视觉上位系统设计开发(halcon-winform)-6.节点与宫格
Relationship between truncated random distribution and original distribution
Besides lying flat, what else can a 27 year old do in life?
Explanation of time complexity and space complexity
PyTorch crop images differentiablly
leetcode_ Power of Four
Troubleshooting method of CPU surge
Matlab r2011b neural network toolbox precautions
基于SVN分支开发模式流程浅析
Jvm-02-class loading subsystem
XWiki安装使用技巧
Série yolov5 (i) - - netron, un outil de visualisation de réseau
Chapter 04_ Logical architecture
视觉上位系统设计开发(halcon-winform)-1.流程节点设计
"Seven weapons" in the "treasure chest" of machine learning: Zhou Zhihua leads the publication of the new book "machine learning theory guide"
Dataframe returns the whole row according to the value
Summary of concurrent full knowledge points