C#怎么调用C++的dll,dll函数的输入类型是Mat(或者是const char*)

pixian0237 2017-04-08 05:08:48
现在我用C#调用dll出现了问题,当我把dll函数的输入类型改为const char*的时候,出现的问题就是

其中我的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 System.Threading;
using System.Runtime.InteropServices;
using System.IO;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
[DllImport("smallT_BJ.dll", EntryPoint = "?smallTarget@@YA?AV?$Point_@H@cv@@PBD@Z")]
public static extern Point smallTarget(string path);
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string path =" C:\\1.bmp";
Point point = new Point();
point = smallTarget(path);
}
}
}


C++的h文件的内容如下

#include <windows.h>
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <opencv2\opencv.hpp>
#include <fstream>
#include <memory>
#include <stdlib.h>
#include <math.h>
#include <time.h>

using namespace std;
using namespace cv;

#ifdef SMALLT_BJ_EXPORTS
#define SMALLT_BJ_API __declspec(dllexport)
#else
#define SMALLT_BJ_API __declspec(dllimport)
#endif

SMALLT_BJ_API Mat filters(Mat source, int thresholdin);

SMALLT_BJ_API Mat filterspatial2(Mat source, int th);

SMALLT_BJ_API void cmedian(Mat src, Mat dst, int innerbox_size, int outerbox_size);

SMALLT_BJ_API Mat prefilter(Mat source);

SMALLT_BJ_API vector<Mat> getSuspects(Mat& frame, Mat src, int box_size, vector<Point>& LeftUpPoints, vector<vector<Point>>& cont);

SMALLT_BJ_API Point smallTarget(const char* file);

我也可以把 smallTarget函数的输入类型在原函数里面进行修改为Mat类型。现在是用Mat还是用const char*,怎么解决这个异常问题呢
...全文
284 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
lvjiyang 2020-07-31
  • 打赏
  • 举报
回复
博主,我也是一样的问题,你解决了吗?解决方法是什么呢?

4,248

社区成员

发帖
与我相关
我的任务
社区描述
OpenCV相关技术交流专区
计算机视觉人工智能opencv 技术论坛(原bbs) 广东省·深圳市
社区管理员
  • OpenCV
  • 幻灰龙
  • OpenCV中国团队
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

OpenCV中国团队官方博客:https://blog.csdn.net/opencvchina

试试用AI创作助手写篇文章吧