尝试为OpenCV 3.4.3编译opencv_traincascade

时间:2018-08-31 14:50:44

标签: c++ opencv centos6

当尝试编译完整的源代码时,它通过cmakemake就可以了,它说它建立了级联,但是当进行make install时却失败了。

[root@node 3.4.3]$ cmake -D CMAKE_INSTALL_PREFIX=/path/opencv/3.4.3/ /path/opencv/source/opencv-3.4.3/
...
-- Configuring done
-- Generating done
-- Build files have been written to: /path/opencv/3.4.3

[root@node 3.4.3]$ make -j6
[  0%] Built target gen-pkgconfig
[  1%] Built target libpng
...
[ 93%] Built target opencv_perf_calib3d
Scanning dependencies of target opencv_traincascade
[ 94%] Built target opencv_interactive-calibration
[ 95%] Built target opencv_videostab
[ 96%] Built target opencv_stitching
[ 97%] Built target opencv_test_videostab
[ 98%] Built target opencv_test_calib3d
[ 99%] Built target opencv_test_stitching
[ 99%] Built target opencv_perf_stitching
[ 99%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade.dir/traincascade.cpp.o
[ 99%] Linking CXX executable ../../bin/opencv_traincascade
[100%] Built target opencv_traincascade
[root@node 3.4.3]$ make install
[  0%] Built target gen-pkgconfig
[  3%] Built target libjpeg-turbo
[  6%] Built target libtiff
...
[ 97%] Built target opencv_test_videostab
[ 98%] Built target opencv_traincascade
[ 98%] Built target opencv_createsamples
[ 99%] Built target opencv_annotation
[ 99%] Built target opencv_visualisation
[100%] Built target opencv_interactive-calibration
[100%] Built target opencv_version
Install the project...
-- Install configuration: "Release"
-- Up-to-date: /path/opencv/3.4.3/share/OpenCV/licenses/ippicv-readme.htm
...
-- Up-to-date: /path/opencv/3.4.3/share/OpenCV/lbpcascades/lbpcascade_silverware.xml
CMake Error at apps/traincascade/cmake_install.cmake:42 (file):
  file INSTALL cannot find
  "/path/opencv/3.4.3/bin/opencv_traincascade".
Call Stack (most recent call first):
  apps/cmake_install.cmake:37 (include)
  cmake_install.cmake:123 (include)



make: *** [install] Error 1

当我在bin中查看时,没错,没有opencv_traincascade。我也尝试自己编译它,但是由于出现了很多未定义的引用,所以它失败了。

[root@node 3.4.3]$ g++ -I /path/opencv/3.4.3/include -o opencv_traincascade ../source/opencv-3.4.3/apps/traincascade/traincascade.cpp
/tmp/ccgslHVv.o: In function `main':
traincascade.cpp:(.text+0x6f): undefined reference to `cv::getNumThreads()'
traincascade.cpp:(.text+0xa0): undefined reference to `CvCascadeParams::CvCascadeParams()'
traincascade.cpp:(.text+0xaf): undefined reference to `CvCascadeBoostParams::CvCascadeBoostParams()'
traincascade.cpp:(.text+0x3c0): undefined reference to `CvCascadeParams::printDefaults() const'
traincascade.cpp:(.text+0x3cf): undefined reference to `CvCascadeBoostParams::printDefaults() const'
traincascade.cpp:(.text+0x8a5): undefined reference to `CvCascadeParams::scanAttr(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
traincascade.cpp:(.text+0x998): undefined reference to `CvCascadeBoostParams::scanAttr(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
traincascade.cpp:(.text+0xb39): undefined reference to `cv::setNumThreads(int)'
traincascade.cpp:(.text+0xc11): undefined reference to `CvCascadeClassifier::train(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int, int, int, int, CvCascadeParams const&, CvFeatureParams const&, CvCascadeBoostParams const&, bool, double)'
/tmp/ccgslHVv.o: In function `cv::Mat::~Mat()':
traincascade.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccgslHVv.o: In function `cv::Mat::release()':
traincascade.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
/tmp/ccgslHVv.o: In function `CvParams::~CvParams()':
traincascade.cpp:(.text._ZN8CvParamsD2Ev[_ZN8CvParamsD5Ev]+0xd): undefined reference to `vtable for CvParams'
/tmp/ccgslHVv.o: In function `CvCascadeBoostParams::~CvCascadeBoostParams()':
traincascade.cpp:(.text._ZN20CvCascadeBoostParamsD2Ev[_ZN20CvCascadeBoostParamsD5Ev]+0x9): undefined reference to `vtable for CvCascadeBoostParams'
/tmp/ccgslHVv.o: In function `CvCascadeImageReader::CvCascadeImageReader()':
traincascade.cpp:(.text._ZN20CvCascadeImageReaderC2Ev[_ZN20CvCascadeImageReaderC5Ev]+0x15): undefined reference to `CvCascadeImageReader::PosReader::PosReader()'
traincascade.cpp:(.text._ZN20CvCascadeImageReaderC2Ev[_ZN20CvCascadeImageReaderC5Ev]+0x25): undefined reference to `CvCascadeImageReader::NegReader::NegReader()'
traincascade.cpp:(.text._ZN20CvCascadeImageReaderC2Ev[_ZN20CvCascadeImageReaderC5Ev]+0x36): undefined reference to `CvCascadeImageReader::PosReader::~PosReader()'
/tmp/ccgslHVv.o: In function `CvCascadeImageReader::~CvCascadeImageReader()':
traincascade.cpp:(.text._ZN20CvCascadeImageReaderD2Ev[_ZN20CvCascadeImageReaderD5Ev]+0x24): undefined reference to `CvCascadeImageReader::PosReader::~PosReader()'
/tmp/ccgslHVv.o: In function `CvCascadeClassifier::CvCascadeClassifier()':
traincascade.cpp:(.text._ZN19CvCascadeClassifierC2Ev[_ZN19CvCascadeClassifierC5Ev]+0x15): undefined reference to `CvCascadeParams::CvCascadeParams()'
/tmp/ccgslHVv.o: In function `cv::Ptr<CvHaarFeatureParams> cv::makePtr<CvHaarFeatureParams>()':
traincascade.cpp:(.text._ZN2cv7makePtrI19CvHaarFeatureParamsEENS_3PtrIT_EEv[_ZN2cv7makePtrI19CvHaarFeatureParamsEENS_3PtrIT_EEv]+0x20): undefined reference to `CvHaarFeatureParams::CvHaarFeatureParams()'
/tmp/ccgslHVv.o: In function `cv::Ptr<CvLBPFeatureParams> cv::makePtr<CvLBPFeatureParams>()':
traincascade.cpp:(.text._ZN2cv7makePtrI18CvLBPFeatureParamsEENS_3PtrIT_EEv[_ZN2cv7makePtrI18CvLBPFeatureParamsEENS_3PtrIT_EEv]+0x20): undefined reference to `CvLBPFeatureParams::CvLBPFeatureParams()'
/tmp/ccgslHVv.o: In function `cv::Ptr<CvHOGFeatureParams> cv::makePtr<CvHOGFeatureParams>()':
traincascade.cpp:(.text._ZN2cv7makePtrI18CvHOGFeatureParamsEENS_3PtrIT_EEv[_ZN2cv7makePtrI18CvHOGFeatureParamsEENS_3PtrIT_EEv]+0x20): undefined reference to `CvHOGFeatureParams::CvHOGFeatureParams()'
/tmp/ccgslHVv.o: In function `CvCascadeParams::~CvCascadeParams()':
traincascade.cpp:(.text._ZN15CvCascadeParamsD2Ev[_ZN15CvCascadeParamsD5Ev]+0xd): undefined reference to `vtable for CvCascadeParams'
collect2: error: ld returned 1 exit status

我正在使用gcc / 7.2.0和cmake / 3.4.3。让我知道您还需要其他哪些细节。

[root @ node 3.4.3] $ uname -a Linux节点2.6.32-696.30.1.el6.x86_64#1 SMP Tue May 22 03:28:18 UTC 2018 x86_64 x86_64 x86_64 GNU / Linux

1 个答案:

答案 0 :(得分:0)

首先,安装构建opencv所需的库和依赖项:

apt-get update && apt-get upgrade -y
apt-get install -y build-essential cmake pkg-config \
                       libjpeg62-turbo-dev libtiff5-dev \
                       libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
                       libatlas-base-dev gfortran python2.7-dev python3.5-dev \
                       python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev \
                       wget unzip ant libatlas-base-dev gfortran pylint \
                       libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

然后,下载并解压缩源代码:

mkdir opencv
cd opencv
wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.4.5.zip && unzip -qq opencv.zip
wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.4.5.zip && unzip -qq opencv_contrib.zip

创建构建目录:

mkdir build
cd build

生成makefile。调整您需要的opencv标志(我只看过Java绑定)和将模块提取到其他位置的contrib模块的路径:

cmake -DBUILD_SHARED_LIBS=OFF \
          -BUILD_opencv_apps=ON \
          -DOPENCV_ENABLE_NONFREE:BOOL=ON \
          -DCMAKE_BUILD_TYPE=Release \
          -DBUILD_opencv_python2=OFF \
          -DBUILD_opencv_python3=OFF \
          -DINSTALL_C_EXAMPLES=OFF \
          -DBUILD_TESTS=OFF \
          -DBUILD_PERF_TESTS=OFF \
          -DCMAKE_INSTALL_PREFIX=../out \
          -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.4.5/modules \
          ../opencv-3.4.5

像往常一样进行安装:

make -j4

make install

对我来说,关键部分是install_prefix变量。出于某种原因,当将前缀设置到构建目录时,它不起作用,但是当我指定了另一个目录(在我的情况下为out时),效果很好