Installation of OpenCV 3.1 (Python 3.4) on Ubuntu 14.04

Installation:

  1. lets create a virtual environment with name ‘opencv’

    A FEW VIRTUALENV COMMANDS:
    a. Leave/exit virtualenv opencv, use ‘deactivate opencv’

    b. Go to or get into virtualenv opencv, use ‘workon opencv’

    c. Remove/delete virtualenv pls use rmvirtualenv <virtualenv name>. BUT PLS DEACTIVATE FIRST BEFORE REMOVING
    for example:

     
  2. COMPILE AND INSTALL OPENCV 3 LIB FOR PYTHON 3
    ref:http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/
    http://askubuntu.com/questions/94102/what-is-the-difference-between-apt-get-update-and-upgrade
    http://milq.github.io/install-opencv-ubuntu-debian/
    1. Install prerequisites

    2. Install developer tools used to compile OpenCV 3.0:

    3. Install libraries and packages used to read various image formats from disk:

    4. Install a few libraries used to read video formats from disk: (GOT ERROR)

    SKIP???
    OK HERE IS THE SOLUTION:
    (ref:http://askubuntu.com/questions/691109/how-do-i-install-ffmpeg-and-codecs)
    Install ffmpeg and the codecs:

    Re-run ‘sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev’. SHOULD WORKS NOW!!!

    e. Install GUI libs: (ref:http://milq.github.io/install-opencv-ubuntu-debian/)

    SOLUTION: Install Lib GTK so we can use OpenCV’s GUI features:

    Re-run ‘sudo apt-get install qt5-default libvtk6-dev’

    f. Install packages that are used to optimize various functions inside OpenCV, such as matrix operations:

    g. Install documentation (doxigen):

    h. Install Parallelism and linear algebra libraries:

     

  3. We’re halfway done setting up Python. But in order to compile OpenCV 3.0 with Python 3.4+ bindings, we’ll need to install the Python 3.4+ headers and development files:
    a. sudo apt-get install python3.4-dev

    b. go into our virtualenv ‘opencv’

    c. OpenCV represents images as NumPy arrays, so we need to install NumPy into our ‘opencv’ virtual environment:

    CHECK numpy VERSION: (ITS OKAY JUST USE python IN VIRTUALENV CREATED FOR PYTHON3)

     

  4. Build and install OpenCV 3.0 with Python 3.4+ bindings
    a. deactivate opencv first (NO. DON’T DO THIS. KEEP ON THE opencv virtualenv BECAUSE WE’LL USE numpy!)

    b. Alright, our system is all setup now! Let’s pull down OpenCV from GitHub and checkout the 3.1.0 version:

    c. We’ll also need to grab the opencv_contrib repo as well (for more information as to why we need opencv_contrib, take a look at my previous OpenCV 3.0 Ubuntu install post: http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/):

    IMPORTANT: I FOUND AN ERROR ‘The data should normally be NULL! in function allocate’ WHEN TRY TO TEST SIFT Holography Feature Matching (flann.knnMatch). PLS FIX THIS FIRST (SEE SOLUTION IN /media/data/MASTER/opencv/github_list_fish_rec.txt) BEFORE BUILD OPENCV AT STEP #5 BELOW!
    d.a Time to setup the build (USE virtualenv opencv BETTER BECAUSE WE NEED numpy!!!):–> RENAMED DIR TO ‘build0’. I THINK DONT USE THIS. JUST USE d.b.

    d.b Time to setup the build (USE virtualenv opencv BETTER BECAUSE WE NEED numpy!!!):

    e. compile! (TAKE LONG TIME AND I GOT 5 GB DATA)
    make -j4
    Where the 4 can be replaced with the number of available cores on your processor to speedup the compilation time.
    To find out how many core your computer has, pls do:
    ref:http://www.howtogeek.com/howto/ubuntu/display-number-of-processors-on-linux/

    f. Assuming OpenCV 3.1 compiled without error, you can now install it on your system:

    g.

     

  5. Sym-link OpenCV 3.1
    If you’ve reached this step, OpenCV 3.1 should now be installed in /usr/local/lib/python3.4/site-packages/

    Here, our OpenCV bindings are stored under the name cv2.cpython-34m.so

    Be sure to take note of this filename, you’ll need it in just a few seconds!

    However, in order to use OpenCV 3.1 within our opencv virtual environment, we first need to sym-link OpenCV into the site-packages directory of the cv environment, like this:

    Notice how I am changing the name from cv2.cpython-34m.so to cv2.so — this is so Python can import our OpenCV bindings using the name cv2 .

    So now when you list the contents of the opencv virtual environment’s site-packages directory, you’ll see our OpenCV 3.1 bindings (the cv2.so file):

    Again, this is a very important step, so be sure that you have the cv2.so file in your virtual environment, otherwise you will not be able to import OpenCV in your Python scripts!

    5. Test out the OpenCV 3.0 and Python 3.4+ install

    As you can see, OpenCV 3.1 with Python 3.4+ bindings has been successfully installed on my Ubuntu system!

    6. EXECUTE SOME OPENCV EXAMPLES (ref:http://milq.github.io/install-opencv-ubuntu-debian/)
    a. Run this example (edge detect):

    Would open an image (fruit) with edge detect!

    b. run python samples (video capture from my laptop camera):



    7. CREATE AN EXAMPLE DEMO
    There is a sample code in /opencv/samples/cpp/example_cmake/
    To compile example.cpp successfully, we need CMakeLists.txt and Makefile
    run:

    RESULT:

    TO EXECUTE THE FILE:

    FOR MORE OPENCV TUTORIAL FOR PYTHON, PLS SEE /media/data/MASTER/opencv/opencv_python_tutorial.txt

Leave a Reply

Your email address will not be published. Required fields are marked *