OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 4456|回复: 0

【求助】c++封装opencv成为dll给c#调用

[复制链接]
发表于 2019-11-6 20:29:45 | 显示全部楼层 |阅读模式
本帖最后由 Harpery 于 2019-11-6 20:46 编辑

c++封装opencv的imread函数,作为一个测试调用案例,但是,在c#调用的时候,始终无法调用imread函数读取图片,问一下,有没有大牛知道?谢谢啦!
这是c++中封装的代码dll2.cpp
  1. #include "pch.h"
  2. #include "Dll2.h"
  3. #include<Windows.h>
  4. #include"opencv2/opencv.hpp"
  5. #include"opencv2/core/eigen.hpp"
  6. #include<iostream>
  7. #include<stdlib.h>
  8. #pragma comment(lib,"opencv_world310.lib")

  9. using namespace cv;
  10. using namespace std;
  11. using namespace Eigen;

  12. extern "C" __declspec(dllexport) int getReadPic()
  13. {
  14.         Mat readImage = imread("D:\\pic\\pic1.jpg");
  15.         int rowPic = 111111;
  16.         rowPic = readImage.rows;
  17.         return rowPic;
  18. }
复制代码
在c#里面调用
  1. public sealed partial class MainPage : Page
  2.     {
  3.     [DllImport("Dll2.dll", CharSet = CharSet.Unicode)]
  4.     extern static int getReadPic();
  5.     public MainPage()
  6.     {
  7.         this.InitializeComponent();
  8.     }

  9.     private void Button_Click(object sender, RoutedEventArgs e)
  10.     {
  11.         unsafe
  12.         {
  13.               int num = getReadPic();
  14.               textBox.Text = num.ToString();
  15.         }
  16.     }
  17.     }
复制代码


回复

使用道具 举报

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

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-3-29 01:25 , Processed in 0.013607 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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