opencv debug版本在linux下编译,并写了一个DEMO

Posted ahfuzhang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv debug版本在linux下编译,并写了一个DEMO相关的知识,希望对你有一定的参考价值。

用如下方法编译opencv:

git clone "https://github.com/opencv/opencv.git"

mkdir opencv_debug

cd opencv

mkdir build

cd build

cmake ..

#查看编译选项

cmake -LA | awk ‘{if(f)print} /-- Cache values/{f=1}‘

#我的编译选项(其实反复了很多次)

/usr/local/bin/cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/data/ahfuzhang/install_packages/opencv_debug/ -DBUILD_SHARED_LIBS=OFF -DBUILD_WITH_DYNAMIC_IPP=OFF -DWITH_IPP=OFF -DBUILD_IPP_IW=OFF -DBUILD_ITT=OFF -DBUILD_JAVA=OFF -DBUILD_PROTOBUF=OFF -DBUILD_TESTS=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_python_bindings_generator=OFF -DWITH_CUDA=OFF -DWITH_ITT=OFF -DWITH_OPENCL=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_PROTOBUF=OFF -DWITH_OPENEXR=OFF -DWITH_JASPER=OFF -DWITH_PNG=OFF -DWITH_WEBP=OFF

make -j20  #我核多,土豪

make install

 

写了如下一个计算图像直方图的程序:

//image_hist.cpp
#include <iostream>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    if (argc<2){
        printf("usage:%s <img>
", argv[0]);
        return -1;
    }
    Mat img = imread(argv[1], IMREAD_UNCHANGED);
    if (img.data==NULL){
        printf("read file fail
");
        return -1;
    }
    int channels[] = {0};
    int histSize[] = {256, 1};
    float _ranges[] = { 0, 256 };
    const float* ranges[] = {_ranges};
    Mat hist;
    calcHist(&img, 1, channels, Mat(), hist, 2, histSize, ranges, true, false);
    for (int i=0; i<256; ++i){
        int count = (int)hist.at<float>(i, 0);
        printf("%d ", count);
    }
    return 0;
}  

编译:

g++ -o image_hist.o -c image_hist.cpp -g -I"/data/ahfuzhang/install_packages/opencv_debug/include/opencv4/" -std=c++11

链接:

g++ -o image_hist image_hist.o -L"/data/home/ahfuzhang/install_packages/opencv_build/lib64/" -lopencv_calib3d  -lopencv_features2d -lopencv_flann -lopencv_gapi -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_video -lopencv_videoio -lopencv_core -lrt -lpthread -ldl -lz  "/usr/lib64/liblapack.so.3.4.2" -lopenblas "/usr/lib64/libjpeg.so.62.1.0" "/usr/lib64/libtiff.so.5.2.0" 

运行:

./image_hist 1.jpg
read file fail

 

DEMO并未运行成功,网上搜了是库的问题,等下继续解决!

 


以上是关于opencv debug版本在linux下编译,并写了一个DEMO的主要内容,如果未能解决你的问题,请参考以下文章

在release模式下编译opencv写的人脸检测代码,提示:无法打开输入文件“opencv_calib3d244.lib”

Linux系统下编译OpenCV(解决无法读取图片和视频的问题)

linux下编译opencv

linux环境下编译运行OpenCV程序的两种方法

在fedora25x86下编译opencv的Android版本的过程记录

opencv系列之ubuntu系统下编译python版本的opencv(指定特定的ffmpeg)