- Machine Learning for OpenCV
- Michael Beyeler
- 608字
- 2021-07-02 19:47:16
Verifying the installation
It's a good idea to double-check our installation. While our terminal is still open, we fire up IPython, which is an interactive shell to run Python commands:
$ ipython
Now make sure that you are running (at least) Python 3.5 and not Python 2.7. You might see the version number displayed in IPython's welcome message. If not, you can run the following commands:
In [1]: import sys
... print(sys.version)
3.5.3 |Continuum Analytics, Inc.| (default, Feb 22 2017, 21:28:42) [MSC v.1900 64 bit (AMD64)]
Now try to import OpenCV:
In [2]: import cv2
You should get no error messages. Then, try to find out the version number:
In [3]: cv2.__version__
Out[3]: '3.1.0'
Make sure that the Python version reads 3.5 or 3.6, but not 2.7. Additionally, make sure that OpenCV's version number reads at least 3.1.0; otherwise, you will not be able to use some OpenCV functionality later on.
You can then exit the IPython shell by typing exit - or hitting Ctrl + D and confirming that you want to quit.
Alternatively, you can run the code in a web browser thanks to Jupyter Notebook. If you have never heard of Jupyter Notebooks or played with them before, trust me - you will love them! If you followed the directions as mentioned earlier and installed the Python Anaconda stack, Jupyter is already installed and ready to go. In a terminal, type as follows:
$ jupyter notebook
This will automatically open a browser window, showing a list of files in the current directory. Click on the opencv-machine-learning folder, then on the notebooks folder, and voila! Here you will find all the code for this book, ready for you to be explored:

The notebooks are arranged by chapter and section. For the most part, they contain only the relevant code, but no additional information or explanations. These are reserved for those who support our effort by buying this book - so thank you!
Simply click on a notebook of your choice, such as 01.00-A-Taste-of-Machine-Learning.ipynb, and you will be able to run the code yourself by selecting Kernel > Restart & Run All:

There are a few handy keyboard shortcuts for navigating Jupyter Notebooks. However, the only ones that you need to know about right now are the following:
- Click in a cell in order to edit it.
- While the cell is selected, hit Ctrl + Enter to execute the code in it.
- Alternatively, hit Shift + Enter to execute a cell and select the cell below it.
- Hit Esc to exit write mode, then hit A to insert a cell above the currently selected one and B to insert a cell below.
However, I strongly encourage you to follow along the book by actually typing out the commands yourself, preferably in an IPython shell or an empty Jupyter Notebook. There is no better way to learn how to code than by getting your hands dirty. Even better if you make mistakes--we have all been there. At the end of the day, it's all about learning by doing!
- 多媒體CAI課件設計與制作導論(第二版)
- What's New in TensorFlow 2.0
- Learn to Create WordPress Themes by Building 5 Projects
- 少年輕松趣編程:用Scratch創作自己的小游戲
- 匯編語言程序設計(第2版)
- 網店設計看這本就夠了
- Mastering RStudio:Develop,Communicate,and Collaborate with R
- Learning ArcGIS for Desktop
- Getting Started with LLVM Core Libraries
- RSpec Essentials
- Qt 4開發實踐
- 計算機應用基礎(第二版)
- HTML5移動前端開發基礎與實戰(微課版)
- Python無監督學習
- Mastering Unity 2017 Game Development with C#(Second Edition)