代码下载编译安装

$ 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 )

opencv编译运行demo碰到的问题相关推荐

  1. DuiLib学习笔记1.编译运行demo

    c++中皮肤问题比较麻烦,MFC自带的太难用.DirectUI界面库就比较强大了,之前像skin++之类的基于DirectUI收费昂贵.DuiLib是基于DirectUI的界面库,可以将用户界面和处理 ...

  2. ESP32编译运行ADF音频库

    明确ADF对应的IDF版本 ADF v2.1.v2.0 官网上说的支持v3.3.v4.0.v4.1,但是推荐v3.3,经过实际运行测试发现,v4.0等可以,但是支持不全面,有些Demo完全不支持,所以 ...

  3. [IJKPLAYER]编译与DEMO运行

    前言 系统:UBUNTU 16.04桌面版 编译步骤,主要还是参考README.md中Build Android的描述 Android/iOS video player based on FFmpeg ...

  4. 华为Atlas200DK的环境部署与运行demo(人脸识别)

    文章目录 前言 一.部署准备 1.基本准备 2.安全清空sd卡 3.安装摄像头 二.环境部署 1.运行环境与开发环境合设 1.烧录dd镜像 2.开发板启动 3.开发板连接PC机 1.USB端口连接 2 ...

  5. OpenVINO——3. OpenVINO文字识别OCR运行demo

    1. 简介 搜索了一波关于openVINO的使用,竟然也有很多资料,看来是自己不关注这方面,井底之蛙了. 这里有个问题,按照上面安装步骤安装的仅仅是OpenVINO,但是查看OpenvinoTookl ...

  6. opencv-3.4.3 交叉编译并且移植到高通820开发板(包括Qt 5.11.2部分交叉编译及移植),NEON OpenCV编译

    opencv-3.4.3 交叉编译并且移植到高通820开发板(包括Qt 5.11.2部分交叉编译及移植),NEON OpenCV编译 原文我是用有道笔记记录的,下面排版不是很好,可参看有道笔记原文:h ...

  7. ST-GCN源码运行demo配置过程(openpose-1.5.0+win10)

    目录 配置Openpose-1.5.0 Openpose下载 Cmake编译Openpose 测试Openpose 配置Anaconda环境 安装基础工具 安装PyTorch 测试PyTorch 安装 ...

  8. Qt开发笔记之Qwt(一):Qwt介绍、编译与Demo

    若该文为原创文章,未经允许不得转载 原博主博客地址:长沙红胖子_长沙红胖子网络科技有限公司_CSDN博客 原博主博客导航:红胖子(红模仿)的博文大全:开发技术集合(包含Qt实用技术.树莓派.三维.Op ...

  9. 在Win10系统上使用VScode + Cmake配置C/C++开发环境,实现一键编译运行

    1.前言 前几天在公司的Ubuntu20.04电脑上配置了VSCode + Cmake的C/C++开发环境,可以用来跑跑C/C++的代码,然后,现在住的地方用的Windows,开发环境用的是 Visu ...

最新文章

  1. python入门:正则表达式,面向对象编程,零基础视频教程分享
  2. 像DW的应用源格式那样格式化VS里面的代码
  3. Redis进阶-Redis缓存优化
  4. ping不通Linux系统解决方法
  5. 第5讲:软考中高项04_进度管理、成本管理
  6. bat处理中的管道[|]
  7. vs2017+pcl1.8.1配置
  8. 获取原始NMEA 0183语句的方法
  9. DVWA 靶场通关教程
  10. 本特利177230-00-01-CN
  11. 关于网页消息提示音问题解决与实现
  12. 2021蓝桥杯Java复习【史上最详细攻略】【持续更新】
  13. Android 架构师成长之路
  14. English语法_分词用法-作名词
  15. 【第27篇】MobileNetV2:倒置残差和线性瓶颈
  16. 计算机函数sumif实例,Excel2019中SUMIF函数的语法及使用方法与实例
  17. 将Shapefile(SHP)转换为Surfer中的网格(GRD)的方法-通用方法。
  18. 软考java题目_2016下半年软考程序员考试冲刺模拟试题及答案(三)
  19. 欧拉回路 欧拉通路 欧拉回路图
  20. 收集一些网页模板/素材的网站

热门文章

  1. MATLAB学习与使用:向量及其运算
  2. python:共轭梯度法(以希尔伯特矩阵为例)
  3. 倍福--Database的安装
  4. 年薪几十万的北漂生活是怎样的
  5. 论文计算机的教学方法,计算机教学方法论文
  6. axure 抖音部件库_致敬抖音一周年:用Axure还原酷炫高保真原型【附系列教程】...
  7. ubuntu安装xrdp(远程桌面协议)报错:无法获得锁
  8. 最严谨的计算机语言p,世界最严谨的语言排行 法语登顶汉语屈居第二
  9. excel 通过if进行字符串模糊查询
  10. GitLab 详细安装及使用教程