demo开发之问题04编译ubuntu环境下编译opencv

本文详细记录了在安装和配置OpenCV过程中遇到的各种问题及其解决方法,包括依赖包缺失、配置文件修改、数据下载等,为开发者提供全面的技术指导。

一、安装过程中出现的问题

1.  looking for ccache --not found

sudo apt-get install ccache

2.  Performance test HAVE)C_WSUGGEST_OVERRIDE - Failed

What parameter did you pass to cmake to allow for "Non-free algorithms: YES"? I have tried -D OPENCV_ENABLE_NON_FREE=ON and other combinations of that nature, but have yet to get the YES I want.

3. could not find jasper

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev

4. no package 'gtk+-3.0 found'

sudo apt-get install build-essential libgtk-3-dev

 5. could not found OpenBLAS include. Turning OpenBLAS_FOUND off

https://github.com/opencv/opencv/issues/12957

https://stackoverflow.com/questions/36483054/install-openblas-via-apt-get-sudo-apt-get-install-openblas-dev

1)安装package

udo apt install libopenblas-dev, libopenblas-base

但是在安装过程中可能出现无法定位包的问题,即为unable to locate libopenblas-dev, libopenblas-base,这是可执行以下操作,

apt-cache search openblas

libblas-test - Basic Linear Algebra Subroutines 3, testing programs
libopenblas-base - Optimized BLAS (linear algebra) library based on GotoBLAS2
libopenblas-dev - Optimized BLAS (linear algebra) library based on GotoBLAS2

然后再次安装;最后,执行以下操作。

sudo apt install liblapacke-dev

sudo ln -s /usr/include/lapacke.h /usr/include/x86_64-linux-gnu # corrected path for the library 

2)修改配置文件

Appending these respective additional Paths in OpenCVFindOpenBLAS.cmake :

opencv/cmake/OpenCVFindOpenBLAS.cmake

Line 46 in eb981cc

SET(Open_BLAS_INCLUDE_SEARCH_PATH

and

opencv/cmake/OpenCVFindOpenBLAS.cmake

Line 58 in eb981cc

SET(Open_BLAS_LIB_SEARCH_PATHS

6. CBLAS/LAPACK header are not found in /usr/include/x86_64-linux-gun

7.Could NOT find HDF5

sudo apt-get install libhdf5-dev

8. module opencv-ovis disabled because OGRE3D was not found

sudo apt-get install libogre-1.9-dev # 1.9不能省略

9.data downloda:face_landmark_model.dat==>timeout

将opencv/build/CMakeDownloadLog.txt中face_landmark_model选项的数据下载地址修改为https://github.com/opencv/opencv_3rdparty/blob/contrib_face_alignment_20170818/face_landmark_model.dat

10.VTK is not found,please set -DVTK_DIR in CMake to VTK build directory,or to VTK install

1) 从VTK官网下载最新的稳定版本

2)使用cmake重新编译,然后进入build文件执行sudo make install

11. Checking for modules 'tesseract;lept'  No package 'tesseract' found Tesseract:   NO

https://www.linux.com/blog/using-tesseract-ubuntu

1) 安装依赖包

$ sudo apt-get install libpng-dev libjpeg-dev libtiff-dev zlib1g-dev

$ sudo apt-get install gcc g++

$ sudo apt-get install autoconf automake libtool checkinstall

2)下载tessearct

$ cd ~ $ git clone https://github.com/tesseract-ocr/tesseract.git $ cd tesseract

3)使用cmake重新编译,保证没有错误

4)编译成功后,进入build问加减,执行以下命令:sudo make install

12.Found installed version of gflags: /usr/lib/x86_64-linux-gnu/cmake/gflags
Detected gflags version: 2.2.1
Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
Module opencv_sfm disabled because the following dependencies are not found: Glog/Gflags

sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev

13. Module opencv_ovis disabled because OGRE3D was not found

这里需要安装ogre3d,但是在安装它之前,需要先安装ois

1)从git上下载

https://github.com/ogre3d/OIS.git

2)cmake一下,然后进入build 完成sudo make install

3)git上下载

https://github.com/OGRECave/ogre.git

4)cmake一下

进入build,输入以下命令 sudo make install

14. Ceres Solver for reconstruction API is required.

1)检查依赖包是否安装

# google-glog + gflags
sudo apt-get install libgoogle-glog-dev
# BLAS & LAPACK
sudo apt-get install libatlas-base-dev
# Eigen3
sudo apt-get install libeigen3-dev
# SuiteSparse and CXSparse (optional)
# - If you want to build Ceres as a *static* library (the default)
#   you can use the SuiteSparse package in the main Ubuntu package
#   repository:
sudo apt-get install libsuitesparse-dev
# - However, if you want to build Ceres as a *shared* library, you must
#   add the following PPA:
sudo add-apt-repository ppa:bzindovic/suitesparse-bugfix-1319687
sudo apt-get update
sudo apt-get install libsuitesparse-dev

2)从github上下载ceres-solver

git clone https://github.com/ceres-solver/ceres-solver.git

3)重新编译,记得在build文件中运行sudo make install

15. Tesseract_include_dir not found in moudle/text

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Tesseract_INCLUDE_DIR
   used as include directory in directory /home/rodrigo/opencv_contrib-3.2.0/modules/text

1) 把 Tesseract_build文件清空,重新编译。

2)把opencv的build文件清空,重新编译

二、总结

1)大部分问题是依赖包没有安装,所以在google的时候注意控制关键字,install XXX.

2)  不要着急,逐个攻破。

 

 

 

 

要在Ubuntu 20.04编译并运行一个C++ OpenCV示例程序,需要确保OpenCV已经正确安装并且开发环境已经配置好。以下是详细的步骤: ### 编译和运行C++ OpenCV示例程序 #### 1. 安装必要的依赖 首先,确保系统上安装了必要的构建工具和库。如果尚未安装,可以通过以下命令安装: ```bash sudo apt-get update sudo apt-get install -y build-essential cmake git libopencv-dev ``` #### 2. 编写C++ OpenCV示例程序 创建一个新的C++文件,例如`example.cpp`,并输入以下代码: ```cpp #include <opencv2/opencv.hpp> #include <iostream> int main(int argc, char** argv) { // 加载图像 cv::Mat image = cv::imread("test.jpg"); // 检查图像是否成功加载 if (image.empty()) { std::cout << "无法加载图像!" << std::endl; return -1; } // 显示图像 cv::namedWindow("Display Image", cv::WINDOW_AUTOSIZE); cv::imshow("Display Image", image); // 等待按键 cv::waitKey(0); return 0; } ``` 这段代码会尝试读取名为`test.jpg`的图像文件,并显示出来。如果文件不存在或者无法读取,程序会输出错误信息。 #### 3. 编译C++ OpenCV示例程序 使用`g++`命令编译上面的程序,并链接OpenCV库: ```bash g++ example.cpp -o example `pkg-config --cflags --libs opencv4` ``` 这条命令会编译`example.cpp`文件,并生成名为`example`的可执行文件。`pkg-config`工具用于获取编译和链接OpenCV程序所需的标志。 #### 4. 运行C++ OpenCV示例程序 确保有一个名为`test.jpg`的图像文件在同一目录下,然后运行程序: ```bash ./example ``` 如果一切正常,应该会看到一个窗口显示`test.jpg`图像。 ### 版本验证 为了验证OpenCV的版本,可以使用以下命令: ```bash pkg-config --modversion opencv4 ``` 这将输出当前安装的OpenCV版本号[^1]。 ### 相关问题 1. 如何在Ubuntu 20.04上安装特定版本的OpenCV? 2. 如何解决OpenCV编译时遇到的常见错误? 3. 如何在Ubuntu 20.04上配置OpenCV开发环境? 4. 如何使用CMake来构建包含OpenCV的C++项目? 5. 如何在Ubuntu 20.04上卸载OpenCV
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值