Halcom 发表于 2017-2-9 22:33:27

C#调用C++版halcon生成的dll

halcon生成C++版代码,封装为dll,供C#调用:
具体链接:
**** Hidden Message *****
C#窗体程序--调用代码:
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 HalconDotNet;
using System.Runtime.InteropServices;

namespace CED_CSharp
{
    public partial class Form1 : Form
    {
      public Form1()
      {
            InitializeComponent();
      }

      private void button1_Click(object sender, EventArgs e)
      {
            HObject ho_Image,ho_GrayImage, ho_ImageCED, ho_DiffOfGauss;
            HTuple ImagePath = @"C:/Users/ysw/Desktop/视频讲解/图像处理视频Halcon/Halcon图像处理-edit/logo3.jpg";
            HTuple hv_Width = null, hv_Height = null, hv_Sigma1 = null, hv_Sigma2 = null;

            HOperatorSet.ReadImage(out ho_Image, ImagePath);
            HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage);
            HOperatorSet.GetImageSize(ho_GrayImage, out hv_Width, out hv_Height);
            hv_Sigma1 = 0.5;
            hv_Sigma2 = 3;
            HOperatorSet.GenEmptyObj(out ho_ImageCED);
            HOperatorSet.GenEmptyObj(out ho_DiffOfGauss);
            if (CED_CSharp.LoadDLL.CED_LoG(ho_Image, out ho_ImageCED, out ho_DiffOfGauss, hv_Sigma1, hv_Sigma2))
            {
                HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, hv_Height - 1, hv_Width - 1);
                HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);

                HOperatorSet.SetPart(hWindowControl2.HalconWindow, 0, 0, hv_Height - 1, hv_Width - 1);
                HOperatorSet.DispObj(ho_ImageCED, hWindowControl2.HalconWindow);

                HOperatorSet.SetPart(hWindowControl3.HalconWindow, 0, 0, hv_Height - 1, hv_Width - 1);
                HOperatorSet.DispObj(ho_DiffOfGauss, hWindowControl3.HalconWindow);
            }
            else
            {
                MessageBox.Show("CED_LoG算法调用有误!!!");
            }

            //HOperatorSet.CoherenceEnhancingDiff(ho_Image, out ho_ImageCED, hv_Sigma1, 4, 0.5, 50);
            //HOperatorSet.DiffOfGauss(ho_ImageCED, out ho_DiffOfGauss, hv_Sigma2, 1.6);

            //HOperatorSet.SetPart(hWindowControl2.HalconWindow, 0, 0, hv_Height - 1, hv_Width - 1);
            //HOperatorSet.DispObj(ho_ImageCED, hWindowControl2.HalconWindow);

            //HOperatorSet.SetPart(hWindowControl3.HalconWindow, 0, 0, hv_Height - 1, hv_Width - 1);
            //HOperatorSet.DispObj(ho_DiffOfGauss, hWindowControl3.HalconWindow);


      }
    }
}

jamesyjw 发表于 2017-10-21 13:53:58

看看,最近正好用到!

xiechao 发表于 2018-12-13 14:24:21

看看,现在一直在研究,还没有搞明白,谢谢分享

xiechao 发表于 2018-12-13 14:25:38

谢谢大师傅的分享,我现在封装了一个DLL,DLL里面的参数有HObject,程序运行总是报错误,不知道怎么办,能不能指导下我,我这边付费的,谢谢

Halcom 发表于 2019-1-20 22:55:28

xiechao 发表于 2018-12-13 14:25
谢谢大师傅的分享,我现在封装了一个DLL,DLL里面的参数有HObject,程序运行总是报错误,不知道怎么办,能 ...

你看一下我对应的链接,谢谢

yjlft 发表于 2020-1-12 15:03:29

谢谢,学习一下。

brian 发表于 2020-2-9 10:42:54

学习一下,谢谢

李先生 发表于 2020-5-4 16:05:55

感谢分享,非常棒的学习资料

cacalu123 发表于 2021-3-12 14:34:10

看看,最近正好用到!

sefule@163.com 发表于 2023-10-24 14:28:27

没有C++代码,不是一个完整示例。
页: [1]
查看完整版本: C#调用C++版halcon生成的dll