Halcon 联合C# 编程实验

本文介绍了如何使用Halcon在C#中实现摄像头捕获、图像预处理、边缘检测,并展示了仿射变换和XLD轮廓提取技术。通过实例代码展示了从打开相机到显示处理结果的全过程。

Halcon中 有两种参数类型:
分为 Iconic 与 Control. Iconic 为图片, control 为a1 b2
这两种, 每一种又分为输入和输出两种参数

固定参数顺序
input Iconic
output Iconic
input control
output control

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 转换为 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 设置图片与窗口等比例
        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;
            /
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潘诺西亚的火山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值