码迷,mamicode.com
首页 > 其他好文 > 详细

制作动态链接库给opencv程序使用(使用QtCreator)

时间:2014-12-29 18:09:18      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

新建一个c++库项目

技术分享

技术分享

 

pro文件

#-------------------------------------------------
#
# Project created by QtCreator 2014-12-29T16:10:53
#
#-------------------------------------------------

QT       -= core gui

TARGET = dlldemo
TEMPLATE = lib
CONFIG += staticlib

SOURCES += dlldemo.cpp

HEADERS += dlldemo.h


INCLUDEPATH += D:/sdk/opencv/build/include

LIBS += -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

unix {
    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     -ldlldemo


INCLUDEPATH += D:/sdk/opencv/build/include

LIBS += -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)

标签:

原文地址:http://www.cnblogs.com/yuliyang/p/4192020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!