首页 > 代码库 > 制作动态链接库给opencv程序使用(使用QtCreator)
制作动态链接库给opencv程序使用(使用QtCreator)
新建一个c++库项目
pro文件
#-------------------------------------------------## Project created by QtCreator 2014-12-29T16:10:53##-------------------------------------------------QT -= core guiTARGET = dlldemoTEMPLATE = libCONFIG += staticlibSOURCES += dlldemo.cppHEADERS += dlldemo.hINCLUDEPATH += D:/sdk/opencv/build/includeLIBS += -LD:/sdk/opencv/build/x86/vc12/lib -lopencv_calib3d249d -lopencv_contrib249d -lopencv_core249d -lopencv_features2d249d -lopencv_flann249d -lopencv_gpu249d -lopencv_highgui249d -lopencv_imgproc249d -lopencv_legacy249d -lopencv_ml249d -lopencv_nonfree249d -lopencv_objdetect249d -lopencv_ocl249d -lopencv_photo249d -lopencv_stitching249d -lopencv_superres249d -lopencv_ts249d -lopencv_video249d -lopencv_videostab249dunix { target.path = /usr/lib INSTALLS += target}
dlldemo.h
#ifndef DLLDEMO_H#define DLLDEMO_H#include <iostream>#include <fstream>#include <sstream>#include <string>#include <vector>#include <opencv2/objdetect/objdetect.hpp>#include <opencv2/highgui/highgui.hpp>#include <opencv2/imgproc/imgproc.hpp>#include <opencv2/core/core.hpp>using namespace std;using namespace cv;class Dlldemo{public: Dlldemo(); int addtwo(int a,int b); Mat togray(Mat img); void draw_text(cv::Mat &canvas, const char *str, int x, int y, float scale = 1.0);};#endif // DLLDEMO_H
dlldemo.cpp
#include "dlldemo.h"Dlldemo::Dlldemo(){}int Dlldemo::addtwo(int a, int b){ return a+b;}Mat Dlldemo::togray(Mat img){ cv::Mat greyMat; cv::cvtColor(img, greyMat, CV_BGR2GRAY); draw_text (greyMat,"#by dll function", 5, 30,0.8); return greyMat;}void Dlldemo::draw_text(Mat &canvas, const char *str, int x, int y, float scale){ int w = 2; for(int dy = -w; dy <= w; ++dy) { for (int dx = -w; dx <= w; ++dx) { cv::putText(canvas, str, cv::Point(x+dx,y+dy), cv::FONT_HERSHEY_SIMPLEX, scale, cv::Scalar(0,0,0), 2, CV_AA); } } cv::putText(canvas, str, cv::Point(x,y), cv::FONT_HERSHEY_SIMPLEX, scale, cv::Scalar(255,255,255), 2, CV_AA);}
build--->生成
测试
新建一个c++工程
拷贝dlldemo.h 和dlldemo.lib
修改pro文件
LIBS += -LD:/project/testdlldemo -ldlldemoINCLUDEPATH += D:/sdk/opencv/build/includeLIBS += -LD:/sdk/opencv/build/x86/vc12/lib -lopencv_calib3d249d -lopencv_contrib249d -lopencv_core249d -lopencv_features2d249d -lopencv_flann249d -lopencv_gpu249d -lopencv_highgui249d -lopencv_imgproc249d -lopencv_legacy249d -lopencv_ml249d -lopencv_nonfree249d -lopencv_objdetect249d -lopencv_ocl249d -lopencv_photo249d -lopencv_stitching249d -lopencv_superres249d -lopencv_ts249d -lopencv_video249d -lopencv_videostab249d
测试代码main.cpp
#include <iostream>#include "dlldemo.h"using namespace std;int main(){ cout << "Hello World!" << endl; int a=10; int b=20; Dlldemo dll; printf("sum of a,b is :%d",dll.addtwo (a,b)); cv::Mat canvas; canvas = cv::imread("d://nike.jpg", -1); Mat result= dll.togray (canvas); imshow ("dll result",result); waitKey (); return 0;}
成功
源码下载
http://pan.baidu.com/s/1kT7QBbx
制作动态链接库给opencv程序使用(使用QtCreator)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。