-
GCC 4.4.x or later
-
CMake 2.6 or higher
-
Git
-
GTK+2.x or higher, including headers (libgtk2.0-dev) # 控制opencv GUI
-
pkg-config
-
Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
-
ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
-
[optional] libtbb2 libtbb-dev
-
[optional] libdc1394 2.x
-
[optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
$ sudo apt-get install build-essential
$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev # 处理图像所需的包
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包
$ sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能
$ sudo apt-get install ffmpeg
自己安装得依赖包
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
出现类似问题及解决方法:
问题: /sbin/ldconfig.real: /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcudnn.so.6 is not a symbol link
sudo ldconfig -v
找到这一行错误:libcudnn.so.6 -> libcudnn.so.6.0.21
ubuntu下面ctrl+shift+F可以查找命令窗中得显示内容
或者用命令:
dpkg -S /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcudnn.so.6
解决问题代码:
sudo ln -sf /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcudnn.so.4.0.21 /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcudnn.so.6
下载地址: https://opencv.org/releases.html
进入下载好得解压文件夹当中,创建一个新的文件夹:
mkdir build
cd build
cmake -D:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
编译+安装:
sudo make #make -j4表示四核并行安装
sudo make install
将opencv的库添加到本地路径:
sudo gedit /etc/ld.so.conf.d/opencv.conf
文件中加入内容: /usr/local/lib
sudo ldconfig
法二:
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
配置bash文件
sudo gedit /etc/bash.bashrc
末尾配置如下:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
生效:
source /etc/bash.bashrc
更新:
sudo updatedb
安装完成测试:
找到下载好的解压包的opencv文件,我的位置是在 opencv-3.4.1/samples/cpp/example_cmake,
在这个文件目录下面有make文件,所以执行
cmake .
make
./opencv_example
即可看到打开了摄像头,在左上角有一个hello opencv ,表示配置成功
法二:
在这里,要在下面打开的这个文件夹中添加CMakeLists.txt和Makefile文件,这里对其做如下修改:(以下的说明都是根据经验得来,没有经过严格求证,如有错误,麻烦指正,谢谢)
CMakeLists.txt
# cmake needs this line
cmake_minimum_required(VERSION 2.8)
# Define project name
project(opencv_example_project)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
if(CMAKE_VERSION VERSION_LESS "2.8.11")
# Add OpenCV headers location to your include paths
include_directories(${OpenCV_INCLUDE_DIRS})
endif()
# Declare the executable target built from your sources
add_executable(display_image display_image.cpp) #第一个是为自己生成的目标执行文件命名 第二个变量是需要make的cpp的名字
# Link your application with OpenCV libraries
target_link_libraries(display_image ${OpenCV_LIBS}) #替换成自己的执行文件的名称就可以了,与上面的add_executable的第一个名称相同
Makefile(在这个文件中相应修改的未知就是all:执行文件的名字,下一行:执行文件名字:编译文件的名字.o, clean: 编译额外那件的名字.o 执行文件名字
CXX ?= g++
CXXFLAGS += -c -Wall $(shell pkg-config --cflags opencv)
LDFLAGS += $(shell pkg-config --libs --static opencv)
all: display_image
display_image: display_image.o; $(CXX) $< -o $@ $(LDFLAGS)
%.o: %.cpp; $(CXX) $< -o $@ $(CXXFLAGS)
clean: ; rm -f display_image.o display_image
cd ~/opencv-3.4.0/samples/cpp/tutorial_code/introduction/display_image
cmake .
make
./display_image ~/opencv-3.4.0/samples/data/lena.jpg
参考文献:
https://blog.csdn.net/yudiemiaomiao/article/details/72780790
https://blog.csdn.net/qq_24626557/article/details/70173399
https://blog.csdn.net/langb2014/article/details/54376716
https://blog.csdn.net/cocoaqin/article/details/78163171