100% found this document useful (3 votes)
36 views

(Ebook) Building Computer Vision Applications Using Artificial Neural Networks: With Step-by-Step Examples in OpenCV and TensorFlow with Python by Shamshad Ansari ISBN 9781484258866, 148425886X - The ebook in PDF/DOCX format is available for instant download

The document provides information about various ebooks related to building computer vision applications using artificial neural networks, including titles by Shamshad Ansari and others. It includes links to download these ebooks in multiple formats and offers insights into the content covered, such as image processing techniques and machine learning systems. Additionally, it outlines prerequisites for software installation and core concepts in image and video processing.

Uploaded by

tsueiahene
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
36 views

(Ebook) Building Computer Vision Applications Using Artificial Neural Networks: With Step-by-Step Examples in OpenCV and TensorFlow with Python by Shamshad Ansari ISBN 9781484258866, 148425886X - The ebook in PDF/DOCX format is available for instant download

The document provides information about various ebooks related to building computer vision applications using artificial neural networks, including titles by Shamshad Ansari and others. It includes links to download these ebooks in multiple formats and offers insights into the content covered, such as image processing techniques and machine learning systems. Additionally, it outlines prerequisites for software installation and core concepts in image and video processing.

Uploaded by

tsueiahene
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 83

Instant Ebook Access, One Click Away – Begin at ebooknice.

com

(Ebook) Building Computer Vision Applications


Using Artificial Neural Networks: With Step-by-
Step Examples in OpenCV and TensorFlow with Python
by Shamshad Ansari ISBN 9781484258866, 148425886X

https://ebooknice.com/product/building-computer-vision-
applications-using-artificial-neural-networks-with-step-by-
step-examples-in-opencv-and-tensorflow-with-python-50195836

OR CLICK BUTTON

DOWLOAD EBOOK

Get Instant Ebook Downloads – Browse at https://ebooknice.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

(Ebook) Building Computer Vision Applications Using Artificial Neural Networks, 2nd
Edition by Shamshad Ansari ISBN 9781484298657, 1484298659

https://ebooknice.com/product/building-computer-vision-applications-using-
artificial-neural-networks-2nd-edition-53726238

ebooknice.com

(Ebook) OpenCV with Python blueprints: design and develop advanced computer vision
projects using OpenCV with Python by Michael Beyeler ISBN 9781785282690, 1785282697

https://ebooknice.com/product/opencv-with-python-blueprints-design-and-develop-
advanced-computer-vision-projects-using-opencv-with-python-20640218

ebooknice.com

(Ebook) Learn OpenCV with Python by Examples: Implement Computer Vision Algorithms
Provided by OpenCV with Python for Image Processing, Object Detection and Machine
Learning by James Chen ISBN 9781738908448, 1738908445

https://ebooknice.com/product/learn-opencv-with-python-by-examples-implement-
computer-vision-algorithms-provided-by-opencv-with-python-for-image-processing-
object-detection-and-machine-learning-50883868

ebooknice.com

(Ebook) OpenCV 3 Computer Vision with Python Cookbook: Leverage the power of OpenCV
3 and Python to build computer vision applications by Alexey Spizhevoy, Aleksandr
Rybnikov ISBN 9781788474443, 1788474449

https://ebooknice.com/product/opencv-3-computer-vision-with-python-cookbook-
leverage-the-power-of-opencv-3-and-python-to-build-computer-vision-
applications-10447758

ebooknice.com
(Ebook) OpenCV Computer Vision with Python by Howse, Joseph ISBN 9781782163923,
1782163921

https://ebooknice.com/product/opencv-computer-vision-with-python-55662098

ebooknice.com

(Ebook) Artificial Neural Networks with Java - Tools for Building Neural Network
Applications by Igor Livshin ISBN 9781484244203, 1484244206

https://ebooknice.com/product/artificial-neural-networks-with-java-tools-for-
building-neural-network-applications-9951116

ebooknice.com

(Ebook) Ultimate Neural Network Programming with Python: Create Powerful Modern AI
Systems by Harnessing Neural Networks with Python, Keras, and TensorFlow by Rajput,
Vishal; ISBN 9789391246549, 9391246540

https://ebooknice.com/product/ultimate-neural-network-programming-with-python-
create-powerful-modern-ai-systems-by-harnessing-neural-networks-with-python-
keras-and-tensorflow-53620894

ebooknice.com

(Ebook) Computer Vision Using Deep Learning: Neural Network Architectures with
Python and Keras by Vaibhav Verdhan ISBN 9781484266151, 1484266153

https://ebooknice.com/product/computer-vision-using-deep-learning-neural-
network-architectures-with-python-and-keras-24606292

ebooknice.com

(Ebook) Artificial Neural Networks with Java: Tools for Building Neural Network
Applications, 2nd Edition by Igor Livshin ISBN 9781484273678, 1484273672

https://ebooknice.com/product/artificial-neural-networks-with-java-tools-for-
building-neural-network-applications-2nd-edition-35149846

ebooknice.com
Building Computer
Vision Applications
Using Artificial Neural
Networks
With Step-by-Step Examples in
OpenCV and TensorFlow with Python

Shamshad Ansari

www.allitebooks.com
Building Computer Vision
Applications Using
Artificial Neural Networks
With Step-by-Step Examples
in OpenCV and TensorFlow
with Python

Shamshad Ansari

www.allitebooks.com
Building Computer Vision Applications Using Artificial Neural Networks: With
Step-by-Step Examples in OpenCV and TensorFlow with Python
Shamshad Ansari
Centreville, VA, USA

ISBN-13 (pbk): 978-1-4842-5886-6 ISBN-13 (electronic): 978-1-4842-5887-3


https://doi.org/10.1007/978-1-4842-5887-3

Copyright © 2020 by Shamshad Ansari


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Celestin Suresh John
Development Editor: Matthew Moodie
Coordinating Editor: Aditee Mirashi
Cover designed by eStudioCalamar
Cover image designed by Pixabay
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-
sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a
Delaware corporation.
For information on translations, please e-mail [email protected], or visit www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/978-1-4842-5886-6. For more
detailed information, please visit www.apress.com/source-code.
Printed on acid-free paper

www.allitebooks.com
In God we trust.
To my wonderful parents, Abdul Samad and
Nazhat Parween, who always corrected my mistakes and
raised me to become a good person.
To my lovely wife, Shazia, and our two beautiful daughters,
Dua and Erum. Without their love and support, this book
would not have been possible.

www.allitebooks.com
Table of Contents
About the Author�����������������������������������������������������������������������������������������������������xv

About the Technical Reviewer�������������������������������������������������������������������������������xvii


Acknowledgments��������������������������������������������������������������������������������������������������xix

Introduction������������������������������������������������������������������������������������������������������������xxi

Chapter 1: Prerequisites and Software Installation�������������������������������������������������� 1


Python and PIP������������������������������������������������������������������������������������������������������������������������������ 2
Installing Python and PIP on Ubuntu���������������������������������������������������������������������������������������� 2
Installing Python and PIP on macOS���������������������������������������������������������������������������������������� 2
Installing Python and PIP on CentOS 7������������������������������������������������������������������������������������ 3
Installing Python and PIP on Windows������������������������������������������������������������������������������������� 3
virtualenv�������������������������������������������������������������������������������������������������������������������������������������� 3
Installing and Activating virtualenv����������������������������������������������������������������������������������������� 4
TensorFlow������������������������������������������������������������������������������������������������������������������������������������ 5
Installing TensorFlow��������������������������������������������������������������������������������������������������������������� 5
PyCharm IDE��������������������������������������������������������������������������������������������������������������������������������� 5
Installing PyCharm������������������������������������������������������������������������������������������������������������������ 6
Configuring PyCharm to Use virtualenv����������������������������������������������������������������������������������� 6
OpenCV����������������������������������������������������������������������������������������������������������������������������������������� 7
Working with OpenCV�������������������������������������������������������������������������������������������������������������� 7
Installing OpenCV4 with Python Bindings�������������������������������������������������������������������������������� 8
Additional Libraries����������������������������������������������������������������������������������������������������������������������� 8
Installing SciPy������������������������������������������������������������������������������������������������������������������������ 8
Installing Matplotlib����������������������������������������������������������������������������������������������������������������� 8

www.allitebooks.com
Table of Contents

Chapter 2: Core Concepts of Image and Video Processing��������������������������������������� 9


Image Processing������������������������������������������������������������������������������������������������������������������������� 9
Image Basics������������������������������������������������������������������������������������������������������������������������������� 10
Pixels������������������������������������������������������������������������������������������������������������������������������������������ 10
Pixel Color������������������������������������������������������������������������������������������������������������������������������ 10
Coordinate Systems�������������������������������������������������������������������������������������������������������������������� 11
Python and OpenCV Code to Manipulate Images������������������������������������������������������������������������ 14
Program: Loading, Exploring, and Showing an Image����������������������������������������������������������� 15
Program: OpenCV Code to Access and Manipulate Pixels����������������������������������������������������� 17
Drawing��������������������������������������������������������������������������������������������������������������������������������������� 18
Drawing a Line on an Image�������������������������������������������������������������������������������������������������� 18
Drawing a Rectangle on an Image���������������������������������������������������������������������������������������� 21
Drawing a Circle on an Image����������������������������������������������������������������������������������������������� 25
Summary������������������������������������������������������������������������������������������������������������������������������������ 26

Chapter 3: Techniques of Image Processing����������������������������������������������������������� 27


Transformation���������������������������������������������������������������������������������������������������������������������������� 27
Resizing��������������������������������������������������������������������������������������������������������������������������������� 28
Translation����������������������������������������������������������������������������������������������������������������������������� 32
Rotation��������������������������������������������������������������������������������������������������������������������������������� 34
Flipping���������������������������������������������������������������������������������������������������������������������������������� 37
Cropping�������������������������������������������������������������������������������������������������������������������������������� 40
Image Arithmetic and Bitwise Operations����������������������������������������������������������������������������������� 42
Addition��������������������������������������������������������������������������������������������������������������������������������� 43
Subtraction���������������������������������������������������������������������������������������������������������������������������� 46
Bitwise Operations���������������������������������������������������������������������������������������������������������������� 52
Masking�������������������������������������������������������������������������������������������������������������������������������������� 58
Splitting and Merging Channels�������������������������������������������������������������������������������������������������� 61
Noise Reduction Using Smoothing and Blurring������������������������������������������������������������������������� 64
Mean Filtering or Averaging�������������������������������������������������������������������������������������������������� 64
Gaussian Filtering������������������������������������������������������������������������������������������������������������������ 67

vi
Table of Contents

Median Blurring��������������������������������������������������������������������������������������������������������������������� 69
Bilateral Blurring������������������������������������������������������������������������������������������������������������������� 71
Binarization with Thresholding��������������������������������������������������������������������������������������������������� 74
Simple Thresholding�������������������������������������������������������������������������������������������������������������� 74
Adaptive Thresholding����������������������������������������������������������������������������������������������������������� 77
Otsu’s Binarization����������������������������������������������������������������������������������������������������������������� 79
Gradients and Edge Detection����������������������������������������������������������������������������������������������������� 82
Sobel Derivatives (cv2.Sobel() Function)������������������������������������������������������������������������������� 82
Laplacian Derivatives (cv2.Laplacian() Function)������������������������������������������������������������������ 87
Canny Edge Detection����������������������������������������������������������������������������������������������������������� 89
Contours�������������������������������������������������������������������������������������������������������������������������������������� 90
Drawing Contours������������������������������������������������������������������������������������������������������������������ 93
Summary������������������������������������������������������������������������������������������������������������������������������������ 94

Chapter 4: Building a Machine Learning–Based Computer Vision System������������� 95


Image Processing Pipeline���������������������������������������������������������������������������������������������������������� 95
Feature Extraction����������������������������������������������������������������������������������������������������������������������� 97
How to Represent Features��������������������������������������������������������������������������������������������������� 98
Color Histogram��������������������������������������������������������������������������������������������������������������������� 99
Histogram Equalizer������������������������������������������������������������������������������������������������������������ 106
GLCM����������������������������������������������������������������������������������������������������������������������������������� 109
HOGs������������������������������������������������������������������������������������������������������������������������������������ 115
LBP�������������������������������������������������������������������������������������������������������������������������������������� 121
Feature Selection���������������������������������������������������������������������������������������������������������������������� 128
Filter Method����������������������������������������������������������������������������������������������������������������������� 128
Wrapper Method������������������������������������������������������������������������������������������������������������������ 129
Embedded Method�������������������������������������������������������������������������������������������������������������� 130
Model Training��������������������������������������������������������������������������������������������������������������������������� 130
How to Do Machine Learning���������������������������������������������������������������������������������������������� 130
Supervised Learning������������������������������������������������������������������������������������������������������������ 131
Unsupervised Learning�������������������������������������������������������������������������������������������������������� 132

vii
Table of Contents

Model Deployment�������������������������������������������������������������������������������������������������������������������� 133


Summary���������������������������������������������������������������������������������������������������������������������������������� 135

Chapter 5: Deep Learning and Artificial Neural Networks������������������������������������ 137


Introduction to Artificial Neural Networks��������������������������������������������������������������������������������� 137
Perceptron��������������������������������������������������������������������������������������������������������������������������� 140
Multilayer Perceptron���������������������������������������������������������������������������������������������������������� 141
What Is Deep Learning?������������������������������������������������������������������������������������������������������ 143
Deep Learning or Multilayer Perceptron Architecture��������������������������������������������������������� 143
Activation Functions������������������������������������������������������������������������������������������������������������ 146
Feedforward������������������������������������������������������������������������������������������������������������������������ 154
Error Function���������������������������������������������������������������������������������������������������������������������� 154
Optimization Algorithms������������������������������������������������������������������������������������������������������ 158
Backpropagation����������������������������������������������������������������������������������������������������������������� 164
Introduction to TensorFlow�������������������������������������������������������������������������������������������������������� 165
TensorFlow Installation�������������������������������������������������������������������������������������������������������� 166
How to Use TensorFlow������������������������������������������������������������������������������������������������������� 166
Tensor���������������������������������������������������������������������������������������������������������������������������������� 166
Variable�������������������������������������������������������������������������������������������������������������������������������� 167
Constant������������������������������������������������������������������������������������������������������������������������������ 167
Our First Computer Vision Model with Deep Learning: Classification of Handwritten Digits���� 169
Model Evaluation����������������������������������������������������������������������������������������������������������������������� 178
Overfitting���������������������������������������������������������������������������������������������������������������������������� 179
Hyperparameters���������������������������������������������������������������������������������������������������������������������� 184
TensorBoard������������������������������������������������������������������������������������������������������������������������ 185
Experiments for Hyperparameter Tuning����������������������������������������������������������������������������� 185
Saving and Restoring Model����������������������������������������������������������������������������������������������������� 189
Save Model Checkpoints During Training���������������������������������������������������������������������������� 190
Manually Save Weights������������������������������������������������������������������������������������������������������� 193
Load the Saved Weights and Retrain the Model������������������������������������������������������������������ 193
Saving the Entire Model������������������������������������������������������������������������������������������������������ 193

viii
Table of Contents

Retraining the Existing Model���������������������������������������������������������������������������������������������� 194


Using a Trained Model in Applications��������������������������������������������������������������������������������� 194
Convolution Neural Network����������������������������������������������������������������������������������������������������� 194
Architecture of CNN������������������������������������������������������������������������������������������������������������� 195
How Does CNN Work����������������������������������������������������������������������������������������������������������� 196
Summary of CNN Concepts������������������������������������������������������������������������������������������������� 201
Training a CNN Model: Pneumonia Detection from Chest X-rays���������������������������������������� 202
Examples of Popular CNNs�������������������������������������������������������������������������������������������������� 213
Summary����������������������������������������������������������������������������������������������������������������������������� 217

Chapter 6: Deep Learning in Object Detection������������������������������������������������������ 219


Object Detection������������������������������������������������������������������������������������������������������������������������ 219
Intersection Over Union������������������������������������������������������������������������������������������������������������� 220
Region-Based Convolutional Neural Network��������������������������������������������������������������������������� 222
Fast R-CNN������������������������������������������������������������������������������������������������������������������������������� 224
Faster R-CNN���������������������������������������������������������������������������������������������������������������������������� 225
Region Proposal Network���������������������������������������������������������������������������������������������������� 226
Fast R-CNN�������������������������������������������������������������������������������������������������������������������������� 227
Mask R-CNN������������������������������������������������������������������������������������������������������������������������������ 227
Backbone����������������������������������������������������������������������������������������������������������������������������� 228
RPN�������������������������������������������������������������������������������������������������������������������������������������� 229
Output Head������������������������������������������������������������������������������������������������������������������������� 229
What Is the Significance of the Masks?������������������������������������������������������������������������������ 230
Mask R-CNN in Human Pose Estimation����������������������������������������������������������������������������� 230
Single-Shot Multibox Detection������������������������������������������������������������������������������������������������ 231
SSD Network Architecture��������������������������������������������������������������������������������������������������� 232
Training�������������������������������������������������������������������������������������������������������������������������������� 235
SSD Results������������������������������������������������������������������������������������������������������������������������� 238
YOLO������������������������������������������������������������������������������������������������������������������������������������������ 238
YOLO Network Design���������������������������������������������������������������������������������������������������������� 240
Limitations of YOLO������������������������������������������������������������������������������������������������������������������� 241

ix
Table of Contents

YOLO9000 or YOLOv2����������������������������������������������������������������������������������������������������������� 241


YOLOv3�������������������������������������������������������������������������������������������������������������������������������� 244
Comparison of Object Detection Algorithms����������������������������������������������������������������������������� 247
Comparison of Architecture������������������������������������������������������������������������������������������������� 247
Comparison of Performance������������������������������������������������������������������������������������������������ 248
Training Object Detection Model Using TensorFlow������������������������������������������������������������������ 249
TensorFlow on Google Colab with GPU�������������������������������������������������������������������������������� 250
Detecting Objects Using Trained Models����������������������������������������������������������������������������������� 274
Installing TensorFlow’s models Project������������������������������������������������������������������������������� 274
Code for Object Detection���������������������������������������������������������������������������������������������������� 277
Training a YOLOv3 Model for Object Detection�������������������������������������������������������������������������� 290
Installing the Darknet Framework��������������������������������������������������������������������������������������� 291
Downloading Pre-trained Convolutional Weights���������������������������������������������������������������� 292
Downloading an Annotated Oxford-IIIT Pet Dataset������������������������������������������������������������� 292
Preparing the Dataset���������������������������������������������������������������������������������������������������������� 293
Configuring the Training Input��������������������������������������������������������������������������������������������� 297
Configuring the Darknet Neural Network���������������������������������������������������������������������������� 298
Training a YOLOv3 Model����������������������������������������������������������������������������������������������������� 299
How Long the Training Should Run�������������������������������������������������������������������������������������� 301
Final Model�������������������������������������������������������������������������������������������������������������������������� 301
Detecting Objects Using a Trained YOLOv3 Model��������������������������������������������������������������������� 302
Installing Darknet to the Local Computer���������������������������������������������������������������������������� 302
Python Code for Object Detection���������������������������������������������������������������������������������������� 303
Summary���������������������������������������������������������������������������������������������������������������������������������� 307

Chapter 7: Practical Example: Object Tracking in Videos������������������������������������� 309


Preparing the Working Environment����������������������������������������������������������������������������������������� 310
Reading a Video Stream������������������������������������������������������������������������������������������������������������ 312
Loading the Object Detection Model����������������������������������������������������������������������������������������� 314
Detecting Objects in Video Frames������������������������������������������������������������������������������������������� 315
Creating a Unique Identity for Objects Using dHash����������������������������������������������������������������� 317
Using the Hamming Distance to Determine Image Similarity��������������������������������������������������� 319

x
Table of Contents

Object Tracking������������������������������������������������������������������������������������������������������������������������� 319


Displaying a Live Video Stream in a Web Browser�������������������������������������������������������������������� 322
Installing Flask�������������������������������������������������������������������������������������������������������������������� 322
Flask Directory Structure���������������������������������������������������������������������������������������������������� 322
HTML for Displaying a Video Stream����������������������������������������������������������������������������������� 323
Flask to Load the HTML Page���������������������������������������������������������������������������������������������� 324
Flask to Serve the Video Stream����������������������������������������������������������������������������������������� 324
Running the Flask Server���������������������������������������������������������������������������������������������������� 325
Putting It All Together���������������������������������������������������������������������������������������������������������������� 325
Summary���������������������������������������������������������������������������������������������������������������������������������� 336

Chapter 8: Practical Example: Face Recognition�������������������������������������������������� 337


FaceNet������������������������������������������������������������������������������������������������������������������������������������� 338
FaceNet Neural Network Architecture��������������������������������������������������������������������������������� 338
Training a Face Recognition Model������������������������������������������������������������������������������������������� 344
Checking Out FaceNet from GitHub������������������������������������������������������������������������������������� 345
Dataset�������������������������������������������������������������������������������������������������������������������������������� 345
Downloading VGGFace2 Data���������������������������������������������������������������������������������������������� 347
Data Preparation������������������������������������������������������������������������������������������������������������������ 349
Model Training��������������������������������������������������������������������������������������������������������������������� 351
Evaluation���������������������������������������������������������������������������������������������������������������������������� 353
Developing a Real-Time Face Recognition System������������������������������������������������������������������� 354
Face Detection Model���������������������������������������������������������������������������������������������������������� 354
Classifier for Face Recognition�������������������������������������������������������������������������������������������� 355
Summary���������������������������������������������������������������������������������������������������������������������������������� 360

Chapter 9: Industrial Application: Real-Time Defect Detection in Industrial


Manufacturing������������������������������������������������������������������������������������������������������ 361
Real-Time Surface Defect Detection System���������������������������������������������������������������������������� 362
Dataset�������������������������������������������������������������������������������������������������������������������������������� 362
Google Colab Notebook������������������������������������������������������������������������������������������������������� 364
Data Transformation������������������������������������������������������������������������������������������������������������ 365
Training the SSD Model������������������������������������������������������������������������������������������������������� 374

xi
Table of Contents

Exporting the Model������������������������������������������������������������������������������������������������������������ 377


Model Evaluation����������������������������������������������������������������������������������������������������������������� 378
Prediction���������������������������������������������������������������������������������������������������������������������������� 379
Real-Time Defect Detector�������������������������������������������������������������������������������������������������� 380
Image Annotations�������������������������������������������������������������������������������������������������������������������� 380
Installing VoTT��������������������������������������������������������������������������������������������������������������������� 381
Create Connections������������������������������������������������������������������������������������������������������������� 382
Create a New Project����������������������������������������������������������������������������������������������������������� 383
Create Class Labels������������������������������������������������������������������������������������������������������������� 384
Label the Images����������������������������������������������������������������������������������������������������������������� 385
Export Labels����������������������������������������������������������������������������������������������������������������������� 386
Summary���������������������������������������������������������������������������������������������������������������������������������� 387

Chapter 10: Computer Vision Modeling on the Cloud������������������������������������������� 389


TensorFlow Distributed Training������������������������������������������������������������������������������������������������ 390
What Is Distributed Training?����������������������������������������������������������������������������������������������� 390
TensorFlow Distribution Strategy���������������������������������������������������������������������������������������� 393
TF_CONFIG: TensorFlow Cluster Configuration�������������������������������������������������������������������� 398
Example Code of Distributed Training with a Parameter Server����������������������������������������������� 400
Steps for Running Distributed Training on the Cloud���������������������������������������������������������������� 404
Distributed Training on Google Cloud���������������������������������������������������������������������������������������� 406
Signing Up for GCP Access�������������������������������������������������������������������������������������������������� 406
Creating a Google Cloud Storage Bucket����������������������������������������������������������������������������� 407
Creating the GCS Bucket from the Web UI��������������������������������������������������������������������������� 407
Creating the GCS Bucket from the Cloud Shell�������������������������������������������������������������������� 409
Launching GCP Virtual Machines����������������������������������������������������������������������������������������� 410
SSH to Log In to Each VMs�������������������������������������������������������������������������������������������������� 414
Uploading the Code for Distributed Training or Cloning the GitHub Repository������������������� 415
Installing Prerequisites and TensorFlow������������������������������������������������������������������������������ 415
Running Distributed Training����������������������������������������������������������������������������������������������� 416
Distributed Training on Azure���������������������������������������������������������������������������������������������������� 417

xii
Table of Contents

Creating a VM with Multiple GPUs on Azure������������������������������������������������������������������������ 418


Installing GPU Drivers and Libraries������������������������������������������������������������������������������������ 422
Creating virtualenv and Installing TensorFlow��������������������������������������������������������������������� 424
Implementing MirroredStrategy������������������������������������������������������������������������������������������ 424
Running Distributed Training����������������������������������������������������������������������������������������������� 425
Distributed Training on AWS������������������������������������������������������������������������������������������������������ 428
Horovod������������������������������������������������������������������������������������������������������������������������������� 428
How to Use Horovod������������������������������������������������������������������������������������������������������������ 429
Creating a Horovod Cluster on AWS������������������������������������������������������������������������������������� 433
Installing Horovod���������������������������������������������������������������������������������������������������������������� 440
Running Horovod to Execute Distributed Training��������������������������������������������������������������� 441
Summary���������������������������������������������������������������������������������������������������������������������������������� 442

Index��������������������������������������������������������������������������������������������������������������������� 443

xiii
About the Author
Shamshad (Sam) Ansari is president and CEO of Accure
Inc., an artificial intelligence automation company that he
founded. He has raised Accure from startup to a sustainable
business by building a winning team and acquiring customers
from across the globe. He has technical expertise in the areas
of computer vision, machine learning, AI, cognitive science,
NLP, and big data. He architected, designed, and developed
the Momentum platform that automates AI solution
development. He is an inventor and has four US patents in the
areas of AI and cognitive computing.
Shamshad previously worked as a senior software engineer with IBM, as VP of
engineering with Orbit Solutions, and as principal architect and director of engineering
with Apixio.

xv
About the Technical Reviewer
James Baldo is an associate professor at George Mason
University in the Volgenau School of Engineering and the
director of the Data Analytics Engineering (DAEN) Program.
His 38 years as a practicing engineer has provided him
with a broad foundation of knowledge and experience
in data analytics and engineering systems. His data
analytics interests span the areas of data engineering, data
science, and data architecture with a focus on data-centric
applications. His software engineering expertise has been
in support of deploying applications to cloud-based environments and microservice
architectures. As director of the DAEN Program, he has been responsible for developing
and coordinating its new online program offering. He holds a BS in chemistry, MS in
chemistry, MS in computer engineering, and PhD in information technology/software
engineering. He enjoys canoeing, hiking, and golf, and he lives in Manassas, Virginia,
with his wife.

xvii
Acknowledgments
I decided to write this book because I wanted to achieve two objectives: build the
computer vision concepts from the ground up to an advanced level, and provide a guide
to apply the concepts in building real-world vision systems. I will demonstrate every
single concept with use cases and code examples. I have organized the topics, connected
the contents to meaningful and practical use cases, and made sure the code was working
and fully tested. It all required my undivided attention, and I could not have done it
without the support of my family. I can’t thank my wife enough for taking care of our two
daughters and keeping them occupied while I was busy writing this book. She turned
this into a positive experience for them and for me: The kids started keeping track of my
progress and celebrated every time I finished a section, subsection, or chapter. In turn,
this gave me tremendous energy and motivation that I thoroughly enjoyed while working
on this book. I just don’t know what magic my wife used to do this.
My life is indebted to Anumati Bhagi and Ashok Bhagi, who are no less than parents
to me; their love and support always motivate me.
This book is a collection of my lifetime experiences that I gained by working with
some of the greatest engineers, data scientists, and business professionals. I would
like to thank all my colleagues at Accure and all the past companies I have worked at. I
sincerely thank all my teachers, professors, and mentors who enlightened me with their
knowledge and wisdom.
It has been a great experience working with the Apress editorial team. Aditee
Marashi, the coordinating editor, has been prompt with her responses to any question
I have had. She has also been instrumental in keeping track of the schedule. Hats off to
her. It’s been awesome working with Mathew Moodie, the development editor. Thank
you, Aditee and Matt.
My special thanks go to John Celestine, the senior editor. He is a thorough,
thoughtful, and fast decision-maker. Thank you, John, for believing in me. Thanks to
Apress for publishing this book.

xix
Acknowledgments

Professor James Baldo was the most valuable contributor to the book. As a technical
reviewer, he executed every single line of code and made sure that they all worked. He
reviewed every single word of the book, cross-checked references, and provided some
key suggestions that made this book much more valuable than I ever imagined. Thank
you, Professor Baldo.
Finally, I would like to thank the readers of this book. I would love to hear from you
all. Please send your comments, suggestions, and questions to [email protected]. As
the technology evolves, some of the code examples of this book may require updating. I
will try my best to keep all the code up-to-date at the book’s GitHub site. I look forward
to hearing from you.

xx
Introduction
For more than 20 years I have had the pleasure of working with some of the greatest
data scientists and computer vision experts. Along the way I have learned a lot,
especially the best practices of building large-scale computer vision systems. In this
book I present the learnings from my own personal experience and the experience of
people I have had opportunities to work with. I also present the work of some of the
greatest contributors and thought leaders of computer vision, even though I have not
had a chance to work with them. I have provided references to their work at appropriate
places throughout the book.
When I hire new engineers and scientists, one of my biggest challenges has been
to provide them with systematic training so that they can start contributing to the
development of vision systems in the shortest possible time. There are a large number of
online resources and books available on various topics related to computer vision, and it
is easy to get lost in the piles of information they present, given that the field of computer
vision is vast and complex. In this book, I attempted to provide a structured and
systematic approach of building the key concepts and working through example code to
develop real-world computer vision systems. I hope this helps you connect the dots as
you read through the chapters. My goal is to keep this book as practical and hands-on as
possible.
This book starts with the introduction of core concepts of computer vision and
provides code examples to aid in the learning of those concepts. The code examples in
the early part of the book are mainly based on OpenCV with Python.
This book also covers the basic concepts of machine learning and gradually develops
the advanced-level concepts of artificial neural networks or deep learning. Every single
concept is followed by working code examples of real-world use cases. All machine
learning–related code examples are written in TensorFlow with Python.
In this book, there are eight real-world use cases of computer vision with working
code. These use cases are from various industries, such as healthcare, security,
surveillance, and manufacturing. I have provided line-by-line explanations to help you

xxi
Introduction

understand the code. There are three chapters dedicated to practical use cases. These
chapters demonstrate how to build the vision systems from the ground up, starting from
image/video acquisition to building a data pipeline, model training, and deployment.
Training state-of-the-art computer vision models requires a lot of hardware
resources. It is desirable and economically beneficial to train computer vision models on
a cloud infrastructure to leverage the latest hardware resources, such as GPUs, and pay-­
as-­you-go cost models. The last chapter, Chapter 10, provides step-by-step instructions
for building machine learning–based computer vision applications on the three popular
cloud infrastructures: Google Cloud Platform, Amazon AWS, and Microsoft Azure.
Though the book develops the concepts from one pixel all the way to model training
on the cloud, it has certain prerequisites. You should have a working knowledge of the
Python programming language. This book is intended to help working professionals,
programmers, data scientists, and undergraduate and graduate students gain practical
knowledge of building computer vision applications using artificial neural networks.

xxii
CHAPTER 1

Prerequisites and
Software Installation
This is a hands-on book that describes how to develop computer vision applications
in the Python programming language. In this book, you will learn how to work with
OpenCV to manipulate images and build machine learning models using TensorFlow.
OpenCV, originally developed by Intel and written in C++, is an open source
computer vision and machine learning library consisting of more than 2,500 optimized
algorithms for working with images and videos. TensorFlow is an open source
framework for high-performance numerical computation and large-scale machine
learning. It is written in C++ and provides native support for GPUs. Python is the most
widely used programming language for developing machine learning applications. It is
designed to work with C++. Both TensorFlow and OpenCV provide Python interfaces
to access their low-level functionality. Although TensorFlow and OpenCV provide
interfaces in other programming languages, such as Java, C++, and MATLAB, we will
use Python as the primary language because of its simplicity and its large community of
support.
The prerequisites for this book are practical knowledge of Python and familiarity
with NumPy and Pandas. The book assumes that you are familiar with built-in data
containers in Python, such as dictionaries, lists, sets, and tuples. Here are some
resources that may be helpful to meet the prerequisites:

• Python: https://www.w3schools.com/python/

• Pandas: https://pandas.pydata.org/docs/getting_started/
index.html
• NumPy: https://numpy.org/devdocs/user/quickstart.html

1
© Shamshad Ansari 2020
S. Ansari, Building Computer Vision Applications Using Artificial Neural Networks,
https://doi.org/10.1007/978-1-4842-5887-3_1
Chapter 1 Prerequisites and Software Installation

Before we go any further, let’s prepare our working environment and set ourselves up
for the exercises we will be doing as we move along. Here we will start by downloading
and installing the required software libraries and packages.

Python and PIP


Python is our main programming language. PIP is a package installer for Python and a
de facto standard for installing and managing Python packages. To set up our working
environment, we will begin by installing Python and PIP on our working computer. The
installation steps depend on the operating system (OS) you are using. Make sure you
follow the instructions for your OS. If you already have Python and PIP installed, ensure
that you are using Python version 3.6 or greater and PIP version 19 or greater. To check
the version number of Python, execute the following command on your terminal:

$ python3 --version

The output of this command should be something like this: Python 3.6.5.
To check the version number of PIP, execute the following command on your
terminal:

$ pip3 --version

This command should show a version number of PIP 3, for example, PIP 19.1.

Installing Python and PIP on Ubuntu


Run the following commands in your Ubuntu terminal:

sudo apt update


sudo apt install python3-dev python3-pip

Installing Python and PIP on macOS


Run the following commands on macOS:

brew update
brew install python

This will install both Python and PIP.


2
Chapter 1 Prerequisites and Software Installation

Installing Python and PIP on CentOS 7


Run the following commands on CentOS 7:

sudo yum install rh-python36


sudo yum groupinstall 'Development Tools'

Installing Python and PIP on Windows


Install the Microsoft Visual C++ 2015 Redistributable Update 3. This comes with Visual
Studio 2015 but can be installed separately by following these steps:

1. Go to the Visual Studio downloads at https://visualstudio.


microsoft.com/vs/older-downloads/.

2. Select Redistributables and Build Tools.

3. Download and install the Microsoft Visual C++ 2015


Redistributable Update 3.

Make sure long paths are enabled on Windows. Here are the instructions to do that:
https://superuser.com/questions/1119883/windows-10-enable-ntfs-long-paths-
policy-option-missing.
Install the 64-bit Python 3 release for Windows from https://www.python.org/
downloads/windows/ (select PIP as an optional feature).
If these installation instructions do not work in your situation, refer to the official
Python documentation at https://www.python.org/.

v irtualenv
virtualenv is a tool to create isolated Python environments. virtualenv creates a directory
containing all the necessary executables to use the packages that a Python project will
need. virtualenv provides the following advantages:

• virtualenv allows you to have two versions of the same library so that
both your programs continue to run. Say you have a program that
requires version 1 of a Python library and another program needs
version 2 of the same library; virtualenv will allow you to run both.

3
Chapter 1 Prerequisites and Software Installation

• virtualenv creates a useful stand-alone and self-contained


environment for your development work that could be utilized for a
production environment without needing to install dependencies.

Next, we will install virtualenv and configure the environment with all the required
software. For the remainder of the book, we will assume that our reference program
dependencies will be contained in this virtualenv.
Install virtualenv using the following PIP command (the command is the same
on all OSs):

$ sudo pip3 install -U virtualenv

This will install virtualenv system-wide.

Installing and Activating virtualenv


First, create a directory where you want to set up virtualenv. I have named this directory
cv (short for “computer vision”).

$ mkdir cv
Then create the virtualenv in this directory, cv
$ virtualenv --system-site-packages -p python3 ./cv

The following is a sample output from running this command (on my MacBook):

Running virtualenv with interpreter /anaconda3/bin/python3


Already using interpreter /anaconda3/bin/python3
Using base prefix '/anaconda3'
New python executable in /Users/sansari/cv/bin/python3
Also creating executable in /Users/sansari/cv/bin/python
Installing setuptools, pip, wheel...
done.

Activate the virtual environment using a shell-specific command.

$ source ./cv/bin/activate  # for sh, bash, ksh, or zsh

When virtualenv is active, your shell prompt is prefixed with (cv). Here’s an
example:

(cv) Shamshads-MacBook-Air:~ sansari$


4
Chapter 1 Prerequisites and Software Installation

Install packages within a virtual environment without affecting the host system
setup. Start by upgrading PIP (make sure you do not run any command as root or sudo
while in virtualenv).

$ pip install --upgrade pip

$ pip list  # show packages installed within the virtual environment

When you are done and you want to exit from virtualenv, do the following:

$ deactivate  # don't exit until you're done with your programming

T ensorFlow
TensorFlow is an open source library for numerical computation and large-scale
machine learning. You will learn more about TensorFlow in subsequent chapters. Let’s
first install it and get it ready for our deep learning exercises.

I nstalling TensorFlow
We will install the latest version of TensorFlow from PyPI (https://pypi.org/project/
tensorflow/). We will install TensorFlow for CPUs. Make sure you are in virtualenv and
run the following command:

(cv) $ pip install --upgrade tensorflow

Test your TensorFlow installation by running this command:

(cv) $ python -c "import tensorflow as tf"

If TensorFlow is successfully installed, the output should not show any errors.

P
 yCharm IDE
You can use your favorite IDE for writing and managing Python code, but for the purpose
of this book, we will use the community version of PyCharm, a Python IDE.

5
Chapter 1 Prerequisites and Software Installation

Installing PyCharm
Go to the official website of PyCharm at https://www.jetbrains.com/pycharm/
download/#section=linux, select the appropriate operating system, and click Download
(under Community Version). After the download is completed, click the downloaded
package, and follow the on-screen instructions. Here are the direct links for different
operating systems:

• Linux: https://www.jetbrains.com/pycharm/download/download-­
thanks.html?platform=linux&code=PCC

• Mac: https://www.jetbrains.com/pycharm/download/download-­
thanks.html?platform=mac&code=PCC

• Windows: ­https://www.jetbrains.com/pycharm/download/
download-thanks.html?platform=windows&code=PCC

Configuring PyCharm to Use virtualenv


Follow these steps to use the virtualenv, cv, we created earlier:

1. Launch the PyCharm IDE and select File ➤ Settings for Windows
and Linux or select PyCharm ➤ Preferences for macOS.

2. In the Settings/Preferences dialog, select Project <project name> ➤


Project Interpreter.

3. Click the icon and click Add.


4. In the left pane of the Add Python Interpreter dialog, select
Existing Environment.

5. Expand the Interpreter list and select any of the existing


interpreters. Alternatively, click and specify a path to the
Python executable in your file system, for example, /Users/
sansari/cv/bin/python3.6 (see Figure 1-1).
6. Select the checkbox “Make available to all projects,” if you want.

6
Chapter 1 Prerequisites and Software Installation

Figure 1-1. Selecting an interpreter

OpenCV
OpenCV is one of the most popular and widely used libraries for image processing. All
code examples in this book are based on OpenCV 4. Therefore, our installation steps are
for version 4 of OpenCV.

Working with OpenCV


OpenCV is written in C/C++, and because it’s platform dependent, the installation
instructions vary from OS to OS. In other words, OpenCV needs to be built for your
particular platform/OS to run smoothly. We will use Python bindings to call OpenCV for
any image processing needs.
Like any other library, OpenCV is evolving; therefore, if the following installation
instructions do not work in your case, check the official website for the exact
installation process.

7
Chapter 1 Prerequisites and Software Installation

We will take an easy route to install OpenCV 4 and Python 3 bindings using PIP. We
will install the opencv-python-contrib package from PyPI in the virtual environment
that we created previously.
So here we go!

Installing OpenCV4 with Python Bindings


Make sure you are in your virtual environment. Simply change directory to your virtualenv
directory (the cv directory we created previously) and type the following command:

$ source cv/bin/activate

Install OpenCV in a snap using the following command:

$ pip install opencv-contrib-python

Additional Libraries
There are some additional libraries that we will need as we work on some of the
examples. Let’s install and keep them in our virtualenv.

Installing SciPy
Install SciPy with the following:

$ pip install scipy

Installing Matplotlib
Install Matplotlib with the following:

$ pip install matplotlib

Please note that the libraries installed in this chapter are frequently updated. It
is strongly advised to check the official websites for updates, new versions of these
libraries, and the latest installation instructions.

8
CHAPTER 2

Core Concepts of Image


and Video Processing
This chapter introduces the building blocks of an image and describes various methods
to manipulate them. Our learning objectives in this chapter are as follows:

• To understand the smallest unit of an image (a pixel) and how colors


are represented

• To learn how pixels are organized in an image and how to access and
manipulate them

• To draw different shapes, such as lines, rectangles, and circles, on an


image

• To write code in Python and use OpenCV to work with examples to


access and manipulate images

I mage Processing
Image processing is the technique of manipulating a digital image to either get an
enhanced image or extract some useful information from it. In image processing, the
input is an image, and the output may be an image or some characteristics or features
associated with that image. A video is a series of images or frames. Therefore, the
technique of image processing also applies to video processing. In this chapter, I will
explain the core concepts of digital image processing. I will also show you how to work
with images and write code to manipulate them.

9
© Shamshad Ansari 2020
S. Ansari, Building Computer Vision Applications Using Artificial Neural Networks,
https://doi.org/10.1007/978-1-4842-5887-3_2
Chapter 2 Core Concepts of Image and Video Processing

Image Basics
A digital image is an electronic representation of an object/scene or scanned document.
The digitalization of an image means converting it into a series of numbers and storing
these numbers in a computer storage system. Understanding how these numbers are
arranged and how to manipulate them is the primary objective of this chapter. In this
chapter, I will explain what makes an image and how to manipulate it using OpenCV and
Python.

Pixels
Imagine a series of dots arranged in rows and columns, and these dots have different
colors. This is pretty much how an image is formed. The dots that form an image are
called pixels. These pixels are represented by numbers, and the values of the numbers
determine the color of a pixel. Think of an image as a grid of square cells with each cell
consisting of one pixel of a particular color. For example, a 300×400-pixel image means
that the image is organized into a grid of 300 rows and 400 columns. That means our
image has 300×400 = 120,000 pixels.

Pixel Color
A pixel is represented in two ways: grayscale and color.

Grayscale
In a grayscale image, each pixel takes a value between 0 and 255. The value 0 represents
black, and 255 represents white. The values in between are varying shades of gray. The
values close to 0 are darker shades of gray, and values closer to 255 are brighter shades of
gray.

Color
The RGB (which stands for Red, Blue, and Green) color model is one of the most popular
color representations of a pixel. There are other color models, but we will stick to RGB in
this book.

10
Chapter 2 Core Concepts of Image and Video Processing

In the RGB model, each pixel is represented as a tuple of three values, generally
represented as follows: (value for red component, value for green component, value for
blue component). Each of the three colors is represented by integers ranging from 0 to
255. Here are some examples:

(0,0,0) is a black color.

(255,0,0) is a pure red color.

(0,255,0) is a pure green color.

What color is represented by (0,0,255)?


What color is represented by (255,255,255)?
This w3school website (https://www.w3schools.com/colors/colors_rgb.asp) is a
great place to play with different combinations of RGB tuples to explore more patterns.
Explore what color is represented by each of the following tuples:

(0,0,128)

(128,0,128)

(128,128,0)

Let’s try to make yellow. Here is a clue: red and green make yellow. That means a
pure red (255), a pure green (255), and no blue (0) will make yellow. So, our RGB tuple
for yellow is (255,255,0).
Now that we have a good understanding of pixels and their color, let’s understand
how pixels are arranged in an image and how to access them. The following section will
discuss the concept of coordinate systems in image processing.

C
 oordinate Systems
Pixels in an image are arranged in the form of a grid that is made of rows and columns.
Imagine a square grid of eight rows and eight columns. This will form an 8×8 or 64-pixel
image. This may be imagined as a 2D coordinate system in which (0,0) is the top-left
corner. Figure 2-1 shows our example 8×8-pixel image.

11
Chapter 2 Core Concepts of Image and Video Processing

Figure 2-1. Pixel coordinate system

The left-top corner is the start or origin of the image coordinate system. The pixel
at the top-right corner is represented by (7,0), the bottom-left corner is (7,0), and the
bottom-right pixel is (7,7). This may be generalized as (x,y), where x is the position of the
cell from the left edge of the image and y is the vertical position down from the top edge
of the image. In Figure 2-1, the red pixel is in the fifth position from the left and fourth
from the top. Since the coordinate system begins at 0, the coordinate of the red pixel
shown in Figure 2-1 is (4,3).
To make it a little clearer, let’s imagine an image that is 8×8 pixels, with the letter H
written on it (as shown in Figure 2-3). Also, for simplicity, assume this is a grayscale
image with the letter H written in black and the rest of the area of the image in white.

Figure 2-2. Pixel coordinate system example

Remember, in the grayscale model, a black pixel is represented by 0, and a white one
is represented by 255. Figure 2-3 shows the values of each pixel within the 8×8 grid.

12
Chapter 2 Core Concepts of Image and Video Processing

Figure 2-3. Pixel matrix and values

So, what’s the value of the pixel at position (1,4)? And at position (2,2)?
I hope you now have a clear picture of how images are represented by numbers
arranged in a grid. These numbers are serialized and stored in the computer’s
storage system and rendered as an image when displayed to the screen. By now you
know how to access pixels using the coordinate system and how to assign colors to
these pixels.
We have established a solid foundation and learned the basic concepts of image
representation. Let’s get ourselves some hands-on practice with some Python and
OpenCV coding. In the following section, I will show you, step-by-step, how to write
code to load images from the computer’s disk, access pixels, manipulate them, and write
them back to the disk. Without further ado, let’s dive in!

13
Chapter 2 Core Concepts of Image and Video Processing

Python and OpenCV Code to Manipulate Images


OpenCV represents the pixel values of an image as a NumPy array. (Not familiar with
NumPy? You can find a “getting started” tutorial at https://numpy.org/devdocs/user/
quickstart.html). In other words, when you load an image, OpenCV creates a NumPy
array. The pixel values can be obtained from NumPy by simply supplying the (x,y)
coordinates.
When you give the (x,y) coordinates, NumPy will return the values of colors of the
pixel at those coordinates as follows:

For a grayscale image, the returned value from NumPy will be a


single value between 0 and 255.

For a color image, the returned value from NumPy will be a tuple
for red, green, and blue. Note that OpenCV maintains the RGB
sequence in the reverse order. Remember this important feature
of OpenCV to avoid any confusion while working with OpenCV.

In other words, OpenCV stores the colors in BGR sequence and not in RGB
sequence.
Before we write any code, let’s make sure we always use our virtualenv, in the ~/cv
directory, that we already set up with PyCharm.
Launch your PyCharm IDE and make a project (I named my project cviz, short
for “computer vision”). Refer to Figure 2-4 and ensure that you have selected Existing
Interpreter and have our virtualenv Python 3.6(cv) selected.

14
Chapter 2 Core Concepts of Image and Video Processing

Figure 2-4. PyCharm IDE, showing the setup of the project with virtualenv

Program: Loading, Exploring, and Showing an Image


Listing 2-1 shows the Python code to load, explore, and display an image.

Listing 2-1. Python Code to Load, Explore, and Display an Image

Filename: Listing_2_1.py
1    from __future__ import print_function
2    import cv2
3
4    # image path
5    image_path = "images/marsrover.png"
6    # Read or load image from its path
7    image = cv2.imread(image_path)
8    # image is a NumPy array
9    print("Dimensions of the image: ", image.ndim)
10   print("Image height: ", format(image.shape[0]))
11   print("Image width: ", format(image.shape[1]))
12   print("Image channels: ", format(image.shape[2]))

15
Chapter 2 Core Concepts of Image and Video Processing

13   print("Size of the image array: ", image.size)


14   # Display the image and wait until a key is pressed
15   cv2.imshow("My Image", image)
16   cv2.waitKey(0)

The code in Listing 2-1 is explained here.


In lines 1 and 2, we import Python’s print_function from the __future__ package
and cv2 of OpenCV.
Line 5 is simply the path of the image that we are going to load from a directory.
If your input path is in a different directory, you should give either the full or relative
path to the image file.
In line 7, using the cv2.imread() function of OpenCV, we are reading the image into
a NumPy array and assigning to a variable called image (this variable can be anything
you like).
In lines 9 through 13, using NumPy features, we are displaying the dimension of
the image array, height, width, number of channels, and size of the array (which is the
number of pixels).
Line 15 displays the image as is using OpenCV’s imshow() function.
In line 16, the waitKey() function allows the program not to terminate immediately
and wait for the user to press any key. When you see the image window that will display
in line 15, press any key to terminate the program, else the program will block.
Figure 2-5 shows the output of Listing 2-1.

Dimension of the image: 3


Image height: 400
Image width: 640
Image channels: 3
Size of the image array: 768000

Figure 2-5. Output and image display

16
Chapter 2 Core Concepts of Image and Video Processing

The image NumPy array consists of three dimensions: height × width × channel. The
first element of the array is the height, which tells us how many rows our pixel grid has.
Similarly, the second element is the width, which represents the number of columns of
the grid. The three channels represent the BGR (not RBG) color components. The size
of the array is 400×640×3 = 768,000. This actually means that our image has 400×640 =
256,000 pixels, and each pixel has three color values.

Program: OpenCV Code to Access and Manipulate Pixels


In the next program, we will see how to access and modify pixel values using the
coordinate system that we learned about earlier. Listing 2-2 shows the code example
with the line-by-line explanation after it.

Listing 2-2. Code Example to Access and Manipulate Image Pixels


Filename: Listing_2_2.py
1    from __future__ import print_function
2    import cv2
3
4    # image path
5    image_path = "images/marsrover.png"
6    # Read or load image from its path
7    image = cv2.imread(image_path)
8
9    # Access pixel at (0,0) location
10   (b, g, r) = image[0, 0]
11   print("Blue, Green and Red values at (0,0): ", format((b, g, r)))
12
13   # Manipulate pixels and show modified image
14   image[0:100, 0:100] = (255, 255, 0)
15   cv2.imshow("Modified Image", image)
16   cv2.waitKey(0)

Listing 2-2 is explained here.


Lines 1 through 7 import and read the image from a directory path (as explained
when discussing Listing 2-1).
In line 10, we are getting the BGR (and not RBG) values of the pixel at coordinates
(0,0) and assigning them to the (b,g,r) tuple using the NumPy syntax.

17
Chapter 2 Core Concepts of Image and Video Processing

Line 11 displays the BGR values.


In line 14, we are taking a range of pixels from 0 to 100 along the y-axis and from 0
to 100 along the x-axis to form a 100×100 square and assigning the values (255,255,0) or
pure blue, pure green, and no red to all the pixels within this square.
Line 16 displays the modified image.
Line 17 waits for the user to press any key for the program to exit.
Figure 2-6 shows some sample output of Listing 2-2.

Blue, Green and Red values at (0,0): (40, 55, 134)

Figure 2-6. Output and modified image display

As shown in Figure 2-6, the modified image has a 100×100-pixel square at the top-left
corner in aqua, represented by (255,255,0) of the BGR scheme.

D
 rawing
OpenCV provides convenient methods to draw shapes on an image. We will learn how to
draw a line, rectangle, and circle on an image using the following methods:

Line: cv2.line()
Rectangle: cv2.rectangle()

Circle: cv2.circle()

Drawing a Line on an Image


We will use a simple method of drawing a line on an image, shown here:

1. Load the image into a NumPy array.

2. Decide the coordinates of the starting position of the line.


18
Chapter 2 Core Concepts of Image and Video Processing

3. Decide the coordinates of the end position of the line.

4. Set the color of the line.

5. Optionally, set the thickness of the line.

Listing 2-3 demonstrates how to draw a line on an image.

Listing 2-3. Drawing a Line on an Image

Filename: Listing_2_3.py
1    from __future__ import print_function
2    import cv2
3
4    # image path
5    image_path = "images/marsrover.png"
6    # Read or load image from its path
7    image = cv2.imread(image_path)
8
9    # set start and end coordinates
10   start = (0, 0)
11   end = (image.shape[1], image.shape[0])
12   # set the color in BGR
13   color = (255,0,0)
14   # set thickness in pixel
15   thickness = 4
16   cv2.line(image, start, end, color, thickness)
17
18   #display the modified image
19   cv2.imshow("Modified Image", image)
20   cv2.waitKey(0)

Here is the line-by-line explanation of the code.


Lines 1 and 2 are the usual imports. From now on, I will not repeat the imports
unless we have a new one to mention.
Line 5 is the image path.
Line 7 actually loads the image into a NumPy array called image.
Line 10 defines the starting coordinates of the point from where the line will be
drawn. Recall that the location (0,0) is the top-left corner of the image.
19
Chapter 2 Core Concepts of Image and Video Processing

Line 11 specifies the coordinates of the endpoint of the image. You will notice that
the expression (image.shape[1], image.shape[0]) represents the coordinates of the
bottom-right corner of the image.
You have probably guessed by now that we are drawing a diagonal line.
Line 13 sets the color of the line we are going to draw, and line 15 sets its thickness.
The actual line is drawn in line 16. The cv2.line() function takes the following
arguments:

–– Image NumPy. This is the image where we are drawing the line.
–– Start coordinates.

–– End coordinates.

–– Color.

–– Thickness. (This is optional. If you do not pass this argument, our


line will have a default thickness of 1.)

Finally, the modified image is shown on line 19. Line 20 waits for the user to press
any key to terminate the program. Figure 2-7 shows the sample output of the image we
just drew a line on.

Figure 2-7. Image with a diagonal line in blue

20
Chapter 2 Core Concepts of Image and Video Processing

Drawing a Rectangle on an Image


Drawing a rectangle is easy with OpenCV. Let’s dive into the code directly (Listing 2-4).
We will first load an image and draw a rectangle to it. We will save the modified image to
the disk.

Listing 2-4. Loading an Image, Drawing a Rectangle to It, Saving It, and
Displaying the Modified Image
Filename: Listing_2_4.py
1    from __future__ import print_function
2    import cv2
3
4    # image path
5    image_path = "images/marsrover.png"
6    # Read or load image from its path
7    image = cv2.imread(image_path)
8    # set the start and end coordinates
9    # of the top-left and bottom-right corners of the rectangle
10   start = (100,70)
11   end = (350,380)
12   # Set the color and thickness of the outline
13   color = (0,255,0)
14   thickness = 5
15   # Draw the rectangle
16   cv2.rectangle(image, start, end, color, thickness)
17   # Save the modified image with the rectangle drawn to it.
18   cv2.imwrite("rectangle.jpg", image)
19   # Display the modified image
20   cv2.imshow("Rectangle", image)
21   cv2.waitKey(0)

Here is a line-by-line explanation of Listing 2-4.


Lines 1 and 2 are our usual imports.
Line 5 assigns the image path.
Line 6 reads the image from its path.

21
Chapter 2 Core Concepts of Image and Video Processing

Line 10 sets the starting point of the rectangle we want to draw on the image. The
starting point consists of the coordinates of the top-left corner of the rectangle.
Line 11 sets the endpoint of the rectangle. This represents the coordinates of the
bottom-right corner of the rectangle.
Line 13 sets the color, and line 14 sets the thickness of the outline of the rectangle.
Line 16 actually draws the rectangle. We are using OpenCV’s rectangle() function,
which takes the following parameters:

–– NumPy array that holds the pixel values of the image


–– The start coordinates (top-left corner of the rectangle)

–– The end coordinates (bottom-right of the rectangle)

–– The color of the outline

–– The thickness of the outline

Notice that line 16 does not have any assignment operator. In other words, we did
not assign the return value from the cv2.rectangle() function to any variable. The
NumPy array, image, that is passed as an argument to the cv2.rectangle() function is
modified.
Line 18 saves the modified image, with rectangle drawn on it, to a file on the disk.
Line 20 displays the modified image.
Line 21 calls the waitKey() function to allow the image to remain displayed on the
screen until a key is pressed. The function waitKey() waits for a key event infinitely or
for a certain delay in milliseconds. Since the OS has a minimum time between switching
threads, the waitKey() function will not wait, after a key is pressed, for exactly the delay
time passed as an argument to the waitKey() function. The actual wait time depends on
other programs that your computer might be running at the time when a key is pressed
and waitKey() function is called.
Figure 2-8 shows the output of the image with the rectangle drawn on it.

22
Chapter 2 Core Concepts of Image and Video Processing

Figure 2-8. Image with rectangle drawn

In the previous example, we first read an image from the disk and drew a rectangle
on it. We will now slightly modify this example and draw the rectangle on a blank canvas.
We will first create a canvas (as opposed to loading an existing image) and draw a
rectangle on it. We will then save and display the resultant image. See Listing 2-5.

Listing 2-5. Drawing a Rectangle on a New Canvas and Saving the Image

Filename: Listing 2_5.py


1    from __future__ import print_function
2    import cv2
3    import numpy as np
4
5    # create a new canvas
6    canvas = np.zeros((200, 200, 3), dtype = "uint8")
7    start = (10,10)
8    end = (100,100)
9    color = (0,0,255)
10   thickness = 5
11   cv2.rectangle(canvas, start, end, color, thickness)
12   cv2.imwrite("rectangle.jpg", canvas)
13   cv2.imshow("Rectangle", canvas)
14   cv2.waitKey(0)

23
Chapter 2 Core Concepts of Image and Video Processing

In Listing 2-5, all the lines except lines 3 and 6 are the same as in Listing 2-4.
Line 3 imports the NumPy library that we will use to create the canvas.
Line 6 is where we are creating an image (called the canvas). Our canvas is 200×200
pixels with each pixel holding three channels (to hold BGR values). The variable name,
canvas, is a NumPy array that, in this case, holds a zero value for each pixel. Notice that
the data type of each pixel value of the canvas is an 8-bit unsigned integer (as explained
in Chapter 1).
How would you draw a solid rectangle (meaning, a rectangle filled with a
particular color)?
Clue: set the thickness to -1.
Figure 2-9 shows the output of Listing 2-5. Figure 2-10 shows a canvas with a solid
rectangle drawn on it.

Figure 2-9. Rectangle with border thickness 5

Figure 2-10. Solid rectangle with a thickness of -1

24
Chapter 2 Core Concepts of Image and Video Processing

Drawing a Circle on an Image


Drawing a circle on an image is equally easy. You create your own canvas or load an
existing image and then set the coordinates of the center, radius, color, and thickness of
the outline of the circle.
Listing 2-6 shows a working piece of code that draws a circle on a blank canvas.
Figure 2-11 shows the output of this code listing.

Listing 2-6. Drawing a Circle on a Canvas

Filename: Listing_2_6.py
1    from __future__ import print_function
2    import cv2
3    import numpy as np
4
5    # create a new canvas
6    canvas = np.zeros((200, 200, 3), dtype = "uint8")
7    center = (100,100)
8    radius = 50
9    color = (0,0,255)
10   thickness = 5
11   cv2.circle(canvas, center, radius, color, thickness)
12   cv2.imwrite("circle.jpg", canvas)
13   cv2.imshow("My Circle", canvas)
14   cv2.waitKey(0)

The code in Listing 2-6 is not very different from that of Listing 2-5 except that line 7
defines the center of the circle.
In addition, line 8 sets the radius, line 9 defines the color, and line 10 sets the
thickness of the circle. Finally, line 11 draws the circle and accepts the following
parameters:

–– The image on which to draw the circle. This is our NumPy array
containing the image pixels.
–– The coordinates of the center of the circle.

–– The radius of the circle.

25
Chapter 2 Core Concepts of Image and Video Processing

–– The color of the outline of the circle.

–– The thickness of the outline.

Figure 2-11. A circle drawn at the center of a black canvas

Here’s an exercise for you:

1. Draw a solid circle at the center of the canvas.

2. Draw two concentric circles with the outermost circle having a


radius of 1.5 times the radius of the inner circle.

Summary
In this chapter, we learned the basics of images, starting with pixels and how they are
represented in different color schemes, namely, gray and color. The coordinate system
helps locate a specific pixel and manipulate their values. We learned how to draw some
basic shapes such as a line, a rectangle, and a circle on an image. Although these are very
basic and easy, they are important concepts to do anything in image processing.
In the next chapter, we will explore different techniques and algorithms used in
image processing.

26
Other documents randomly have
different content
"You made goodness seem so charming!"

"I, good? ... If you knew!"

"I do know. I know exactly what I mean. There's so much disgusting


hypocrisy in the world a fellow gets to think that the bad people are the only
honest ones. You taught me better."

Pen turned and clung to him. A tear or two rolled down her cheeks. "Oh,
my dear! ... It isn't true! ... But it comforts me so!"

Enfolded in happiness and delicious peace, they became sleepy in spite


of themselves. Notwithstanding his sleepy protests, she drew herself away
from him.

"Stretch out," she whispered. "I will sit on the stool beside you where I
can look at you. I love so to look at you!"

"Pen! ... No! You sleep! ... I'll keep watch!"

But he sunk lower and lower. Soon he was gone. Pen sitting beside him
could gaze her fill. The moon was coming in the front windows now. The
direct rays did not fall on him, but there was light enough for her to see. All
relaxed and helpless like that he seemed to belong to her more completely
than he ever did awake—and stubborn. She could scarcely bear to look at
him.

In the end she slept too with her cheek on his breast.

She was awakened, she knew not how long afterwards, by a sound. Even
in the instant of waking she recognized the sound. It was the stealthy creak
of the tin roof outside her window. At the touch of her hand on his cheek
Don awoke all of a piece. He slipped noiselessly to the floor. They crept to
the middle of the room.

With her lips at his ear she breathed: "There's a man on the porch roof."

"Did he look in?"


"I don't think so. He couldn't have seen you through the screen."

"If he tries to come in...?"

"Slip through the door behind you."

Don made to creep away from her. She laid a hand on his arm. "Wait!"

There was no further sound from the man outside.

"He's not coming in," Pen whispered. "He's out there to cut off your
escape."

A tremendous rat-tat-tat resounded through the empty halls.

"I shouldn't have slept!" murmured Don.

"It's all right!" whispered Pen. "I intended you should stay here."

"I feel trapped within walls!"

"You are safest here!"

The knocking was imperiously repeated. Outside Pen's door they heard
her father's agitated voice.

"Pen, are you there?"

"Yes, Dad," she said coolly.

"Stay where you are, my dear. I'll go down."

For the third time that night the worthy little man pattered down stairs in
his bare feet.

Pen opened her door an inch. She heard her father's prudent inquiry
through the closed door, and a gruff voice outside reply:

"Open the door!"


Pendleton remonstrated, and the voice, Delehanty's, was brutally raised:

"Open the door or I'll smash it in!"

She heard the key squeak in the lock. Pendleton's remonstrances were
drowned in the sounds made by the entrance of a number of men.
Pendleton's voice was raised in agonized tones. Delehanty said:

"We're going to search the house!"

Pen had the sense that her little father was trying to bar them out by main
strength. Signing to Don to remain where he was, she hastened to the head
of the stairs. She called down:

"Let them in, father. We have nothing to hide."

Returning to her room she locked the door. Her father came up stairs
accompanied by a pair of shod feet. His voice at Pen's door was utterly
bewildered.

"They insist on searching the house ... searching the house! At this
hour!"

"Well, that's all right," said Pen.

"They say if you'll stay quietly in your room they'll leave that until last.
There's a man out here on guard. Better dress, dear."

"I shall be all right," said Pen.

She turned and kissed Don with a smile on her lips. Her eyes shone with
the light of battle.

He looked more dubious. "Is your way of retreat still open?" he


whispered.

She nodded.

"Well then...?"
"Wait till they come up stairs."

She listened with her ear at the crack of the door. Vague sounds arose
from below. She was tormented by her inability to hear exactly. Finally she
motioned to Don to stand back out of any possible range of vision, and
opening the door, she put her head around it.

Instantly a flash-light was thrown on her and a voice said:

"You can't come out, Miss."

"I don't want to come out," said Pen coolly. "I want to hear what's going
on in my house."

Now her ear practised in that house, could follow their movements very
well. They were in the cellar. They took no precautions for silence. They
came stamping up the cellar stairs, and were to be heard in the kitchen and
the outer kitchen. They spread through the main rooms of the house. Pen
smiled to herself, hearing them move heavy objects of furniture, looking for
hiding-places in the walls. Finally they started up the main stairway, but
were diverted into the rear extension. Doors were opened and shut, furniture
pulled about. As they started to move back towards the front, Pen closed her
door.

"They're coming!" she breathed in Don's ear. "Now's the time!"

She took him to the door leading to the rear room. "Lock this door
behind you and put the key in your pocket." She pointed to an open window
in the corner of the room facing the rear. "There's your way out. The
ironing-board is on the floor under the window. Stretch it across catty-
cornered to the sash of the bathroom window. I pulled down the top sash
ready for you. As you go, turn and close this window behind you. When
you get in the bath-room pull the board after you. Don't touch that window.
It squeaks. Wait in the bath-room with the door open. If you hear anybody
coming that way slip down the back stairs and into the cellar. While you're
in the bathroom watch this window. When they're through with this room
I'll raise the window and leave it up. That's your signal to come back."
There was a peremptory knock on the door of Pen's room. The lovers
pressed hands and parted. Slipping through the door, Don closed it
noiselessly and turned the key.

"What is it?" Pen asked.

The voice of Delehanty brusquely replied: "Open the door, please."

Pen wanted all the time she could gain. "Is my father there?" she asked
as if in doubt.

"Yes, my dear," said Pendleton quaveringly. "Please open."

"One moment!"

She turned down the covers of her bed, and rumpled them. Her ears were
strained for sounds from the back, but she heard nothing. So much the
better!

"You've had plenty of time to dress!" said Delehanty harshly.

She opened the door. There was a small crowd in the hall. One carried a
brilliant acetylene lantern which filled the place with a strong white light
and threw grotesque shadows upwards. All the detectives had their hats on;
some were short, some tall. It was like a caricature in violent chiaroscuro.
As for Pendleton, he had his pants pulled over his night-shirt and his bare
feet looked piteous. A picture of ineffectiveness, he was still carrying a
lighted candle in all that glare.

Without so much as by your leave Delehanty strode into the room with
three of his men at his heels. The chief was chewing an extinct cigar which
smelled vilely. Pen choked with rage. She bit her lips to keep back an
outburst. Her father went to her, and squeezed her hand imploringly. The
three men spread around the room like well-trained dogs. One could
imagine them sniffing. They were armed with electric torches with which to
illumine dark corners. Delehanty went direct to the door into the rear room
and rattled it.
"What's behind here?" he demanded.

"Another bed room," said Pen. "The guest-room."

"Guest-room?" sneered Delehanty. "Where's the key?"

"The door has been locked for many years. I couldn't tell you."

"Well what's the door from that room into the hall doing locked?"

"Because I keep certain things of value in there. I don't want the servants
to go in."

Pen's father must have wondered at this answer. But perhaps he was too
confused to take in what she was saying. At any rate he kept quiet.

"Is that key lost too?" sneered Delehanty.

"No," said Pen calmly. "It's among the other keys on the rack in my
sewing-room. My father will get it for you."

Pendleton trotted obediently away with his candle.

When he came back with it Delehanty's sleuths had completed their


search of Pen's room. The whole party passed around through the hall to the
door of the guest-room. The men showed excitement. They thought they
had their man. Delehanty flung the door open and stepped back. He ordered
his men to cast the light of their electric torches inside. This was to draw the
fire of the supposed occupant. Pen's lip curled. Finally the men ventured
across the threshold.

The acetylene lantern filled the great bare chamber with light. It was
meagerly furnished, a gigantic bedroom set of the carved walnut period, the
bed with an old-fashioned mosquito bar, an air-tight stove, an humble little
rocking-chair. The great expanse of white wall was guiltless of paper or tint,
and showed long fine cracks running in every direction like the map of a
complicated river system. The floor was covered with matting.
Delehanty sniffed. "The air is fresh. There's been a window open in
here."

Pen's heart contracted. "The room is aired every day," she said quickly.

Delehanty went to the window in the corner. The two windows at the
side of the room were shuttered on the outside. He cast his light along the
sill.

"There's no dust here," he said accusingly.

"There's no dust anywhere in my house," said Pen.

Delehanty commanded the window to be opened. The acetylene light


was held outside. This was the crucial moment. Pen held her breath.

"What is there?" asked Delehanty.

"Eighteen or twenty foot drop, sir."

"Any gutter pipe or lightning rod?"

"No, sir."

"Close the window."

Pen breathed again.

The bare room offered but few places of concealment, under the bed,
within the washstand, a shallow clothes closet in the wall. They even looked
in the bureau drawers. Finally Delehanty with a grunt, moved towards the
door. Pen's heart swelled big with triumph.

She glanced at Delehanty's cigar. "Would you mind leaving the window
open?" she said cuttingly.

At a nod from the chief, one of the men flung up the sash. Pen felt a little
quiver of inward laughter. There was something humorous in making the
enemy transmit one's signals. All left the room and Pen locked the door. She
handed the key to her father.

"Please put it where you got it."

Delehanty fixed her with an irascible, suspicious eye. "You come along
with us the rest of the way, Miss. I want no trickery!"

Pen shrugged.

The search went on, that queer crew straggling through the rooms
accompanied by their grotesque up-flung shadows. Through Pen's sewing-
room and into Pendleton's bed-room. From thence they passed into the
extraordinary room behind where he kept all his "Collections." He never
threw anything away. Everything under the sun was to be found there. All
around the walls were rickety, home-made tables heaped with his
impedimenta.

All this occupied the searchers quite a while. They threw his stuff about
regardless of his protests.

Finally there was the third story which Pen had long ago given up to dust
and spiders and last of all the "cupalow" into which Keesing to Pen's
amusement, ascended with drawn revolver.

In the end Delehanty stamped down-stairs in a villainous temper, his


soft-footed sleuths at his heels.

At the front door Pendleton attempted to recover his dignity. "Now I


trust you'll favor me with some explanation," he began.

"Ah! ask your daughter for the explanation!" snarled the detective. "Take
my advice, and keep her home nights!"

They all went. Pendleton turned to Pen aghast.

"What did he mean by that?"


But Pen's heart was dancing. An irresponsible gale of laughter caught her
up. She had a wicked impulse to see her father's bare feet twinkle. She
caught his wrists (he still had the candle) and attempted to whirl him
around.

"Oh joy! Oh joy! Oh joy!" she cried. "They're gone!"

"Pen! Have you gone crazy," he protested.

"Yes, it's the heat!"

"Be quiet! What did the man mean?"

"How do I know? A man will say anything when he's sore ... Come on
back to bed."

She pulled him wildly to the foot of the stairs, Pendleton leaning back,
and his bare feet slapping the floor absurdly. Pen laughed so she had to sit
on the bottom step to recover.

"Your levity is very ill-timed!" he said severely.

That only made her laugh the more. "Come on! Come on!" she said,
dragging him up-stairs.

At the door of his room she kissed him, and gave him a push inside. She
flew across to her own room and let herself in.

"Don! Don!" she just breathed, holding out her hands.

There was no answer.

She flew to the door between the two rooms. It yielded to her hand. The
key was in it. So he had come back. The window in the corner was still
open. It was very dark in the back room. She felt all around for him, softly
whispering his name. Her breast contracted with apprehension. She ran
back into the front room to make a light.
As soon as the candle flame grew up she saw a piece of paper pinned to
the wooden mantel. It looked like the fly leaf torn out of a book. There was
a pencil scrawl upon it.

"Dearest: Writing in the dark. That was too near a thing. Can't let you
take such risks. I'm off on my own. Don't worry. Love.

"D."

CHAPTER X

DAYS OF SUSPENSE

Pen lay on her bed wide-eyed and dry-eyed until near dawn. It did not
lessen her misery any that a good part of it was anger at having her will
balked. She accused Don by turn of callousness, of ingratitude, of folly; she
tried to tell herself that he was not worth saving, but without abating any of
her torments of anxiety as to his fate. It was worse than anxiety; she had a
horrible, dull certainty that he would be taken as soon as it became light.
Like a wilful child intent only upon having his own way, he had run blindly
out into their trap.

After the briefest period of unconsciousness she was awakened by a stir


outside the house. Looking out of the window she saw that the sun was but
just up, the great square shadow of the house reached almost to the edge of
the bank. Nevertheless early as it was, the house grounds were full of
people, and more were arriving through the gates. These were Islanders,
fisher-folk, or men from the farms in earth-colored garments. Under the
bank she could hear the put-put of arriving motor-boats. Among the people
the gross figure of Delehanty was conspicuous, moving about, picking out
men here and there.

Well, if he was still looking for men Don was not yet caught,
nevertheless, Pen's heart sickened at the sight. It was clear enough what was
happening. During the last few days popular interest in the chase had fallen
off, but the news of the finding of the canoe had revived it. The blood lust
was aroused again. When she got down to the kitchen Pen learned from the
excited negroes that Riever had increased the reward to ten thousand
dollars. That was what had brought the crowd.

Like a woman who had died and whose body was condemned to drag
on, Pen started things going in the kitchen and set the table for breakfast.
When her father came into the dining-room even he who noticed so little,
was struck by the contrast of her present look with the laughing mænad who
had thrust him into his room the night before.

"What's the matter?" he asked sharply.

Pen shrugged. She had to make some excuse. "Last night was too much
for me," she muttered.

"I thought so!" he said severely. "I told you you were acting wildly ...
Riever had nothing to do with that affair," he added irrelevantly.

"What difference does it make?"

Pendleton had already been out of doors, and he could talk about nothing
but the latest developments of the case. In his new interest, his resentment
against Delehanty had cooled. Pen could not gather from his talk what they
were saying about her. No doubt they spared his feelings—or mocked him
without his being aware of it. With the curious blindness that was
characteristic of him, he had not yet connected the finding of the canoe with
his daughter.

"How strange that Counsell should have come back here after having
paddled away!" he said. "And yet, how natural! It was the last thing anyone
would suppose that he would do!"
Pen let him run on, half attending.

Worse was in store for her. Her father said:

"Of course Riever has been entirely discreet in making his new
announcement. He had it written out and sent it over to the Island last night
to be posted up outside the store. His offer reads: 'Ten thousand dollars for
the apprehension of Donald Counsell.' But everybody understands that it
means dead or alive. Many of the men are armed."

Pen thought she had experienced the extremity of torment. But this was
saving for her. She half rose from her chair with a face of horror, and
dropped back again.

"But this is murder!" she gasped.

"Eh?" said little Pendleton blinking.

"Cold-blooded murder! ... Cynical murder! ... To set an armed mob after
a defenseless man ... with the promise of reward!"

"But he's desperate. If he's cornered he'll fight..."

"He is unarmed!" said Pen.

Her father's jaw dropped. "How do you know?"

She saw that she had betrayed herself, but she was beyond caring.
Pushing her chair back she went to the mantel and resting her arms upon it
dropped her head on them. "Oh God! what sort of a world is it where such
things are possible!" she cried.

"Pen, what am I to think from this?" he stammered aghast.

She could not be still in her agony. She paced up and down stretching up
her arms for the ease to her breast which was not to be had. "Whatever you
like!" she said.

"You have been seeing him? You know where he is?"


"I don't know now."

"My God!"

Pen hurried from the room, leaving him in a state of collapse.

She still went about her daily tasks like a piece of mechanism. She had
to keep in some sort of motion. She experienced strange lapses, discovered
herself offering whole corn in her hand to the newly-hatched chicks; came
to to find herself in places without any notion of what she had come for.
Her father kept out of her way.

It took a long time to organize the searchers. Delehanty was not taking
any chance of failure. He was in no particular hurry since he had already
sent a large party by boat to the head of the creek to cut off any escape up
the Neck. Finally about ten o'clock the rest were ready. They set off in three
parties, the first making its way along the river shore to comb the woods on
the Absolom's Island side; the second setting off towards the lighthouse to
surround the pond in the woods; the third and largest party heading straight
back by the Neck road. Their instructions were to deploy along the edge of
the woods, and wait until they got in touch with the parties on either flank.
Two lads who brought motor-cycles over from the Island were delegated to
act as messengers between Delehanty and the searchers.

When they had gone an ominous Sabbath quiet descended on Broome's


Point, which was harder to bear than the confusion. Delehanty went off to
the cottage. There was no one to be seen but a few of the yellow-faced
squatters' women from up the Neck who peered from under their sun-
bonnets with shy, half-human eyes, and a group of old men standing by the
porch discussing bygone murders with zest.

Later, Pen came upon her father in the back kitchen, or dairy, evidently
seeking to waylay her. He seemed not greatly affected by the scene in the
dining-room, only for a hang-dog air, and a difficulty in meeting her glance.
As a matter of fact Pen's tragic eyes intimidated him. For himself, he had
been absorbed in trifles for so long that he could not feel anything very
deeply.
He said: "I suppose you've forgotten that we were to lunch on the yacht
to-day."

Pen stared at him. Still he had not understood!

"I suppose you don't want to go," he said quickly.

"No," said Pen.

"What will Mr. Riever think," he said plaintively.

"I don't care."

The gathering storm on her brows warned him not to go any further. But
he still hung around like a child.

To get rid of him Pen said: "Why don't you go?"

He brightened. "Well, I wasn't sure if it was proper..."

"Oh go ahead! Tell him I'm sick. Tell him anything you like."

"Well I will if you think it's all right. I want to talk business with him
anyway."

He donned the old frock coat and the comical, flat straw hat and set off
as blithely as a child with a penny in its hand. Pen's glance after him was
bitter. Nevertheless she was thankful to be rid of him.

There came a time when Pen could no longer keep up even the pretense
of doing her chores. Always with her mind's eyes she was following the
searchers. They had come to the edge of the woods. They were spreading
out. They were waiting until the parties on either side came up. Now they
had climbed the fence and were advancing slowly with their guns held
ready; ignorant, passionate men with their guns cocked! She went to her
room and paced up and down with her clenched hands pressed to her breast.
She could not stay there either. She came down on the porch where she
could hear better and paced endlessly up and down, careless of who might
be a witness to her agitation. All her faculties were concentrated on hearing.
She was listening for shots.

Time passed and there was no news. She sent Ellick, the more intelligent
of Aunt Maria's sons down to the beach to pick up what he could. One or
two negroes had come over in the boats. This was regarded as a white man's
business and they were not allowed to take part in it. Nothing transpired
until mid-afternoon when Ellick came back to say that the motorcycle boys
had brought in Counsell's camping outfit which had been found in the
woods. Of Counsell himself there was no word.

A wild hope arose in Pen's breast. Suppose after all he had succeeded in
getting away up the Neck before the line was drawn across it!

Her hope soon sickened though. What good if he had escaped for the
moment? There was but the one road eighty miles long, by which he could
reach cities and crowds and safety. And by this time everybody along that
road was on the qui vive to catch him, their mouths watering at the ten
thousand dollar reward. What chance had he of succor? Where could he get
food? Or on that sandy peninsula, water?

She tormented her brain with futile calculations. Could he or could he


not have made it? Delehanty had dispatched the party up the creek
immediately after searching the house. Pen had heard the boats set off. By
that time Don had had half an hour's start. A man walks perhaps four miles
an hour, the boats averaged seven. It was four miles to the head of the
creek, and but a step from the landing to the Neck road. Still Don ought to
have got there first. But he might have turned aside to get something from
his hidden store in the woods! Pen's brain whirled dizzily.

At other times she pictured him crouching white-faced in the bush,


listening to the relentless slow approach of the searchers, and knowing that
the other side was watched too. Then the dash for freedom, the shots ... That
picture came back again and again. She could not shut it out. How gladly
she would have heard the news that he had been brought in—unhurt.

At five o'clock she beheld her father turning in at the gate accompanied
by Riever. At the sight of the latter Pen saw red. Hideous little creature
lunching on his fine yacht while his dollars sent men into the woods to
murder! And now to come strutting ashore for an afternoon stroll with his
expensive cigar cocked between his lips! How dared he present himself to
her! Her impulse was to project herself down off the porch and tell him! But
a last strand of prudence held. She went to her room instead.

There she struggled with her feelings. Five o'clock! Faint though it might
be, there was a real chance that Don had escaped. She must therefore go on
fighting for him. And in order to fight for him effectually she must maintain
some sort of relations with his loathsome enemy.

There was a knock on her door, and her father said timidly: "Mr. Riever
is down stairs, my dear."

Pen answered composedly: "Very well. I'll be down directly."

Pendleton was delighted. "Thank you, daughter," he purred.

It induced a fresh access of anger in Pen. He had nothing to thank her


for!

Pendleton pattered happily down-stairs. Pen washed and dressed, never


ceasing to admonish herself, and in the end achieved a fair measure of self-
command, though her nerves were in bad shape.

Riever was waiting with a certain air of bravado. Only an involuntary


roll to his eyes betrayed the dark passions that ate him. She greeted him
calmly. He looked secretly relieved.

"I scarcely expected to see you," he said smoothly. "I just came to
enquire how you are."

"I'm all right," said Pen.

"And to express my indignation at what happened last night. Delehanty


certainly goes beyond all bounds! When I get back to New York I shall talk
to the Commissioner about it!"
"Oh, the man must do his work," said Pen. "Surely, he doesn't expect me
to be taken in by this palaver!" she thought.

"He's supposed to exercise some discretion ... You're really all right
again?"

"Quite all right."

"I'm so glad!"

It came to her that he didn't expect her to be taken in. He was satisfied if
she would only appear to be taken in. For different reasons he was just as
anxious to maintain relations as she was. He just wanted everything
unpleasant covered up. That was the spoiled child of it. Pen thought: "I
believe he'd actually marry me without inquiring into my feelings." Well, it
made it easier for her.

Pendleton made some transparent excuse to leave the room. Riever's


shifty eyes gave a roll of terror, thinking that perhaps Pen might now insist
on dragging the truth into the light.

Pen however only said: "I'm surprised to see you on foot this afternoon."

His face turned smug again. "I like walking," he said. "It's my ridiculous
people that insist on having me carried every step."

"Do you walk much in New York?" asked Pen.

He was flattered by her interest. "Yes, very much," he said.

"But I forget, you don't live in the city, do you?"

"Sometimes."

"Have you a home there, too?"

"Well, not exactly a home, but a very pleasant little lodging."

"Ah, an apartment."
"No, I detest apartments. One always feels as if the hall servants were
spying on your comings and goings."

"You stay at your club then?"

"No, clubs are all very well in their way, but I'm not a clubby person. I
like to spread about among my own things. In a club too, the servants are
always under your feet. In New York I like to get away from servants
altogether. I am not so dependent on them as you seem to think."

Pen's heart began to beat a little thickly. "And have you such a place?"
she asked with interest. Apparently they were back just where they had been
before the violent scene of the previous night.

"Yes."

"Do tell me about it."

"It's a quaint little house in an unfashionable neighborhood. It stands in


the name of my valet. The beauty of it is none of my neighbors know me
and I can go and come as I please. It's a petit maison in the French style, a
little entresol below, overhead three tall windows lighting the salon, then a
receding attic, and that's all. I don't suppose there's another house like it in
town."

"And the inside?" said Pen.

"A salle a manger on the ground floor looking out on a little formal
garden at the back. On the main floor the salon in front and a bedroom in
the rear. In the attic, servants rooms. Just a little house for one.... Or two,"
he added with a sidelong glance.

"How interesting!" said Pen. "I'd like to see it."

"I hope you will some day."

"In what part of the town is it?" asked Pen casually.

"On Thirty-Ninth Street east of Lexington."


Pen lowered her eyes to hide the glint of satisfaction in them. "This will
help Blanche," she thought. "I'll write it to-night."

Presently he rose to go. "Tell me you will," he said.

"Will what?" murmured Pen.

"Come to see my little house some day?"

"Nothing is impossible," said Pen turning away her head. If he chose to


read coquetry in the action, that was his look-out.

He held her hand loverly-wise for a long moment, Pen steeling herself
not to shudder. Then he left the room.

Pen began to laugh but there was no sound of mirth in it. She began to
laugh and she could not stop again. The tears ran down her face and her
whole body was shaken with tearing sobs. She ran to her room. She was
horribly unstrung. It was long before she could get hold of herself again.

The collapse eased the strain on her nerves. She came down-stairs and
was able to resume her usual round of tasks. Time was passing, and still no
bad news had been received. Hope grew stronger. Finally word was brought
down the road that the search party had joined forces with the line of guards
drawn across the Neck, and Don Counsell had not been taken. Pen was able
to face the night unafraid.

She presently learned that Delehanty had formed his men into several
camps for the night. The automobile was kept busy running up the road
with supplies for them. At the same time he was preparing to have the road
well patrolled along its whole course through the woods. After dark a
fugitive could not travel any distance except by the road.

The night came on muggy and still and Pen was attacked by a fresh
anxiety. For clouds of mosquitoes arose. She pictured Don fainting with
hunger and thirst, and unable even to make a smudge for fear of betraying
himself, vainly attempting to protect himself from the insects.
She had a wild hope that he might be driven back to her. When the house
had been searched they had found the open cellar door, and in the morning
Delehanty had sent a man to shut the doors and screw them down. Before
she went to bed Pen took lantern and screw driver and satisfying herself that
she was not watched at the moment, knelt behind the bushes and opened the
doors. She also left the way open for Don to return to her room by the route
that he knew of.

She went to bed praying that she might awaken to find him kneeling on
the floor beside her. She did sleep for awhile, for Nature must have her due,
but when she awoke she was still alone.

When she came down-stairs in the morning she heard a new sound that
froze her soul, the deep bay of hounds. Theodo' came into the kitchen, his
eyes rolling wildly in an ashy face, to say that a couple of "man-huntin'
dawgs" had been brought over from the Eastern shore to be put on
Counsell's tracks. These mythical creatures filled the negro with an
extremity of terror. Nothing would tempt him out of doors again.
Meanwhile Pen's collie, Doug, locked up in the barn, hearing these
trespassers on his preserve, and he unable to get at them, went frantic with
rage.

The bloodhounds were taken to the spot in the woods where Don's cache
had been discovered, and were given the scent from Don's clothes. They
picked up his tracks without difficulty and came back over the fields, giving
tongue straight to the cellar door. Delehanty finding it unlocked again,
searched the house once more. The dogs were led around the house. Pen
observing from within, saw that they picked up the trail again outside the
kitchen window. So Don had gone out that way. However they were soon
confused amidst the maze of tracks that tramped down the house grounds in
every direction. Again and again their guardians led them over the ground
with no better success.

Meanwhile, Delehanty having made a new disposition of his forces, the


search in the woods was resumed. He had more men at his disposal on this
day, and a second line of guards was drawn across the Neck higher up.
Additional detectives arrived from New York and Baltimore, and these were
dispatched by horse and motor to search every cabin within miles. At the
same time motor-boats were patrolling all the adjacent shores, so that if the
fugitive was forced out on the beach at any point he would instantly be
sighted.

Notwithstanding these measures the second day passed like the first with
neither sight nor sound of the fugitive. It was believed that he was still in
the neighborhood, because the bloodhounds, though they were led far and
wide through the woods and up the road, had discovered no tracks leading
away from Broome's Point.

When the morning of the third day broke Pen had reached the point of
desperation again. Not for a moment all night had she closed her eyes. She
was now convinced that Don was lying exhausted and starving in some
hidden spot in the woods. Probably no longer even able to give himself up.
For she was sure he would not willingly perish without a fight to clear his
name. When she first came out of the house the sight of a pair of buzzards
circling high against the blue, turned her faint and sick.

To spend another day of inaction was unthinkable. Madness lay that way.
There was no longer any question of helping him to escape. If he was
anywhere near he must be found, whatever might come of it. In her
extremity Pen went to Delehanty to tell him she was going to take part in
the search.

The detective was considerably taken aback. He pushed out his lower lip
and glowered at Pen. "What's the idea?" he demanded.

"I want him found."

"It isn't so long ago since you wanted to lose him."

Pen shrugged.

"Have you any information?" he demanded.

"No. But I know these woods."


"We all know them now," said Delehanty dryly. He considered for a
moment. "Come back in half an hour and I'll talk to you," he said brusquely.

Pen supposed that he wanted to consult with Riever. She was in no


humor to wait.

"You forget I don't have to have your permission to search my own


place," she said. "I offer to work with you. If you don't want me to I'll go
ahead alone." She turned to leave.

"Hold on a minute!" said the detective, "you satisfy me that you're on the
square with me, and I'll work with you fast enough."

Pen was able to tell him the truth—without telling him the whole truth.
"It's very simple," she said. "I don't want him to starve on the place, that's
all."

"Humph! You've lost touch with him, eh?" said Delehanty.

Pen was silent. It was of little moment to her what they thought so they
did not know anything.

"What's your plan?" asked Delehanty.

"For one thing," said Pen, "the fields have never been searched. I see you
send your men up the road every morning. There are hollows in the fields
where a man could lie concealed. Some of the fields are growing up with
young pine that would afford cover."

Delehanty looked at her with unwilling respect. "Anything else?" he


asked.

"If he's in the woods when he heard the searchers approach how easy it
would be to climb a tree until they had passed."

"Are you going to search every tree in the woods?" he asked


sarcastically.

"No," said Pen.


"Will you take a couple of my men along with you?"

"No."

Delehanty scowled darkly.

"I shall call him as I go," said Pen. "If he saw or heard others with me he
wouldn't be so likely to answer."

"Suppose you find him and he refuses to give himself up?"

"After three days without food he'd hardly be in a position to resist."

"Would you undertake to bring him in?"

"You can lend me a revolver if you want. I have none."

"Not on your life!" sneered Delehanty.

Pen shrugged. She had only mentioned the revolver as a bit of stage
business anyway.

"Go and find him if you want," said Delehanty, "but excuse me from
taking any chances of having my gun slipped to him."

Pen went back to the house and made up a packet of sandwiches. As she
was setting out the second time she ran into Riever coming in by the drive.
He had evidently been with Delehanty, and under his forced air of
politeness an extraordinary conflict of feelings was suggested; hope,
distrust and a gnawing curiosity. He would not speak of what was in his
mind, of course. "Where are you setting out for so busily?" he asked with a
false air of blitheness.

Pen was blunt enough. "I believe this man is starving somewhere on the
place, and I'm going to find him if I can."

Riever put on a look of gladness and delight. The guiding rule of his
kind is that by assuming a thing to be so you make it so. He therefore
assumed that Pen had come over to his side, that the millions had won out,
that he and she were now one in sympathy. It need hardly be mentioned
though, that his eye still rolled with a hideous doubt.

"Oh, that's fine of you!" he said ... "But it's dangerous!"

"He wouldn't hurt me," said Pen.

Riever ground his teeth secretly. "How can you be sure?" he said with a
great air of solicitude.

"Because I helped him in the beginning. I fed him."

"But you've thought better of it now?" murmured Riever.

"I'm going to find him if I can."

"I believe you're out after the reward!" Riever said, with a ghastly sort of
facetiousness.

Pen caught at the suggestion. If she were obliged to bring Don in, the
money might make all the difference to them. "Well, why not?" she said. "I
could use the money as well as anybody."

There was a quality of eagerness in her voice that could hardly have
been feigned. For the moment it lulled his doubts. "There's nobody I'd
rather pay it to," he said grinning.

"You mean that?" said Pen. "If I give him up to you, will you pay me the
reward?"

"If you give him up to me I'll double it!" he said meaningly.

"All right!" said Pen. "If I'm successful to-day, I'll hold you to that." She
made to walk on.

Riever's face was full of triumph, but there was still a fear too, another
sort of fear. "Wait a minute," he said. "Suppose you can't handle him?"

"I have no fear of that," said Pen.


He slipped his hand in his side pocket. "Here," he said, "take this." He
produced an automatic pistol. "Do you know how to use it?"

She shook her head. He explained the mechanism.

"Thanks," she said putting it inside her dress, and walked on.

He strutted after her as far as the gates, and stood there watching. She
turned into the path behind the cottage, and followed it into the woods. Her
idea in making the little temple her starting-point was that Don in need of
succor, might haunt the paths they had followed together.

The sun was looking straight into the little glade through the side that
opened above the pond, filling the place with a rich yellow light. Between
the shadows of the pillars a broad beam lay athwart the inscription of the
gravestone, picking out the curly flourishes of the letters that had been
sculped with such loving care. Pen was indifferent now to her shadowy
brother who lay under the stone. She had not remembered him in many
days. Her thoughts were filled by a man of flesh and blood.

"Don! Don!" she spoke softly, not expecting any answer there, and not
getting any.

She let herself down the bank to the spring around at the left which
welled between the roots of a superb white oak that the axe had spared. For
a tree which guards a spring is sacred even to a timber scout. Pen had hopes
of the spring because it was one of the only two places that Don knew of
where fresh water was to be obtained. She searched carefully about it but
was not rewarded by finding any tracks. She made a wider circuit of the
spot but could not see that the underbrush had been disturbed.

She forced her way slowly through the tangle of thorny creepers and
thickly-springing sassafras around the pond to the old wood road. It curved
away secretly into the gloom; old, undisturbed, overgrown; Nature had
painted in this ancient blemish. Years ago the bed of the road had been
packed so hard that even yet nothing would take root there except a mossy
growth like fur underfoot. But at either side bushes had taken advantage of
the free light to spring up thickly. Now for the most part they met overhead,
though there were places where the sun splashed through.

Pen walked slowly, pausing often to softly call Don's name. Nothing
answered her but bird sounds, and the soft chattering of leaves in the high
sunlight. No breath stirred down below. She made wide detours through
secondary roads, mere cuts through the woods that only a practised eye
could follow now.

It was noon when she came out at the edge of the fields. She sat down
under the fence to rest, and, from a sense of duty, to eat something.
Afterwards she struck clear across the rough, neglected, cleared land to the
woods on the other side, then back again, shaping a course that took her
through every hollow. Her experience with sheep had taught her the exact
lay of the peninsula, how each depression gradually deepened into a gully,
running off to some branch on one side or the other. But nowhere did she
find what she was looking for.

She spent several hours searching the banks of the little stream that
meandered through the woods to the east of the fields. That was where she
had sent him to make his camp that night. She found the site of his camp,
but no evidences that he had revisited it. There were plenty of tracks in the
mud of the stream, for the searchers had passed and re-passed this way, but
no voice answered her soft calls.

Finally she struck across the corner of the farthest field, making for the
path which went down through the woods to the arm of Back creek, that
path they had followed on another night, a night of happiness. She thought
of the old skiff drawn up on top of the bank, and had a wild hope that he
might have launched it and succeeded in making his way down the arm and
across the main creek to the mainland. True, the skiff was leaky and rotten,
but a desperate man might make it serve for a short voyage. She ran the last
part of the way.

The skiff was there, just as before! She dropped down upon it, weary of
body and despairing of heart, and burst into tears.

"Don! Don! Don!" she called for the last time.


A green heron mocked her with its discordant croak.

The sun was low, and there could be no further searching that day. Pen
made her heavy way back through the woods, and across the wide field. As
she walked a merciful apathy descended on her. She could suffer no more.
Imaginary pictures of Don starving in the woods no longer rose before her
mind's eye. She was conscious only of a ghastly vacuum inside her. Within
it a little thought stirred like a snake: "This can't go on! If I don't hear in two
or three days more..." She never completed the thought, but her soul was
aware of her intention.

As she was letting down the bars that admitted her to the road, a squad
of men straggled by, searchers homeward bound. Pen hung back to let them
pass. The business was in the nature of a lark to them; young men relieved
for the time being from the tedium of their usual lives, they were talking
loud, laughing, jostling each other in the road. They stared at Pen as
unabashed as animals, and Pen busied herself with the bars. Nevertheless
she was aware that one of them did not stare at her. She looked at him, and
was struck first, by his curiously self-conscious air. She looked afresh,
rubbed her eyes so to speak, and her heart stood still.

It was Don.

True, his chin was covered with a four days' growth of reddish stubble,
his bare head was touselled and unbrushed, he walked with exactly the
same shambling slouch as the others. But it was Don. He had passed her,
but the line of his cheek was enough, and the muscular back under the
cotton shirt. She recognized the old garments she had herself carried to him.
Far from being the starving wreck she had pictured, his cheek was full and
ruddy, his whole body notwithstanding the shamble he affected, full of
spring. For an instant she thought they had taken him. But that was
manifestly ridiculous. He was skylarking with the rest. His whole bearing
was that of a leader amongst them.

Pen leaned against the fence post. A welter of emotions seemed to shatter
her; joy, incredulity, terror that her wits might be wandering, anger at his
careless air of well-being.
Bye and bye she put up the bars mechanically, and started to walk along
the road with a dazed air. She could not take in what had happened. Dusk
was falling. In a couple of hundred yards a figure stepped out from the
shadow of the bordering growth.

"Pen!" it whispered.

Her first reaction was to a shaking anger. She was a little beside herself.
Stamping her foot in the road she cried in a soft, strained voice: "You Don!
Cutting up like a school-boy in the road! Is that all you have on your mind!"

He fell back a step in surprise. Then he laughed softly like the boy she
accused him of being. "But Pen ... aren't you glad?"

"Yes, laugh! do!" she said bitterly. "It's nothing to you what I've been
through these last three days and nights!"

"I told you not to worry," he said sheepishly.

"Told me not to worry! What do you think I am?"

"There was no way in which I could let you hear from me. I thought
you'd understand everything was all right."

"You didn't care! You didn't care!"

He moved close to her. "Pen dear, don't quarrel with me! We have only a
moment. Even this is risky. There are more men coming along the road."

She attempted to push him away. "Don't touch me! You're heartless and
unfeeling!"

Even as she said it she began to sob. She swayed on her feet, and Don
flung an arm about her. She clung to him piteously.

"Oh my darling! my darling! ... Thank God! I have you! ... Don't pay any
attention to what I say. I have suffered so. I was just at the end of my string.
If I had not found you soon I ... I ..."
"Hush, dearest!" he murmured, sobered and remorseful. "You mustn't
say such things. I can't bear it! ... It's true I never thought. I had such
confidence in your strength."

"I thought you were starving in the woods. I couldn't eat when I thought
you had nothing! I couldn't sleep, seeing you lying there."

"Hush! Hush!" he soothed her. "Everything is all right now. Pull yourself
together, dearest. There are stragglers all along the road."

Indeed they could now hear footfalls coming along behind them. They
started to walk too, Don straining Pen hard against his side. Everybody was
traveling the same way. Gradually Pen's breast quieted down.

"What does it mean?" she asked.

"It means I'm one of the searchers for Don Counsell," he said with a
chuckle. "Only place they'd never think of looking for me."

She looked at him a little aghast.

"And I've made good in the job, too," he went on. "I'm considered quite
a valuable man. Delehanty has put me in charge of a squad."

"Delehanty!" she gasped. "Do you mean you have spoken to him?"

"Why not? He doesn't know Don Counsell by sight. None of his men do.
The only one who knows me is Riever, and I take damn good care to keep
out of his way. Luckily it's easy. He doesn't bother with the rough necks.
And you can always see him coming a long way off by his gang."

"How did it come about?" she asked.

"Most natural thing in the world. My way is different from yours. You
plan everything out, and I leave it to the inspiration of the moment. When I
tried to get out by the cellar that night I heard a man down there. They had
one out on the kitchen porch, too. So I took the screen out of the window on
the other side, and dropped to the ground and hid in the shrubbery. I
gradually made my way down to the beach. There were some natives
camping there, but I was afraid to join them then, so I kept under cover until
daylight. In the morning a raft of newcomers arrived from all over, and it
was a simple matter to mix amongst them. They didn't all know each other."

"But you speak differently from these people," said Pen.

"Oh, I kept my mouth shut as much as possible. I gave out that I was
Frank Jones from New Jersey, see? That accounted for my Northern speech.
I said I was off a coasting schooner. Meanwhile I've been practising their
lingo, and I can already speak Mar'land at least well enough to deceive
Delehanty and the other Northerners. Doggone it honey Ah reckon Ah kin
tawk! 'Deed, can I! Gemmen, it's the trewth!"

Pen laughed down his neck.

"Every day that passes makes my position more secure," he said. "I'm
becoming known. At least Frank Jones is. This crop of saw-tooth is a
wonderful disguise."

He softly rubbed his chin against her cheek. Pen liked it.

There came a hail from down the road ahead. "Hey, Jones!"

They moved apart. Don answered: "Coming!" To Pen he said


breathlessly: "How can we meet? ... Oh woman, if you knew how I was
hungering for you day and night!"

"No! No!" said Pen. "Everything's going so well. We mustn't take risks
... But we ought to have some way of communicating."

"Name it quick!"

She considered swiftly. "... Do you know my fattening-coop under the


tree back of the kitchen?"

"I can find it."

"There's a little water-pan inside it. Look under that for a letter."
"All right," he laughed. "If I'm pinched for swiping chickens you'll have
to clear me!"

He ran down the road. Pen followed at a sober pace—still a little dazed.

CHAPTER XI

PEN'S HAND IS FORCED

It was a justly aggrieved father that Pen found awaiting her in the dining-
room.

"Half-past eight!" he said. "Where on earth have you been!"

Pen was quiet and starry-eyed with happiness. It didn't matter much to
her what she said. But she rather wished to avoid a scene. She juggled with
the truth a little.

"Mr. Delehanty wanted me to help him with the search."

"Delehanty! ... Wanted you!" he said amazed. It was too much for him.

"And Mr. Riever," Pen added as an afterthought.

The magic name mollified him a little. "Hum! Ha! ... Well, if Riever
knew ... What suddenly started you off on this tack?"

"I want this business over with!"

"I confess I fail to understand you!" he said severely ... "What help could
you give them anyway?"

"I know the place so well!"


"Do you mean to say you have been searching the woods ... with all
these strangers about?"

"I had only to raise my voice to bring a dozen to my aid ... Besides, Mr.
Riever lent me a revolver."

"Oh! ... Well you might have taken your father into your confidence ...
Did you find anything?"

"No."

A more perspicacious man might have remarked the little catch of joy
with which she said it, but never Pendleton. "The supper is cold," he said
fretfully. "Aunt Maria's gone home."

"Never mind," said Pen. Out of the riches in her breast she could spare
affection for him, the dear, trying child! She kissed his bald spot. "I'll make
a cup of tea for myself."

"I got the mail this afternoon," he grumbled. "There's a letter for you."

"Eh?" said Pen sharply.

"On your plate. I never saw the handwriting before."

Pen glided swiftly around the table. "I never saw it either," she said.
Which was perfectly true. A scrawling, half-formed hand. The post-mark
"New York" told her all that she needed to know.

She thrust it carelessly in her belt and went out into the kitchen.
Pendleton looked affronted. He was terribly curious. Pen lit the oil stove
and put the kettle on. Then she read her letter.

"Dear Miss:

I'm not much at writing. Please excuse mistakes. Well Miss Broome I
guess you were right, all right. Everything bears out what you said. I and
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like