opencv编译运行demo碰到的问题
代码下载编译安装
$ git clone https://github.com/opencv/opencv.git
$ cd opencv
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install
编译后demo运行出错
> terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.4.0-dev) /home/hui/data/study/opencv/modules/highgui/src/window.cpp:634: error: (-2:Unspecified error)
The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support.
If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvNamedWindow'
解决办法
cmake选项中加上:WITH_GTK=ON
sudo apt install libgtkglext1-dev
cmake后的输出
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'gtk+-3.0'
-- Found gtk+-3.0, version 3.22.30
-- Checking for module 'gtk+-2.0'
-- Found gtk+-2.0, version 2.24.32
-- Checking for module 'gthread-2.0'
-- Found gthread-2.0, version 2.56.4
-- Checking for module 'gtkglext-1.0'
-- Found gtkglext-1.0, version 1.2.0
编译错误
[ 44%] Linking CXX executable ../../bin/opencv_test_core
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFWriteEncodedStrip@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFIsTiled@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFWriteScanline@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFGetField@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFScanlineSize@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFWriteDirectory@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFReadEncodedTile@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFReadRGBATile@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFClose@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFClientOpen@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFRGBAImageOK@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFOpen@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFReadEncodedStrip@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFSetField@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFSetWarningHandler@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFSetErrorHandler@LIBTIFF_4.0'
[ 52%] Building CXX object modules/ts/CMakeFiles/opencv_ts.dir/src/ocl_test.cpp.o
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFWriteEncodedStrip@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFIsTiled@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFWriteScanline@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFGetField@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFScanlineSize@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFWriteDirectory@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFReadEncodedTile@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFReadRGBATile@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFClose@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFClientOpen@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFRGBAImageOK@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFOpen@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFReadEncodedStrip@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFSetField@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFSetWarningHandler@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFSetErrorHandler@LIBTIFF_4.0'
cmake选项中加上:BUILD_TIFF=ON
最后的cmake配置项如下
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=ON \
-D WITH_GTK=ON \
-D BUILD_TIFF=ON ..
build后还是报错
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.4.0-dev) /home/hui/data/study/opencv/modules/highgui/src/window.cpp:634: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvNamedWindow'
找到opencv的库,看了下make install没有更新,然后删除掉/usr/local/lib下的opencv相关库后重新make install
$ cd /usr/local/lib
$ ls -l libopencv_core.so.4.4.0
-rw-r--r-- 1 root root 18073456 8月 31 2020 libopencv_core.so.4.4.0
$ rm libpencv*
在demo中cmake后,OpenCV version变成4.5.3,成功了!
$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr/local (found suitable version "4.5.3", minimum required is "4.0.0")
OpenCV version : 4.5.3
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hui/data/Learn-OpenCV-4/Poisson-fusion/build
使用demo是Learn-OpenCV-4,openCV 4计算机视觉项目实战一本书的例子:
https://github.com/PacktPublishing/Learn-OpenCV-4-By-Building-Projects-Second-Edition.git
在opencv的目录下也有sample:
opencv/samples/cpp/tutorial_code/
sample对应的图片资源需要单独下载
https://github.com/opencv/opencv\_extra.git
比如使用seamless_cloning的sample代码, copy 前面demo的一个CMakeLists.txt改改就可以用。
$ cd opencv/samples/cpp/tutorial_code/photo/seamless_cloning
$ mkdir build
$ cmake ..
$ make
生成clone-demo,然后copy opencv_extra对应的资源目录到buld下, 就可以运行sample-demo了。
$ cp -rf opencv_extra/testdata/cv/cloning opencv/samples/cpp/tutorial_code/photo/seamless_cloning/build/.
附CMakeLists.txt
cmake_minimum_required (VERSION 3.0)
PROJECT(poisson-fusion)
set (CMAKE_CXX_STANDARD 11)
IF(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
ENDIF()
# Requires OpenCV
FIND_PACKAGE( OpenCV 4.0.0 REQUIRED )
MESSAGE("OpenCV version : ${OpenCV_VERSION}")
ADD_EXECUTABLE(poisson-fusion main.cpp )
TARGET_LINK_LIBRARIES( poisson-fusion ${OpenCV_LIBS} ${CONAN_LIBS} -lprotobuf )
还没有评论,来说两句吧...