关于封装C++函数中调用了opencv的函数的封装问题

关于封装C++函数中调用了opencv的函数的封装问题

转载请注明来源,谢谢合作!

//DLL的头文件----------------------------------------------------------------------------


#pragma once
#include <opencv2\highgui\highgui.hpp>
#include <opencv2/core/core.hpp>
#include <string>

using namespace cv;
using namespace std;

extern "C" _declspec(dllexport)void showimage(string name);

//DLL的源文件----------------------------------------------------------------------------


#include"Add.h"


void showimage(string name) {
	Mat img = imread(name, 1);
	imshow("picture", img);
	waitKey(0);
}

//主函数----------------------------------------------------------------------------


#include<iostream>
//#include <opencv2\highgui\highgui.hpp>
//#include <opencv2/core/core.hpp>
#include <string>
//#include"Add.h"
#pragma comment(lib,"Add.lib")//导入库文件


using namespace  std;
//using namespace cv;

extern "C" _declspec(dllimport)void showimage(string name);

/*
void showimage(String name) {
	Mat img = imread(name, 1);
	imshow("picture", img);
	waitKey(0);
}*/

int main() {
	string str;
	getline(cin, str);
	showimage(str);
	return 0;
}

结果--------------------------------------------------------------------------
关于封装C++函数中调用了opencv的函数的封装问题

以上是对于opencv封装的一个小的demo,在这里封装使用的是x64的环境,并且系统会自动将我们调用的opencv中的函数一起封装进来。我们在int main 的主函数中不需要再调用opencv的库了。