Install Open. CV 3 and Python 2. Ubuntu. Last week we kicked- off the Open. CV 3. 0 install fest by detailing how to install Open. CV 3. 0 and Python 2. # download opencv-2.4.11. Worked on ubuntu 12.04. I also had to run sudo apt-get install python-opencv to work with python (2.7).OSX platform. Today we are going to continue the Open. CV 3. 0 install instruction series by moving over to the Ubuntu operating system. In the remainder of the post I will provide instructions on how to configure and install Open. CV 3. 0 and Python 2. To learn how to install OpenCV on your Ubuntu 16.04 system. Python 2.7.12 (used by default. Download the OpenCV source. Ubuntu. I have personally tested these instructions on Ubuntu 1. Debian- based operating system. A quick note before we get started: Yes, Open. CV 3. 0 is indeed compatible with Python 3+. However, the install instructions are slightly different between Python 2. Python 3+. In an effort to keep each article self- contained and easy to follow, I am creating separate Open. CV 3. 0 install tutorials for Python 2. Python 3+. If you would like to use Open. CV 3. 0 and Python 3+ on your Ubuntu system, please keep an eye on this blog — I will be posting Open. CV 3. 0 and Python 3+ install instructions later this month. But for the time being, let’s stick with Python 2. How to Install Open. CV 3. 0 and Python 2. Ubuntu. UPDATE: The tutorial you are reading now covers how to install Open. CV 3. 0 with Python 2. Ubuntu 1. 4. 0. 4. This tutorial still works perfectly, but if you want to install Open. CV on the newer Ubuntu 1. Open. CV 3. 1 and Python 2. Python 3. 5) bindings, please use this freshly updated tutorial: https: //www. This is the second article in the Open. CV 3. 0 install- fest series. Last week we covered how to install Open. CV 3. 0 and Python 2. OSX. Today we are going to perform the same Open. CV 3. 0 and Python 2. Ubuntu operating system. In general, you should find installing Open. ![]() CV 3. 0 and Python 2. Ubuntu much easier than installing on OSX. Step 1: Open up a terminal and update the. Step 2: Now we need to install our developer tools. The. pkg- config is likely already installed, but be sure to include it just in case. We’ll be using. git to pull down the Open. CV repositories from Git. Hub. The. cmake package is used to configure our build. Step 3: Open. CV needs to be able to load various image file formats from disk, including JPEG, PNG, TIFF, etc. In order to load these image formats from disk, we’ll need our image I/O packages. Step 4: At this point, we have the ability to load a given image off of disk. But how do we display the actual image to our screen? The answer is the GTK development library, which the. Open. CV depends on to guild Graphical User Interfaces (GUIs). Step 5: We can load images using Open. CV, but what about processing video streams and accessing individual frames? We’ve got that covered here. Step 6: Install libraries that are used to optimize various routines inside of Open. CV. $ sudo apt- get install libatlas- base- dev gfortran. Step 7: Install. pip , a Python package manager. Step 8: Install virtualenv and virtualenvwrapper. These two packages allow us to create separate Python environments for each project we are working on. While installing. Open. CV 3. 0 and Python 2. Ubuntu system, I highly recommend it and the rest of this tutorial will assume you have them installed! Now that we have. WORKON_HOME=$HOME/. WORKON_HOME=$HOME/. This quick update will ensure that both. To make the changes to our. Lastly, we can create our. Open. CV 3. 0 + Python 2. Step 9: As I mentioned above, this tutorial covers how to install Open. CV 3. 0 and Python 2. I’ll have a Open. CV 3. 0 + Python 3 tutorial available later this month), so we’ll need to install our Python 2. Since Open. CV represents images as multi- dimensional Num. Py arrays, we better install Num. Py into our. cv virtual environment. Step 1. 0: Our environment is now all setup — we can proceed to change to our home directory, pull down Open. CV from Git. Hub, and checkout the. Itseez/opencv. git. Itseez/opencv. git$cdopencv$git checkout. Update (3 January 2. You can replace the. Be sure to check Open. CV. org for information on the latest release. As I mentioned last week, we also need the opencv_contrib repo as well. Without this repository, we won’t have access to standard keypoint detectors and local invariant descriptors (such as SIFT, SURF, etc.) that were available in the Open. CV 2. 4. X version. We’ll also be missing out on some of the newer Open. CV 3. 0 features like text detection in natural images. Itseez/opencv_contrib. Itseez/opencv_contrib. Again, make sure that you checkout the same version for. Time to setup the build. D CMAKE_BUILD_TYPE=RELEASE \. D CMAKE_INSTALL_PREFIX=/usr/local \. D INSTALL_C_EXAMPLES=ON \. D INSTALL_PYTHON_EXAMPLES=ON \. D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \. D BUILD_EXAMPLES=ON .$cd~/opencv$mkdirbuild$cdbuild$cmake- DCMAKE_BUILD_TYPE=RELEASE\- DCMAKE_INSTALL_PREFIX=/usr/local\- DINSTALL_C_EXAMPLES=ON\- DINSTALL_PYTHON_EXAMPLES=ON\- DOPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules\- DBUILD_EXAMPLES=ON. Update (3 January 2. In order to build Open. CV. 3. 1. 0 , you need to set. DINSTALL_C_EXAMPLES=OFF (rather than. ON ) in the. cmake command. There is a bug in the Open. CV v. 3. 1. 0 CMake build script that can cause errors if you leave this switch on. Once you set this switch to off, CMake should run without a problem. Notice how compared to last week our CMake command is substantially less verbose and requires less manual tweaking — this is because CMake is able to better automatically tune our install parameters (at least compared to OSX). Now we can finally compile Open. CV. $ make - j. 4Where you can replace the 4 with the number of available cores on your processor to speedup the compilation. Here’s an example of Open. CV 3. 0 compiling on my system: Figure 1: Open. CV 3. 0 with Python 2. Ubuntu 1. 4. 0. 4 system. Assuming that Open. CV compiled without error, you can now install it on your Ubuntu system. Step 1. 1: If you’ve reached this step without an error, Open. CV should now be installed in. However, our. cv virtual environment is located in our home directory — thus to use Open. CV within our. cv environment, we first need to sym- link Open. CV into the. site- packages directory of the. Step 1. 2: Congratulations! You have successfully installed Open. CV 3. 0 with Python 2. Ubuntu system! To confirm your installation, simply ensure that you are in the. Here’s an example of demonstrating the Open. CV 3. 0 and Python 2. Ubuntu machine: Figure 2: Open. CV 3. 0 with Python 2. Ubuntu! Step 1. 3: Now that Open. CV has been configured and installed, let’s build a quick Python script to detect the red game cartridge in the image named. Figure 3: Our goal is to detect the red game cartridge (on the right) in this image. Open up your favorite editor, create a new file, name it. Range(image, lower, upper). Contours(mask. copy(), cv. RETR_EXTERNAL. cv. CHAIN_APPROX_SIMPLE). Area). # approximate the contour. Length(c, True). approx = cv. Poly. DP(c, 0. 0. True). # draw a green bounding box surrounding the red game. Contours(image, [approx], - 1, (0, 2. Image", image). cv. Key(0)1. 23. 45. 67. Range(image,lower,upper)# find contours in the masked image and keep the largest one(_,cnts,_)=cv. Contours(mask. copy(),cv. RETR_EXTERNAL,cv. CHAIN_APPROX_SIMPLE)c=max(cnts,key=cv. Area)# approximate the contourperi=cv. Length(c,True)approx=cv. Poly. DP(c,0. 0. 5*peri,True)# draw a green bounding box surrounding the red gamecv. Contours(image,[approx],- 1,(0,2. Image",image)cv. 2. Key(0)You’ll also need to download the games. Once the. games. jpg file has been downloaded, you can execute the script via. Assuming that you have downloaded the. Figure 4: We have successfully detected the red game cartridge in the image! Notice how our script was able to successfully detect the red game cartridge in the right portion of the image, followed by drawing a green bounding box surrounding it. Obviously this isn’t the most exciting example in the world — but it has demonstrated that we have Open. CV 3. 0 with Python 2. Ubuntu system! So, what’s next? Congrats! You have a brand new, fresh install of Open. Install Open. CV3 on Ubuntu | Learn Open.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
November 2017
Categories |