Ubuntu安装编译OpenCV一键脚本(带ffmpeg)

Posted zhchoutai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu安装编译OpenCV一键脚本(带ffmpeg)相关的知识,希望对你有一定的参考价值。

1.切换到用户文件夹

cd ~

2.新建一个文件。命名为opencv.sh 脚本例如以下:

version="$(wget -q -O - http://sourceforge.net/projects/opencvlibrary/files/opencv-unix | egrep -m1 -o ‘\"[0-9](\.[0-9])+‘ | cut -c2-)"
echo "Installing OpenCV" $version
mkdir OpenCV
cd OpenCV
echo "Removing any pre-installed ffmpeg and x264"
sudo apt-get install unzip
sudo apt-get install cmake
sudo apt-get -qq remove ffmpeg x264 libx264-dev
echo "Installing Dependenices"
sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg
echo "Downloading OpenCV" $version
wget -O OpenCV-$version.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/opencv-"$version".zip/download
echo "Installing OpenCV" $version
unzip OpenCV-$version.zip
cd opencv-$version
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make -j2
sudo checkinstall
sudo sh -c ‘echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf‘
sudo ldconfig
echo "OpenCV" $version "ready to be used"

3.改动为可执行

chmod +x opencv.sh

4.执行

./opencv.sh


注意:假设编译完之后,在lib和bin中没有java相关的jar和.so文件。你须要安装jdk,并导出JAVA_HOME变量:比如,64位ubuntu,

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

(path may differ in your system), cmake generated both:

build/bin/opencv-249.jar
build/lib/libopencv_java249.so
   

以上是关于Ubuntu安装编译OpenCV一键脚本(带ffmpeg)的主要内容,如果未能解决你的问题,请参考以下文章

CentOS一键编译安装nginx,带http2/brotli/zlib/pcre/ssl,非root监听80端口

sh linux ubuntu一键安装svn,直接使用源安装会有问题,编译安装太麻烦,使用老版本可以一键安装,脚本来源于网络,替换了失效的下载链接。

宝塔一键安装脚本

携程Apollo一键编译脚本+部署实现

携程Apollo一键编译脚本+部署实现

opencv4.2+opencv_contrib编译gpu加速带cuda和CUDnn(二)