Install opencv2.4.9 in the virtual environment of python2.7.6

1. Create a virtual environment py276_cv249 and activate the environment (refer to https://www.jianshu.com/p/c7e6ee21484f)
    conda create -n py276_cv249 python=2.7.6 (version number can be modified according to your needs)
    source activate py276_cv249
2. In Install opencv2.4.9 in the virtual environment py276_cv249 (refer to https://www.linuxidc.com/Linux/2016-07/132880.htm and
            file:///home/lijingli/Downloads/%E4%BF%9D%E5% AD%98%E7%BD%91%E9%A1%B5/opencv%E5%AE%89%E8%A3%85/opencv2.7/ubuntu14.04%20+%20OpenCV2.4.9%20%E9%85 %8D%E7%BD%AE%E6%96%B9%E6%B3%95%20-%20MT.Queen%20-%20%E5%8D%9A%E5%AE%A2%E5%9B%AD .html
            https://blog.csdn.net/w151011/article/details/81163914)

    (1) First install the dependent libraries or software required by openCV:

sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev libqt4-dev

    (2) I used opencv2.4.9 to install opencv
    . The compressed package name downloaded on the official website is opencv-2.4.9.zip, which can be downloaded for free on the official website.

    Decompress opencv-2.4.9.zip Decompression command: Enter the directory where the compressed package is located before decompression

    unzip opencv-2.4.9

    Then execute the following command:

    cd opencv-2.4.9mkdir build
    cd build
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=OFF -D WITH_OPENMP=ON -D WITH_QT=ON .. (note WITH_CUDA=OFF) make
    -j4( Modify according to the number of cores of your computer)
    sudo make install
    (3) Environment configuration
    sudo gedit /etc/ld.so.conf (copy /usr/local/lib to the last line in the pop-up window)
    sudo ldconfig (make the configuration take effect)
    sudo gedit /etc/bash.bashrc (in the pop-up window add:

    PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

    export PKG_CONFIG_PATH (copy to the last line of text, this is two lines of environment code, do not combine into one line)

The problem is solved (refer to https://www.cnblogs.com/pprp/p/9459848.html)
If the test can pass after installation, but when there is no cv2 when import cv2 is applied, the result obtained by using which python is /home /learner/anaconda3/bin/python

Then it means that the opencv file you need (opecncv2.4.9/build/lib/cv2.so) should be placed in anaconda3/lib/python3.6 (your corresponding version)/dist-packages (or site-packages)/

 

Guess you like

Origin blog.csdn.net/ali1174/article/details/89025062