PDF Archive

Easily share your PDF documents with your contacts, on the Web and Social Networks.

Send a file File manager PDF Toolbox Search Help Contact



Practical Python and OpenCV (1) .pdf



Original filename: Practical Python and OpenCV (1).pdf

This PDF 1.5 document has been generated by LaTeX with hyperref package / pdfTeX-1.40.13, and has been sent on pdf-archive.com on 06/11/2017 at 18:13, from IP address 191.4.x.x. The current document download page has been viewed 296 times.
File size: 8.3 MB (154 pages).
Privacy: public file




Download original PDF file









Document preview


Practical Python and
OpenCV: An Introductory,
Example Driven Guide to
Image Processing and
Computer Vision
Adrian Rosebrock

COPYRIGHT

The contents of this book, unless otherwise indicated, are
c
Copyright 2014
Adrian Rosebrock, PyImageSearch.com.
All rights reserved.
This version of the book was published on 13 February
2014.
Books like this are made possible by the time investment
made by the authors. If you received this book and did not
purchase it, please consider making future books possible
by buying a copy at http://www.pyimagesearch.com/prac
tical-python-opencv/ today.

ii

CONTENTS
1
2

3
4

5

6

introduction
python and required packages
2.1 NumPy and SciPy . . . . . . . . . . .
2.1.1 Windows . . . . . . . . . . . .
2.1.2 OSX . . . . . . . . . . . . . .
2.1.3 Linux . . . . . . . . . . . . . .
2.2 Matplotlib . . . . . . . . . . . . . . .
2.2.1 All Platforms . . . . . . . . .
2.3 OpenCV . . . . . . . . . . . . . . . . .
2.3.1 Windows and Linux . . . . .
2.3.2 OSX . . . . . . . . . . . . . .
2.4 Mahotas . . . . . . . . . . . . . . . . .
2.4.1 All Platforms . . . . . . . . .
2.5 Skip the Installation . . . . . . . . . .
loading, displaying, and saving
image basics
4.1 So, what’s a pixel? . . . . . . . . . .
4.2 Overview of the Coordinate System
4.3 Accessing and Manipulating Pixels .
drawing
5.1 Lines and Rectangles . . . . . . . . .
5.2 Circles . . . . . . . . . . . . . . . . .
image processing
6.1 Image Transformations . . . . . . . .
6.1.1 Translation . . . . . . . . . . .
6.1.2 Rotation . . . . . . . . . . . .
6.1.3 Resizing . . . . . . . . . . . .
6.1.4 Flipping . . . . . . . . . . . .

iii

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

1
5
6
6
7
7
7
8
8
9
9
10
10
10
11
15
15
18
18
27
27
32
37
37
38
43
48
54

Contents

6.1.5 Cropping . . . . . . . . . . . . .
6.2 Image Arithmetic . . . . . . . . . . . . .
6.3 Bitwise Operations . . . . . . . . . . . .
6.4 Masking . . . . . . . . . . . . . . . . . .
6.5 Splitting and Merging Channels . . . . .
6.6 Color Spaces . . . . . . . . . . . . . . . .
7 histograms
7.1 Using OpenCV to Compute Histograms
7.2 Grayscale Histograms . . . . . . . . . . .
7.3 Color Histograms . . . . . . . . . . . . .
7.4 Histogram Equalization . . . . . . . . . .
7.5 Histograms and Masks . . . . . . . . . .
8 smoothing and blurring
8.1 Averaging . . . . . . . . . . . . . . . . . .
8.2 Gaussian . . . . . . . . . . . . . . . . . .
8.3 Median . . . . . . . . . . . . . . . . . . .
8.4 Bilateral . . . . . . . . . . . . . . . . . . .
9 thresholding
9.1 Simple Thresholding . . . . . . . . . . .
9.2 Adaptive Thresholding . . . . . . . . . .
9.3 Otsu and Riddler-Calvard . . . . . . . .
10 gradients and edge detection
10.1 Laplacian and Sobel . . . . . . . . . . . .
10.2 Canny Edge Detector . . . . . . . . . . .
11 contours
11.1 Counting Coins . . . . . . . . . . . . . .
12 where to now?

iv

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

. . .
. . .
. . .
. . .
. . .
. . .

57
59
66
69
76
80
83
84
85
87
93
95
101
103
105
106
109
112
112
116
120
124
125
130
133
133
142

P R E FA C E

When I first set out to write this book, I wanted it to be
as hands-on as possible. I wanted lots of visual examples
with lots of code. I wanted to write something that you
could easily learn from, without all the rigor and detail of
mathematics associated with college level computer vision
and image processing courses.
I know that from all my years spent in the classroom that
the way I learned best was from simply opening up an editor and writing some code. Sure, the theory and examples
in my textbooks gave me a solid starting point. But I never
really “learned” something until I did it myself. I was very
hands on. And that’s exactly how I wanted this book to be.
Very hands on, with all the code easily modifiable and well
documented so you could play with it on your own. That’s
why I’m giving you the full source code listings and images
used in this book.
More importantly, I wanted this book to be accessible to
a wide range of programmers. I remember when I first
started learning computer vision – it was a daunting task.
But I learned a lot. And I had a lot of fun.
I hope this book helps you in your journey into computer
vision. I had a blast writing it. If you have any questions,
suggestions or comments, or if you simply want to say
hello, shoot me an email at adrian@pyimagesearch.com, or

v

Contents

you can visit my website at www.PyImageSearch.com and
leave a comment. I look forward to hearing from you soon!
-Adrian Rosebrock

vi

PREREQUISITES

In order to make the most of this, you will need to have
a little bit of programming experience. All examples in this
book are in the Python programming language. Familiarity,
with Python, or other scripting languages is suggested, but
not required.
You’ll also need to know some basic mathematics. This
book is hands-on and example driven: lots of examples and
lots of code, so even if you math skills are not up to par, do
not worry! The examples are very detailed and heavily documented to help you follow along.

vii

CONVENTIONS USED IN THIS BOOK

This book includes many code listings and terms to aide
you in your journey to learn computer vision and image
processing. Below are the typographical conventions used
in this book:
Italic
Indicates key terms and important information that
you should take note of. May also denote mathematical equations or formulas based on connotation.
Bold
Important information that you should take note of.
Constant width
Used for source code listings, as well as paragraphs
that make reference to the source code, such as function and method names.

viii


Related documents


PDF Document practical python and opencv 1
PDF Document 13n13 ijaet0313544 revised
PDF Document resume 2
PDF Document resume 2
PDF Document resume
PDF Document 22n13 ijaet0313536 revised


Related keywords