1.在qt工程中选择添加静态库(windows)
根据实际路径稍作修改即可
LIBS += -L$$PWD/../opencv/mingw-x64/ -lopencv_core
LIBS += -L$$PWD/../opencv/mingw-x64/ -lopencv_imgproc
LIBS += -L$$PWD/../opencv/mingw-x64/ -lopencv_photo
INCLUDEPATH += $$PWD/../opencv/include
DEPENDPATH += $$PWD/../opencv/mingw-x64
PRE_TARGETDEPS += $$PWD/../opencv/mingw-x64/libopencv_core.a
PRE_TARGETDEPS += $$PWD/../opencv/mingw-x64/libopencv_imgproc.a
PRE_TARGETDEPS += $$PWD/../opencv/mingw-x64/libopencv_photo.a
2.将前一章编译好的动态库放到QT工程运行目录
3.编写简单代码测试
#include "cjimageprocessing.h"
#include <opencv2/opencv.hpp>
CJImageProcessing::CJImageProcessing()
{
version = cv::getVersionString();
printf("%s\n", version.c_str());
}
#ifndef CJIMAGEPROCESSING_H
#define CJIMAGEPROCESSING_H
#include <string>
class CJImageProcessing
{
public:
CJImageProcessing();
private:
std::string version;
};
#endif // CJIMAGEPROCESSING_H
运行打印结果
4.cmake工程中加入opencv (linux)
cmake脚本作为跨平台或者linux中都是不错的选择
# add lib address
include_directories(${PROJECT_SOURCE_DIR}/lib)
link_directories(${PROJECT_SOURCE_DIR}/lib)
#添加OPENCV库
include_directories(${PROJECT_SOURCE_DIR}/lib/opencv/include)
link_directories(${PROJECT_SOURCE_DIR}/lib/opencv/lib)
target_link_libraries(${PROJECT_NAME} opencv_core)
target_link_libraries(${PROJECT_NAME} opencv_imgproc)
target_link_libraries(${PROJECT_NAME} opencv_photo)