当前位置:网站首页>Halcon joint C # Programming Experiment
Halcon joint C # Programming Experiment
2022-01-15 02:11:40 【La lave de Rodinia】
using HalconDotNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace CsharpHaldemon2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region HObject Convertir en HImage
private void HobjectToHimage(HObject hobject, ref HImage image)
{
HTuple pointer, type, width, height;
HOperatorSet.GetImagePointer1(hobject, out pointer, out type, out width, out height);
image.GenImage1(type, width, height, pointer);
}
#endregion
#region Définir l'image à l'échelle de la fenêtre
private void WindowAdaptation(int width,int height, out HTuple row1, out HTuple column1, out HTuple row2, out HTuple column2)
{
double ratioWidth = (1.0) * width / hWindowControl1.Width;
double ratioHeight = (1.0) * height / hWindowControl1.Height;
if (ratioWidth > ratioHeight)
{
row1 = -(1.0) * ((hWindowControl1.Height * ratioWidth) - height) / 2;
column1 = 0;
row2 = row1 + hWindowControl1.Height * ratioWidth;
column2 = column1 + hWindowControl1.Width * ratioWidth;
}
else
{
row1 = 0;
column1 = -(1.0) * ((hWindowControl1.Width * ratioHeight) - width) / 2;
row2 = row1 + hWindowControl1.Height * ratioHeight;
column2 = column1 + hWindowControl1.Width * ratioHeight;
}
}
#endregion
private CancellationTokenSource cts = new CancellationTokenSource();
private CancellationTokenSource cts1 = new CancellationTokenSource();
private void btnOpenPic_Click(object sender, EventArgs e)
{
//HObject ho_Image, ho_ROI_0, ho_Cross;
//HXLD
//HXLDCont
//HXLDPoly //HXLDContContour etHXLDPolyPolygone
//HImage ho_Image = new HImage();
//HRegion ho_ROI_0 = new HRegion(); //Région
//HXLDCont ho_Cross = new HXLDCont(); //Profil
//ho_Image.ReadImage(@"C:\Users\ZG\Pictures\claudia.png");
//ho_ROI_0.GenRectangle1(30.0, 20, 100, 200);
//hWindowControl1.HalconWindow.SetColor("blue");
//ho_ROI_0.DispRegion(hWindowControl1.HalconWindow);
//hWindowControl1.HalconWindow.SetColor("green");
//ho_Cross.GenCrossContourXld(180.0, 180, 61, 0.785398);
//ho_Cross.DispXld(hWindowControl1.HalconWindow);
//this.hSmartWindowControl1.SetFullImagePart(ho_Image);
//this.hSmartWindowControl1.HalconWindow.DispObj(ho_Image);
//this.hWindowControl1.SetFullImagePart(ho_Image);
//this.hWindowControl1.HalconWindow.DispObj(ho_Image);
HObject ho_Image;
HImage ho_Image1 = new HImage();
HXLDCont ho_Cross = new HXLDCont(); //Profil
HTuple hv_AcqHandle = new HTuple();
HTuple row1, column1, row2, column2;
int width, height;
Task.Run(() =>
{
HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb",
-1, "false", "default", "[0] Chicony USB2.0 Camera", 0, -1, out hv_AcqHandle);
HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
// Appelez la caméra pour obtenir des images asynchrones
HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
//Fermer la poignée
HOperatorSet.CloseFramegrabber(hv_AcqHandle);
//Prends ça.objDevientHimage
HobjectToHimage(ho_Image, ref ho_Image1);
// Obtenir la longueur et la largeur de l'image
ho_Image1.GetImageSize(out width, out height);
//XLDExtraction de bord
ho_Cross = ho_Image1.Rgb1ToGray().EdgesSubPix("canny", 2, 12, 22);
WindowAdaptation(width, height, out row1, out column1, out row2, out column2);
HOperatorSet.SetPart(hWindowControl1.HalconWindow, row1, column1, row2, column2);
//ho_Image1.DispImage(hWindowControl1.HalconWindow);
ho_Cross.DispXld(hWindowControl1.HalconWindow);
}, cts.Token);
}
//threshouldSegmentation des seuils
private void btnThreshold_Click(object sender, EventArgs e)
{
int width, height;
HTuple row1, column1, row2, column2;
HImage ho_Image = new HImage();
HRegion ho_ROI_0 = new HRegion();
ho_Image.ReadImage(@"C:/Users/ZG/Pictures/clip.png");
ho_Image.GetImageSize(out width, out height);
ho_ROI_0 = ho_Image.Rgb1ToGray().Threshold(0.0, 106).Connection().SelectShape("area", "and", 150, 99999);
WindowAdaptation(width, height, out row1, out column1, out row2, out column2);
hWindowControl1.HalconWindow.SetColor("blue");
HOperatorSet.SetPart(hWindowControl1.HalconWindow, row1, column1, row2, column2);
ho_ROI_0.DispRegion(hWindowControl1.HalconWindow);
}
private void picConvertXLD_Click(object sender, EventArgs e)
{
int width, height;
HTuple row1, column1, row2, column2;
HImage ho_Image = new HImage();
HRegion ho_ROI_0 = new HRegion();
HXLDCont ho_Cross = new HXLDCont(); //Profil
ho_Image.ReadImage(@"C:/Users/ZG/Pictures/fabrik.png");
ho_Cross = ho_Image.Rgb1ToGray().EdgesSubPix("canny", 2, 12, 22);
// Adapter la fenêtre
ho_Image.GetImageSize(out width, out height);
WindowAdaptation(width, height, out row1, out column1, out row2, out column2);
HOperatorSet.SetPart(hWindowControl1.HalconWindow, row1, column1, row2, column2);
ho_Cross.DispXld(hWindowControl1.HalconWindow);
}
private void btnThresholdMe_Click(object sender, EventArgs e)
{
HObject ho_Image;
HImage ho_Image1 = new HImage();
HRegion ho_ROI_0 = new HRegion();
HXLDCont ho_Cross = new HXLDCont(); //Profil
HTuple hv_AcqHandle = new HTuple();
HTuple row1, column1, row2, column2;
int width, height;
Task.Run(() =>
{
HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb",
-1, "false", "default", "[0] Chicony USB2.0 Camera", 0, -1, out hv_AcqHandle);
HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
// Appelez la caméra pour obtenir des images asynchrones
HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
//Fermer la poignée
HOperatorSet.CloseFramegrabber(hv_AcqHandle);
//Prends ça.objDevientHimage
HobjectToHimage(ho_Image, ref ho_Image1);
// Obtenir la longueur et la largeur de l'image
ho_Image1.GetImageSize(out width, out height);
//XLDExtraction de bord
ho_ROI_0 = ho_Image1.Rgb1ToGray().Threshold(75.0, 122).Connection().SelectShape("area", "and", 150, 46614.6);
WindowAdaptation(width, height, out row1, out column1, out row2, out column2);
HOperatorSet.SetPart(hWindowControl1.HalconWindow, row1, column1, row2, column2);
hWindowControl1.HalconWindow.SetColor("blue");
//ho_Image1.DispImage(hWindowControl1.HalconWindow);
ho_ROI_0.DispRegion(hWindowControl1.HalconWindow);
//ho_Cross.DispXld(hWindowControl1.HalconWindow);
}, cts1.Token);
}
}
#region Définir l'image à l'échelle de la fenêtre
//ho_Image.GetImageSize(out width, out height);
//double ratioWidth = (1.0) * width / hWindowControl1.Width;
//double ratioHeight = (1.0) * height / hWindowControl1.Height;
//if (ratioWidth > ratioHeight)
//{
// row1 = -(1.0) * ((hWindowControl1.Height * ratioWidth) - height) / 2;
// column1 = 0;
// row2 = row1 + hWindowControl1.Height * ratioWidth;
// column2 = column1 + hWindowControl1.Width * ratioWidth;
//}
//else
//{
// row1 = 0;
// column1 = -(1.0) * ((hWindowControl1.Width * ratioHeight) - width) / 2;
// row2 = row1 + hWindowControl1.Height * ratioHeight;
// column2 = column1 + hWindowControl1.Width * ratioHeight;
//}
#endregion
}
Extraction de sous - pixels de bord
版权声明
本文为[La lave de Rodinia]所创,转载请带上原文链接,感谢
https://chowdera.com/2022/01/202201080558306948.html
边栏推荐
猜你喜欢
随机推荐
- Jenkins 通过API获取从节点的secret
- 浅析npm run serve命令
- Push failed Dst refspec V1.0.0 matches more than one.
- 微服务系列--深入理解RPC底层原理与设计实践
- [highcharts] 04_ wrap
- (highly recommended) mobile audio and video from zero to start
- 微服務系列--深入理解RPC底層原理與設計實踐
- Push failed Dst refspec V1.0.0 matches more than one.
- Série de microservices - compréhension approfondie des principes sous - jacents et des pratiques de conception du CPR
- Push failed DST refspec v1. 0,0 matches more than one.
- Analyse de la commande NPM Run Service
- Jenkins obtient le secret du noeud via l'API
- Jenkins API Access Guide
- Quickly write a vs code plug-in
- Yyds dry goods inventory trunk (I)
- Modify a value to make Scrollview and listview elastic and APK volume optimized
- Jenkins exécute le script grovvy via l'API
- Jenkins configure l'affichage chinois (chinois)
- Jenkins Distributed Architecture
- Introduction à Jenkins
- Problème avec les demandes inter - domaines ne portant pas de cookies
- 数据分析八大模型:OGSM模型
- Appel asynchrone, Multithreading
- Android中的羊角符,面试看这个就够了
- Compréhension approfondie du Multithreading
- Utilisation de is et as
- Classe générique, interface générique
- Classe générique, héritage de l'interface générique, délégué
- Exercice de base de données d'accès
- Accès à la base de données SQL avec Multithreading, invoke et action
- Écrire et tester le Protocole Modbus
- . net how to connect to Youxuan database?
- Splitting e-commerce system into micro service
- Écrire un programme winform en utilisant plusieurs threads
- Déclarations SQL couramment utilisées
- Utilisez le texte. Json analyse le fichier json
- Plusieurs adresses de nuget
- Lire Modbus TCP avec nmodbus
- Module 6 operation of the actual combat camp
- TypeError: Object of type ‘TrackedArray‘ is not JSON serializable