请选择 进入手机版 | 继续访问电脑版

Hello Mat

 找回密码
 立即注册
查看: 10585|回复: 5

原因可能是托管的PInvoke签名与非托管的目标签名不匹配

[复制链接]

1278

主题

1504

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22549
发表于 2017-2-8 22:37:31 | 显示全部楼层 |阅读模式

LoadDLL.cs
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;

  6. using HalconDotNet;
  7. using System.Runtime.InteropServices;

  8. namespace CED_CSharp
  9. {
  10.     class LoadDLL
  11.     {
  12.         // DLL名称
  13.         const string AlgorithmName = "CED.dll";

  14.         [DllImport(AlgorithmName, EntryPoint = "SetLogPath")]
  15.         public static extern void SetLogPath(string path);

  16.         [DllImport(AlgorithmName, EntryPoint = "SetRootDir")]
  17.         public static extern void SetRootDir(string dir);

  18.         [DllImport(AlgorithmName, EntryPoint = "InitLoadDLL")]
  19.         public static extern void InitLoadDLL();

  20.         [DllImport(AlgorithmName, EntryPoint = "CED_LoG_Bridge", CallingConvention = CallingConvention.Cdecl )]
  21.         private static extern bool CED_LoG_Bridge(long ho_Image, out long ho_ImageCED, out long ho_DiffOfGauss, long hv_Sigma1, long hv_Sigma2);

  22.         public static bool CED_LoG(HObject ho_Image, out HObject ho_ImageCED, out HObject ho_DiffOfGauss, HTuple hv_Sigma1, HTuple hv_Sigma2)
  23.         {
  24.             HTuple image, sigma1, sigma2;
  25.             long imageCED, imageLoG;
  26.             HOperatorSet.SerializeObject(ho_Image, out image);
  27.             HOperatorSet.SerializeTuple(hv_Sigma1, out sigma1);
  28.             HOperatorSet.SerializeTuple(hv_Sigma2, out sigma2);
  29.             if (CED_LoG_Bridge(image, out imageCED, out imageLoG, sigma1, sigma2))
  30.             {
  31.                 HOperatorSet.DeserializeObject(out ho_ImageCED, imageCED);
  32.                 HOperatorSet.DeserializeObject(out ho_DiffOfGauss, imageLoG);
  33.                 return true;
  34.             }
  35.             else
  36.             {
  37.                 HOperatorSet.GenEmptyObj(out ho_ImageCED);
  38.                 HOperatorSet.GenEmptyObj(out ho_DiffOfGauss);
  39.                 return false;
  40.             }

  41.         }

  42.     }
  43. }
复制代码
算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

1278

主题

1504

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22549
 楼主| 发表于 2017-11-9 23:40:48 | 显示全部楼层
对输出变量imageCED、imageLoG应该进行内存销毁。

在if内部,添加:
HOperatorSet.ClearSerializedItem(imageCED);
HOperatorSet.ClearSerializedItem(imageLoG);

避免内存溢出。


算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复 支持 反对

使用道具 举报

0

主题

4

帖子

13

金钱

新手上路

Rank: 1

积分
17
发表于 2018-12-13 13:21:46 | 显示全部楼层
谢谢大师傅的分享,我现在在学习
回复 支持 反对

使用道具 举报

0

主题

2

帖子

20

金钱

新手上路

Rank: 1

积分
22
发表于 2020-2-9 10:43:54 | 显示全部楼层
谢谢分享!
回复

使用道具 举报

0

主题

1

帖子

0

金钱

新手上路

Rank: 1

积分
4
发表于 2023-6-26 00:53:39 | 显示全部楼层

谢谢分享!
回复

使用道具 举报

0

主题

2

帖子

0

金钱

新手上路

Rank: 1

积分
8
发表于 2023-10-23 15:06:39 | 显示全部楼层
谢谢分享,学习学习!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-3-29 03:59 , Processed in 0.222701 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表