這是一個測驗案例,采用c++將opencv中的imread封裝成為一個dll,讓后,利用c#呼叫,但是,c#呼叫時始終無法呼叫封裝完成后的imread函式。有沒有人知道這是什么原因,謝謝啦!
#include<memory.h>
#include<time.h>
#include<math.h>
#include<vector>
#include"test.h"
#pragma comment(lib,"opencv_world310.lib")
using namespace cv;
using namespace std;
extern "C" __declspec(dllexport) int test()
{
Mat readImage = imread("D:\\pic\\pic1.JPG");
int rowPic = readImage.rows;
return rowPic;
}
然后利用c#呼叫
[c# code]-Call the test.dll
namespace testOilDetectionCsharp
{
public sealed partial class MainPage : Page
{
[DllImport("test.dll", CharSet = CharSet.Unicode)]
extern static int test();
public MainPage()
{
this.InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
unsafe
{
int num = test();
textBox.Text = num.ToString();
}
}
}
}
理論上,imread函式讀取了圖片資料后,c#呼叫回傳圖片的行數,但是,實際上并沒有回傳預期的值,它始侄訓傳0值,不知道為什么c#呼叫不了經過封裝后的opencv
uj5u.com熱心網友回復:
樓主有答案了嗎,我現在也是這樣
uj5u.com熱心網友回復:
額,我這邊出現這樣的問題是因為opencv編譯的版本問題,這個版本存在一點問題,換另一個版本就可以呼叫成功,你可以試試換個版本看看
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/284661.html
標籤:C++ 語言
