码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2018-12-27 15:30:01      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:sage   libjpeg   oca   pytho   []   code   多次   mdf   deb   

用如下方法编译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>\n", argv[0]);
        return -1;
    }
    Mat img = imread(argv[1], IMREAD_UNCHANGED);
    if (img.data==NULL){
        printf("read file fail\n");
        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

标签:sage   libjpeg   oca   pytho   []   code   多次   mdf   deb   

原文地址:https://www.cnblogs.com/ahfuzhang/p/10184539.html

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