Making a dynamic link library for use with OPENCV programs (using Qtcreator)

Source: Internet
Author: User



Create a new C + + library project












Pro File


#-------------------------------------------------# # Project created by Qtcreator the- A-29t16:Ten: -##-------------------------------------------------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#defineDlldemo_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 namespacestd;using namespaceCV;classdlldemo{ Public: Dlldemo (); intAddtwointAintb);    Mat Togray (Mat img); voidDraw_text (Cv::mat &canvas,Const Char*STR,intXintYfloatScale =1.0);};#endif //Dlldemo_h


Dlldemo.cpp


#include"dlldemo.h"Dlldemo::D Lldemo () {}intDlldemo::addtwo (intAintb) { returnA +b;}    Mat Dlldemo::togray (Mat img) {Cv::mat greymat;    Cv::cvtcolor (IMG, Greymat, Cv_bgr2gray); Draw_text (Greymat,"#by DLL Function",5, -,0.8); returnGreymat;}voidDlldemo::d raw_text (Mat &canvas,Const Char*STR,intXintYfloatScale ) { intW =2;  for(intDY =-W; Dy <= W; ++dy) {  for(intDX =-W; DX <= W; ++dx) {CV::p uttext (canvas, str, CV::P oint (x+dx,y+dy), Cv::font_hershey_simplex, scale, cv::scalar (0,0,0),2, CV_AA); }} CV::p uttext (canvas, str, CV::P oint (x, y), Cv::font_hershey_simplex, scale, cv::scalar (255,255,255),2, CV_AA);}


Build---> Build






Test



Create a new C + + project



Copy dlldemo.h and Dlldemo.lib






Modify the Pro file


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


Test Code Main.cpp


#include <iostream>#include"dlldemo.h"using namespacestd;intMain () {cout<<"Hello world!"<<Endl; intA=Ten; intb= -;    Dlldemo dll; printf ("sum of A, B is:%d", Dll.addtwo (A, b));    Cv::mat Canvas; Canvas= Cv::imread ("d://lining.jpg", -1); Mat result=Dll.togray (canvas); Imshow ("DLL Result", result);    Waitkey (); return 0;}





Success









SOURCE download



Http://pan.baidu.com/s/1kT7QBbx






Making a dynamic link library for use with OPENCV programs (using Qtcreator)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.