The whole process of compiling and installing opencv2.1.13 on Ubuntu16.04 (with resources)

        Currently working on a project of python-opencv reading RTSP streaming video, this behavior requires the opencv library supported by the FFmepg library, so the opencv environment needs to be installed under ubuntu. There are a few pits in the installation process to summarize to avoid everyone getting into the pits. Finally, I attach the link of my installation resources at the end of the article. I hope my friends can actively like it.

            First environment configuration:

            Ubuntu16.04 (this official website is better), ffmpeg2.4.14 (remember not to use high version 3.*), opencv2.4.13, xvidcore1.3.2

            First of all, if the system is newly installed, it is recommended to replace it with Ali's source and update it. In order to prevent the library from being found in subsequent compilations, you can install some support libraries first.

apt-get update
 
apt-get install build-essential
apt-get install cmake git libgtk2.0-dev pkg-config
apt-get install libavcodec-dev libavformat-dev libswscale-dev
apt-get install python-dev python-numpy libtbb2 libtbb-dev
apt-get install libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev libx264-dev
apt-get install libfaac-dev libmp3lame-dev libtheora-dev libvorbis-dev libxvidcore-dev libopencore-amrnb-dev libopencore-amrwb-dev  libswscale-dev  libv4l-dev
apt-get install yasm
            Then decompress the xvidcore package and enter the corresponding path in the command line. For example, mine is
cd /home/m/beifen/xvidcore-1.3.2/build/generic
and then execute
./configure  --prefix=/usr
make
make install
Next, enter the ffmepg directory:
cd /home/m/beifen/ffmpeg-2.4.14
implement:
./configure  --prefix=/usr/local/ffmpeg/  --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
Then execute them in sequence (the make process is a bit slow, you can add -j (CPU cores * 2) to speed up the speed, for example, mine is make -j8)
make  
make install
Modify the /etc/profile file and add at the end
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/ffmpeg/lib/"
execute after saving
source /etc/profile
Create a new ffmepg.conf file in the /etc/ld.so.conf.d directory, write it to /usr/local/ffmpeg, save it and execute it
ldconfig

Next, execute in the corresponding directory of opencv:

cd /home/m/beifen/opencv-2.4.13
mkdir build
cd build

Execute again:

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_TIFF=ON -D BUILD_EXAMPLES=ON -D BUILD_NEW_PYTHON_SUPPORT=ON  --WITHFFMPEG  ..
make
make install
So far all the environments have been completed. If there is a conflict in the use of the opencv version, create a new libopencv.conf file in the /etc/ld.so.conf.d directory and write
/usr/local/lib

Execute ldconfig. Remember to check the version in python after compiling:

import cv2
print cv2.__version__  //out 2.4.13
Next, you can try to extract RTSP video:
import cv2
cap = cv2.VideoCapture("rtsp://admin:[email protected]/h264/ch1/main/av_stream ")
ret = True
while ret:
    ret, frame = cap.read ()
    cv2.imshow("frame",frame)
    cv2.waitKey(1)
cv2.destroyAllWindow()
Baidu cloud address: click here

Password: c3k2













Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325764208&siteId=291194637