Easy Python + OpenCV programming with Canopy

aim

For those who like, I will introduce how to build a Python integrated development environment called Canopy and an example of its use. It is very easy compared to building a C ++ & openCV environment using Visual studio etc. It is mainly aimed at students to faculty and staff (I will talk on the premise of an academic account). Also, I have introduced an example of building on Mac, but I think that there is not much difference on other platforms. For Linux and Windows Please read around the path setting appropriately.

Step 1 Open an account-Download

If you have a college email account like ***. Ac.jp, you can open an academic account with Canopy and get over 200 pre-build packages for free. If you do not have a university account, http://www.iu-tokyo.ac.jp/edu/entra/ http://www.i.kyoto-u.ac.jp/admission/guide.html Please refer to.

Step 2 Installation-Initial setting



  • Decide whether to use Canopy's python by default (can be changed later). kobito.1418787221.972218.png

In most cases yes is fine, but if you want or are creating a python development environment with Vim or Emacs, http://stackoverflow.com/questions/19617936/importerror-no-module-named-site-vim- and-enthought-canopy There is a problem that I get angry with an error around here.

  • In my case, Canopy python is not set as the default, but ipython, which is often used in Canopy, is created as an alias for enpkg, which will be described later. Please let me know if there is a better way around here. kobito.1418787531.691445.png

Step 3 Install the package

  • When you start Canopy, a window like this will appear. First, log in with the account you opened earlier and select Package Manager.

kobito.1418787608.128430.png


  • There are a lot of packages that can be updated like this

kobito.1418787657.428824.png


  • You can also find it by searching for OpenCV. Select Install to install. It's easy.

kobito.1418787708.844389.png


I want to do my best at the terminal

If you don't want to use such a GUI! I want to do my best on the terminal, use enpkg. I am exclusively an enpkg sect.

  • enpkg is here.

kobito.1418794148.808244.png


  • --whats-new will bring up a package that can be updated.

kobito.1418787909.465810.png


You can search for packages with + -s.

kobito.1418788060.607035.png


  • Install it.

kobito.1418788083.535679.png

Developed with iPython notebook

Canopy itself has a console editor, and development is possible by itself, but here, let's use iPython notebook, which is the web-based development environment of iPython.

  • Run ipython notebook on the terminal
  • Backup files etc. will be generated in the directory where ipython notebook is started.

kobito.1418790333.038322.png


  • The following screen will appear. Select the New Notebook on the right. kobito.1418790420.377056.png

  • With iPython notebook, you can write and execute scripts in text boxes called "cells".

kobito.1418790535.752484.png


  • You can also write functions and classes.

kobito.1418790595.188506.png


  • You can also write markdown by selecting Markdown from the pull-down menu on the left side of the menu.

kobito.1418790793.932163.png kobito.1418790709.589093.pngkobito.1418790717.607891.png


  • You can also write bash.

kobito.1418790912.356443.png


  • You can also write html.

kobito.1418790971.489943.png

Let's try OpenCV

Finally, let's briefly try out the features of openCV.

Image display

kobito.1418791217.305235.png

  • `` `% pylab inline``` is one of the functions called magic function, and by executing this, you can display the image inline.

Display of images acquired from the camera

kobito.1418791517.292589.png

  • ``` Time.time ()` `` returns the elapsed seconds from midnight (0:00:00 am) on January 1, 1970 as a float.
  • `cv2.VideoCapture (0)` will connect to the 0th connected camera. If you specify a video file here, that video will be loaded.
  • `cap.read ()` to capture the image and imshow to spit it out. In the above inline environment, the video does not play well, so here we will use the osx environment.
  • By doing `plt.draw ()`, the image will be updated interactively for the first time (easy to forget)

Face detection

Here, we will try the famous Viola & Jones cascading face detection.

  • Pick up a trained model for face detection. Let's write bash on notebook because it's a big deal. kobito.1418792138.620981.png
  • kobito.1418792473.383984.png

Bonus: Image processing with scikit image

In addition to openCV, Python has a package called scikit image, which has a method that is not implemented in openCV. For more information http://scikit-image.org/docs/dev/auto_examples/index.html

Image segmentation

kobito.1418793602.836684.png

  • `skimage.io.ImageCollection``` reads the image group that matches the argument as a list. For example, if you execute ```img = ImageCollection ('img * .png') `on the directory where img0.png, img1.png, ... img10.png is located, the i-th element will be the i-th. A list containing the images of is created.
  • SLIC implemented in `skimage.segmentation.slic``` is one of the image segmentation methods, and it is possible to divide the image into several superpixels as shown above. I can do it. `mark_boundaries``` is a function to draw it.

Recommended Posts

Easy Python + OpenCV programming with Canopy
Binarization with OpenCV / Python
3. 3. AI programming with Python
Python programming with Atom
Competitive programming with python
Programming with Python Flask
Easy TopView with OpenCV
Programming with Python and Tkinter
"Apple processing" with OpenCV3 + Python3
[Co-occurrence analysis] Easy co-occurrence analysis with Python! [Python]
Image editing with python OpenCV
Camera capture with Python + OpenCV
[Python] Using OpenCV with Python (Basic)
Easy folder synchronization with Python
Face detection with Python + OpenCV
Easy Python compilation with NUITKA-Utilities
Easy HTTP server with Python
Network programming with Python Scapy
Using OpenCV with Python @Mac
Shining life with Python and OpenCV
[Python] Easy parallel processing with Joblib
Neural network with OpenCV 3 and Python 3
[Python] Using OpenCV with Python (Image transformation)
[Python] Object-oriented programming learned with Pokemon
[Python] Using OpenCV with Python (Edge Detection)
Easy email sending with haste python3
Try face recognition with python + OpenCV
Bayesian optimization very easy with Python
Cut out face with Python + OpenCV
Face recognition with camera with opencv3 + python2.7
Load gif images with Python + OpenCV
Easy data visualization with Python seaborn.
Find image similarity with Python + OpenCV
Use OpenCV with Python 3 in Window
Draw an illustration with Python + OpenCV
Easy parallel execution with python subprocess
Track baseball balls with Python + OpenCV
Easy modeling with Blender and Python
Graph Based Segmentation with Python + OpenCV
[Python] Easy reading of serial number image files with OpenCV
Draw arrows (vectors) with opencv / python
Basic study of OpenCV with Python
Face detection with Python + OpenCV (rotation invariant)
Easy keyword extraction with TermExtract for Python
Competitive programming with python Local environment settings
[Python] Super easy test with assert statement
[Python] Easy argument type check with dataclass
Save video frame by frame with Python OpenCV
Easy introduction of speech recognition with Python
I tried non-photorealistic rendering with Python + opencv
Image processing with Python & OpenCV [Tone Curve]
Image acquisition from camera with Python + OpenCV
[Easy Python] Reading Excel files with openpyxl
[python, openCV] base64 Face recognition with images
Create miscellaneous Photoshop videos with Python + OpenCV ③ Create miscellaneous Photoshop videos
Easy web app with Python + Flask + Heroku
[Python] Read images with OpenCV (for beginners)
Easy image processing in Python with Pillow
[Easy Python] Reading Excel files with pandas
Easy introduction of python3 series and OpenCV3
Easy web scraping with Python and Ruby