100% found this document useful (1 vote)
12 views

Building Computer Vision Applications Using Artificial Neural Networks, 2nd Edition Shamshad Ansari pdf download

The document provides information on downloading various ebooks and textbooks, particularly focusing on 'Building Computer Vision Applications Using Artificial Neural Networks, 2nd Edition' by Shamshad Ansari. It includes links to additional recommended products related to computer vision and neural networks. The book covers essential topics such as software installation, image processing techniques, and machine learning applications in computer vision.

Uploaded by

kireikurtes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
12 views

Building Computer Vision Applications Using Artificial Neural Networks, 2nd Edition Shamshad Ansari pdf download

The document provides information on downloading various ebooks and textbooks, particularly focusing on 'Building Computer Vision Applications Using Artificial Neural Networks, 2nd Edition' by Shamshad Ansari. It includes links to additional recommended products related to computer vision and neural networks. The book covers essential topics such as software installation, image processing techniques, and machine learning applications in computer vision.

Uploaded by

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

Download the full version and explore a variety of ebooks

or textbooks at https://ebookmass.com

Building Computer Vision Applications Using


Artificial Neural Networks, 2nd Edition Shamshad
Ansari

_____ Tap the link below to start your download _____

https://ebookmass.com/product/building-computer-vision-
applications-using-artificial-neural-networks-2nd-edition-
shamshad-ansari/

Find ebooks or textbooks at ebookmass.com today!


Here are some recommended products for you. Click the link to
download, or explore more at ebookmass.com

Analysis and Visualization of Discrete Data Using Neural


Networks Koji Koyamada

https://ebookmass.com/product/analysis-and-visualization-of-discrete-
data-using-neural-networks-koji-koyamada/

3-D Computer Vision: Principles, Algorithms and


Applications 1st Edition Yu-Jin Zhang

https://ebookmass.com/product/3-d-computer-vision-principles-
algorithms-and-applications-1st-edition-yu-jin-zhang/

Accelerators for Convolutional Neural Networks Arslan


Munir

https://ebookmass.com/product/accelerators-for-convolutional-neural-
networks-arslan-munir/

Computer vision: theory, algorithms, practicalities Fifth


Edition Davies

https://ebookmass.com/product/computer-vision-theory-algorithms-
practicalities-fifth-edition-davies/
AI Applications to Communications and Information
Technologies: The Role of Ultra Deep Neural Networks
Daniel Minoli
https://ebookmass.com/product/ai-applications-to-communications-and-
information-technologies-the-role-of-ultra-deep-neural-networks-
daniel-minoli/

Computer Networks, Global Edition Andrew S. Tanenbaum

https://ebookmass.com/product/computer-networks-global-edition-andrew-
s-tanenbaum/

Probabilistic graphical models for computer vision Ji Q

https://ebookmass.com/product/probabilistic-graphical-models-for-
computer-vision-ji-q/

Computer Vision Technology for Food Quality Evaluation,


Second Edition Sun

https://ebookmass.com/product/computer-vision-technology-for-food-
quality-evaluation-second-edition-sun/

Computer Networks and Internets 6th Edition, (Ebook PDF)

https://ebookmass.com/product/computer-networks-and-internets-6th-
edition-ebook-pdf/
Building Computer Vision
Applications Using
Artificial Neural Networks
With Examples in OpenCV
and TensorFlow with Python
Second Edition

Shamshad Ansari
Building Computer Vision Applications Using Artificial Neural Networks: With
Examples in OpenCV and TensorFlow with Python, Second Edition
Shamshad Ansari
Centreville, VA, USA

ISBN-13 (pbk): 978-1-4842-9865-7 ISBN-13 (electronic): 978-1-4842-9866-4


https://doi.org/10.1007/978-1-4842-9866-4

Copyright © 2023 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 author 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: Laura Berendson
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004,
U.S.A. 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 booktranslations@springernature.com; for reprint,
paperback, or audio rights, please e-mail bookpermissions@springernature.com.
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 https://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 (https://github.com/Apress). For more detailed information, please visit
https://www.apress.com/gp/services/source-code.
Paper in this product is recyclable
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.
Table of Contents
About the Author�����������������������������������������������������������������������������������������������������xv

About the Technical Reviewers�����������������������������������������������������������������������������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���������������������������������������������������������������������������������������� 3
Installing Python and PIP on Red Hat Linux����������������������������������������������������������������������������� 3
Installing Python and PIP on Windows������������������������������������������������������������������������������������� 3
virtualenv�������������������������������������������������������������������������������������������������������������������������������������� 4
Installing and Activating virtualenv����������������������������������������������������������������������������������������� 4
TensorFlow������������������������������������������������������������������������������������������������������������������������������������ 5
Installing TensorFlow on Mac with M1 Chip���������������������������������������������������������������������������� 6
Installing TensorFlow for CPUs������������������������������������������������������������������������������������������������ 7
Installing TensorFlow for GPUs������������������������������������������������������������������������������������������������ 7
PyCharm IDE��������������������������������������������������������������������������������������������������������������������������������� 8
Installing PyCharm������������������������������������������������������������������������������������������������������������������ 8
Configuring PyCharm to Use virtualenv����������������������������������������������������������������������������������� 9
OpenCV��������������������������������������������������������������������������������������������������������������������������������������� 10
Working with OpenCV������������������������������������������������������������������������������������������������������������ 11
Installing OpenCV 4 with Python Bindings����������������������������������������������������������������������������� 11

v
Table of Contents

Additional Libraries��������������������������������������������������������������������������������������������������������������������� 12
Installing SciPy���������������������������������������������������������������������������������������������������������������������� 12
Installing Matplotlib��������������������������������������������������������������������������������������������������������������� 12
Summary������������������������������������������������������������������������������������������������������������������������������� 12

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


Image Processing����������������������������������������������������������������������������������������������������������������������� 15
Image Basics������������������������������������������������������������������������������������������������������������������������������� 16
Pixels������������������������������������������������������������������������������������������������������������������������������������� 16
Coordinate Systems�������������������������������������������������������������������������������������������������������������������� 17
Using Python and OpenCV Code to Manipulate Images������������������������������������������������������������� 20
Program: Loading, Exploring, and Showing an Image����������������������������������������������������������� 21
Program: OpenCV Code to Access and Manipulate Pixels����������������������������������������������������� 23
Drawing��������������������������������������������������������������������������������������������������������������������������������������� 25
Drawing a Line on an Image�������������������������������������������������������������������������������������������������� 25
Drawing a Rectangle on an Image���������������������������������������������������������������������������������������� 28
Drawing a Circle on an Image����������������������������������������������������������������������������������������������� 32
Summary������������������������������������������������������������������������������������������������������������������������������������ 33

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


Transformation���������������������������������������������������������������������������������������������������������������������������� 36
Resizing��������������������������������������������������������������������������������������������������������������������������������� 36
Translation����������������������������������������������������������������������������������������������������������������������������� 40
Rotation��������������������������������������������������������������������������������������������������������������������������������� 43
Flipping���������������������������������������������������������������������������������������������������������������������������������� 45
Cropping�������������������������������������������������������������������������������������������������������������������������������� 48
Image Arithmetic and Bitwise Operations����������������������������������������������������������������������������������� 50
Addition��������������������������������������������������������������������������������������������������������������������������������� 51
Subtraction���������������������������������������������������������������������������������������������������������������������������� 55
Bitwise Operations���������������������������������������������������������������������������������������������������������������� 60
Masking�������������������������������������������������������������������������������������������������������������������������������������� 66
Splitting and Merging Channels�������������������������������������������������������������������������������������������������� 70

vi
Table of Contents

Noise Reduction Using Smoothing and Blurring������������������������������������������������������������������������� 73


Mean Filtering or Averaging�������������������������������������������������������������������������������������������������� 73
Gaussian Filtering������������������������������������������������������������������������������������������������������������������ 76
Median Blurring��������������������������������������������������������������������������������������������������������������������� 78
Bilateral Blurring������������������������������������������������������������������������������������������������������������������� 81
Binarization with Thresholding��������������������������������������������������������������������������������������������������� 83
Simple Thresholding�������������������������������������������������������������������������������������������������������������� 84
Adaptive Thresholding����������������������������������������������������������������������������������������������������������� 86
Otsu’s Binarization����������������������������������������������������������������������������������������������������������������� 89
Gradients and Edge Detection����������������������������������������������������������������������������������������������������� 92
Gradient-Based Edge Detection�������������������������������������������������������������������������������������������� 92
Canny Edge Detection����������������������������������������������������������������������������������������������������������� 99
Contours������������������������������������������������������������������������������������������������������������������������������������ 101
Morphological Transformation�������������������������������������������������������������������������������������������������� 104
Dilation�������������������������������������������������������������������������������������������������������������������������������� 105
Erosion��������������������������������������������������������������������������������������������������������������������������������� 106
Opening������������������������������������������������������������������������������������������������������������������������������� 107
Closing��������������������������������������������������������������������������������������������������������������������������������� 108
Morphological Gradient������������������������������������������������������������������������������������������������������� 109
Top Hat�������������������������������������������������������������������������������������������������������������������������������� 110
Black Hat����������������������������������������������������������������������������������������������������������������������������� 111
Template Matching������������������������������������������������������������������������������������������������������������������� 113
Template Matching with Multiple Objects��������������������������������������������������������������������������� 119
Summary���������������������������������������������������������������������������������������������������������������������������������� 124

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


Image Processing Pipeline�������������������������������������������������������������������������������������������������������� 125
Feature Extraction��������������������������������������������������������������������������������������������������������������������� 127
How to Represent Features������������������������������������������������������������������������������������������������� 129
Color Histogram������������������������������������������������������������������������������������������������������������������� 129
Histogram Equalizer������������������������������������������������������������������������������������������������������������ 136

vii
Table of Contents

GLCM����������������������������������������������������������������������������������������������������������������������������������� 140
HOGs������������������������������������������������������������������������������������������������������������������������������������ 145
LBP�������������������������������������������������������������������������������������������������������������������������������������� 152
Feature Selection���������������������������������������������������������������������������������������������������������������������� 159
Filter Method����������������������������������������������������������������������������������������������������������������������� 160
Wrapper Method������������������������������������������������������������������������������������������������������������������ 160
Embedded Method�������������������������������������������������������������������������������������������������������������� 161
Model Training��������������������������������������������������������������������������������������������������������������������������� 162
How to Do Machine Learning���������������������������������������������������������������������������������������������� 162
Supervised Learning������������������������������������������������������������������������������������������������������������ 163
Unsupervised Learning�������������������������������������������������������������������������������������������������������� 164
Model Deployment�������������������������������������������������������������������������������������������������������������������� 165
Summary���������������������������������������������������������������������������������������������������������������������������������� 167

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


Introduction to Artificial Neural Networks��������������������������������������������������������������������������������� 170
Perceptron��������������������������������������������������������������������������������������������������������������������������� 174
Multilayer Perceptron���������������������������������������������������������������������������������������������������������� 175
What Is Deep Learning?������������������������������������������������������������������������������������������������������ 176
Deep Learning or Multilayer Perceptron Architecture��������������������������������������������������������� 176
Activation Functions������������������������������������������������������������������������������������������������������������ 179
Feedforward������������������������������������������������������������������������������������������������������������������������ 187
Error Function���������������������������������������������������������������������������������������������������������������������� 187
Optimization Algorithms������������������������������������������������������������������������������������������������������ 192
Backpropagation����������������������������������������������������������������������������������������������������������������� 201
Introduction to TensorFlow�������������������������������������������������������������������������������������������������������� 202
TensorFlow Installation�������������������������������������������������������������������������������������������������������� 202
How to Use TensorFlow������������������������������������������������������������������������������������������������������� 202
TensorFlow Terminology������������������������������������������������������������������������������������������������������ 203

viii
Table of Contents

Our First Computer Vision Model with Deep Learning: Classification of Handwritten Digits���� 207
Model Overview������������������������������������������������������������������������������������������������������������������������������������������������ 207
Model Implementation��������������������������������������������������������������������������������������������������������� 208
Model Evaluation����������������������������������������������������������������������������������������������������������������������� 217
Overfitting���������������������������������������������������������������������������������������������������������������������������� 217
Underfitting�������������������������������������������������������������������������������������������������������������������������� 219
Hyperparameters���������������������������������������������������������������������������������������������������������������������� 223
TensorBoard������������������������������������������������������������������������������������������������������������������������ 224
Experiments for Hyperparameter Tuning����������������������������������������������������������������������������� 225
Saving and Restoring Model����������������������������������������������������������������������������������������������������� 229
Save Model Checkpoints During Training���������������������������������������������������������������������������� 230
Manually Save Weights������������������������������������������������������������������������������������������������������� 233
Load the Saved Weights and Retrain the Model������������������������������������������������������������������ 233
Saving the Entire Model������������������������������������������������������������������������������������������������������ 234
Retraining the Existing Model���������������������������������������������������������������������������������������������� 234
Using a Trained Model in Applications��������������������������������������������������������������������������������� 235
Convolutional Neural Network�������������������������������������������������������������������������������������������������� 236
Architecture of CNN������������������������������������������������������������������������������������������������������������� 236
How a CNN Works���������������������������������������������������������������������������������������������������������������� 238
Summary of CNN Concepts������������������������������������������������������������������������������������������������� 243
Training a CNN Model: Pneumonia Detection from Chest X-rays���������������������������������������� 244
Examples of Popular CNNs�������������������������������������������������������������������������������������������������� 255
Summary����������������������������������������������������������������������������������������������������������������������������� 260

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


Object Detection������������������������������������������������������������������������������������������������������������������������ 261
Intersection over Union������������������������������������������������������������������������������������������������������������� 262
Region-Based Convolutional Neural Network��������������������������������������������������������������������������� 264
Fast R-CNN������������������������������������������������������������������������������������������������������������������������������� 266
Faster R-CNN���������������������������������������������������������������������������������������������������������������������������� 267
Region Proposal Network���������������������������������������������������������������������������������������������������� 268
Fast R-CNN�������������������������������������������������������������������������������������������������������������������������� 269

ix
Table of Contents

Mask R-CNN������������������������������������������������������������������������������������������������������������������������������ 269


Backbone����������������������������������������������������������������������������������������������������������������������������� 270
RPN�������������������������������������������������������������������������������������������������������������������������������������� 271
Output Head������������������������������������������������������������������������������������������������������������������������� 271
What Is the Significance of the Masks?������������������������������������������������������������������������������ 271
Mask R-CNN in Human Pose Estimation����������������������������������������������������������������������������� 272
Single-Shot Multibox Detection������������������������������������������������������������������������������������������������ 273
SSD Network Architecture��������������������������������������������������������������������������������������������������� 273
Training�������������������������������������������������������������������������������������������������������������������������������� 276
SSD Results������������������������������������������������������������������������������������������������������������������������� 279
YOLO������������������������������������������������������������������������������������������������������������������������������������������ 279
YOLO Network Design���������������������������������������������������������������������������������������������������������� 282
Limitations of YOLO������������������������������������������������������������������������������������������������������������� 282
YOLO9000 or YOLOv2����������������������������������������������������������������������������������������������������������� 283
YOLOv3�������������������������������������������������������������������������������������������������������������������������������� 286
YOLOv4�������������������������������������������������������������������������������������������������������������������������������������� 289
YOLOv7�������������������������������������������������������������������������������������������������������������������������������������� 290
Comparison of Object Detection Algorithms����������������������������������������������������������������������������� 297
Comparison of Architecture������������������������������������������������������������������������������������������������� 298
Comparison of Performance������������������������������������������������������������������������������������������������ 299
Training Object Detection Model Using TensorFlow������������������������������������������������������������������ 300
TensorFlow on Google Colab with GPU�������������������������������������������������������������������������������� 301
Detecting Objects Using Trained Models����������������������������������������������������������������������������������� 332
Installing TensorFlow’s models Project������������������������������������������������������������������������������� 332
Code for Object Detection���������������������������������������������������������������������������������������������������� 335
Training a YOLOv7 Model for Object Detection�������������������������������������������������������������������������� 349
Dataset�������������������������������������������������������������������������������������������������������������������������������� 350
Preparing Colab Environment��������������������������������������������������������������������������������������������������� 352
Creating the data.yaml File������������������������������������������������������������������������������������������������������� 353
Cloning YOLOv7 GitHub Repository������������������������������������������������������������������������������������������� 353
Training YOLOv7 Model������������������������������������������������������������������������������������������������������������� 354

x
Table of Contents

Launching YOLOv7 Model Training��������������������������������������������������������������������������������������� 356


Monitoring Training Progress����������������������������������������������������������������������������������������������� 359
Monitoring Training Metrics Using TensorBoard������������������������������������������������������������������ 362
Inference or Object Detection Using the Training YOLOv7 Model���������������������������������������������� 362
Exporting YOLOv7 Model to ONNX��������������������������������������������������������������������������������������������� 364
Converting the ONNX Model to TensorFlow and TensorFlow Lite Formats�������������������������������� 366
Predicting Using TensorFlow Lite Model����������������������������������������������������������������������������������� 367
Summary���������������������������������������������������������������������������������������������������������������������������������� 371

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


Preparing the Working Environment����������������������������������������������������������������������������������������� 374
Reading a Video Stream������������������������������������������������������������������������������������������������������������ 376
Loading the Object Detection Model����������������������������������������������������������������������������������������� 379
Detecting Objects in Video Frames������������������������������������������������������������������������������������������� 380
Creating a Unique Identity for Objects Using dHash����������������������������������������������������������������� 381
Using the Hamming Distance to Determine Image Similarity��������������������������������������������������� 383
Object Tracking������������������������������������������������������������������������������������������������������������������������� 384
Displaying a Live Video Stream in a Web Browser�������������������������������������������������������������������� 387
Installing Flask�������������������������������������������������������������������������������������������������������������������� 387
Flask Directory Structure���������������������������������������������������������������������������������������������������� 387
HTML for Displaying a Video Stream����������������������������������������������������������������������������������� 387
Flask to Load the HTML Page���������������������������������������������������������������������������������������������� 389
Flask to Serve the Video Stream����������������������������������������������������������������������������������������� 389
Running the Flask Server���������������������������������������������������������������������������������������������������� 390
Putting It All Together���������������������������������������������������������������������������������������������������������������� 390
Summary���������������������������������������������������������������������������������������������������������������������������������� 400

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


FaceNet������������������������������������������������������������������������������������������������������������������������������������� 402
FaceNet Neural Network Architecture��������������������������������������������������������������������������������� 403
Training a Face Recognition Model������������������������������������������������������������������������������������������� 408
Checking Out FaceNet from GitHub������������������������������������������������������������������������������������� 409

xi
Table of Contents

Dataset�������������������������������������������������������������������������������������������������������������������������������� 410
Downloading VGGFace2 Data���������������������������������������������������������������������������������������������� 412
Data Preparation������������������������������������������������������������������������������������������������������������������ 414
Model Training��������������������������������������������������������������������������������������������������������������������� 419
Evaluation���������������������������������������������������������������������������������������������������������������������������� 420
Developing a Real-Time Face Recognition System������������������������������������������������������������������� 421
Face Detection Model���������������������������������������������������������������������������������������������������������� 421
Classifier for Face Recognition�������������������������������������������������������������������������������������������� 422
Summary���������������������������������������������������������������������������������������������������������������������������������� 428

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


Manufacturing������������������������������������������������������������������������������������������������������ 429
Real-Time Surface Defect Detection System���������������������������������������������������������������������������� 430
Dataset�������������������������������������������������������������������������������������������������������������������������������� 430
Google Colab Notebook������������������������������������������������������������������������������������������������������� 432
Data Transformation������������������������������������������������������������������������������������������������������������ 433
Training the SSD Model������������������������������������������������������������������������������������������������������� 442
Model Evaluation����������������������������������������������������������������������������������������������������������������� 445
Exporting the Model������������������������������������������������������������������������������������������������������������ 446
Prediction���������������������������������������������������������������������������������������������������������������������������� 447
Real-Time Defect Detector�������������������������������������������������������������������������������������������������� 448
Image Annotations�������������������������������������������������������������������������������������������������������������������� 448
Installing VoTT��������������������������������������������������������������������������������������������������������������������� 449
Create Connections������������������������������������������������������������������������������������������������������������� 450
Create a New Project����������������������������������������������������������������������������������������������������������� 451
Create Class Labels������������������������������������������������������������������������������������������������������������� 452
Label the Images����������������������������������������������������������������������������������������������������������������� 453
Export Labels����������������������������������������������������������������������������������������������������������������������� 454
Summary���������������������������������������������������������������������������������������������������������������������������������� 455

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


TensorFlow Distributed Training������������������������������������������������������������������������������������������������ 458
What Is Distributed Training?����������������������������������������������������������������������������������������������� 458

xii
Table of Contents

TensorFlow Distribution Strategy���������������������������������������������������������������������������������������� 461


TF_CONFIG: TensorFlow Cluster Configuration�������������������������������������������������������������������� 466
Example Code of Distributed Training with a Parameter Server����������������������������������������������� 468
Steps for Running Distributed Training on the Cloud���������������������������������������������������������������� 473
Distributed Training on Google Cloud���������������������������������������������������������������������������������������� 475
Signing Up for GCP Access�������������������������������������������������������������������������������������������������� 475
Creating a Google Cloud Storage Bucket����������������������������������������������������������������������������� 476
Launching GCP Virtual Machines����������������������������������������������������������������������������������������� 479
SSH to Log In to Each VMs�������������������������������������������������������������������������������������������������� 483
Uploading the Code for Distributed Training or Cloning the GitHub Repository������������������� 484
Installing Prerequisites and TensorFlow������������������������������������������������������������������������������ 484
Running Distributed Training����������������������������������������������������������������������������������������������� 485
Distributed Training on Azure���������������������������������������������������������������������������������������������������� 486
Creating a VM with Multiple GPUs on Azure������������������������������������������������������������������������ 487
Installing GPU Drivers and Libraries������������������������������������������������������������������������������������ 491
Creating virtualenv and Installing TensorFlow��������������������������������������������������������������������� 493
Implementing MirroredStrategy������������������������������������������������������������������������������������������ 494
Running Distributed Training����������������������������������������������������������������������������������������������� 494
Distributed Training on AWS������������������������������������������������������������������������������������������������������ 497
Horovod������������������������������������������������������������������������������������������������������������������������������� 497
How to Use Horovod������������������������������������������������������������������������������������������������������������ 498
Creating a Horovod Cluster on AWS������������������������������������������������������������������������������������� 502
Installing Horovod���������������������������������������������������������������������������������������������������������������� 510
Running Horovod to Execute Distributed Training��������������������������������������������������������������� 510
Summary���������������������������������������������������������������������������������������������������������������������������������� 512

Index��������������������������������������������������������������������������������������������������������������������� 513

xiii
About the Author
Shamshad Ansari is an author, inventor, and thought
leader in the fields of computer vision, machine learning,
artificial intelligence, and cognitive science. He has
extensive experience in high-scale, distributed, and parallel
computing. Sam currently serves as an adjunct professor at
George Mason University, teaching graduate-level programs
within the Data Analytics Engineering department of the
Volgenau School of Engineering. His areas of instruction
encompass machine learning, natural language processing,
and computer vision, where he imparts his knowledge and
expertise to aspiring professionals.
Having authored multiple publications on topics such as machine learning, RFID,
and high-scale enterprise computing, Sam’s contributions extend beyond academia. He
holds four US patents related to healthcare AI, showcasing his innovative mindset and
practical application of technology.
Throughout his extensive 20+ years of experience in enterprise software
development, Sam has been involved with several tech startups and early-stage
companies. He has played pivotal roles in building and expanding tech teams from
the ground up, contributing to their eventual acquisition by larger organizations.
At the beginning of his career, he worked with esteemed institutions such as the US
Department of Defense (DOD) and IBM, honing his skills and knowledge in the
industry.
Currently, Sam serves as the president and CEO of Accure, Inc., an AI company
that he founded. He is the creator and architect of, and continues to make significant
contributions to, Momentum AI, a no-code platform that encompasses data
engineering, machine learning, AI, MLOps, data warehousing, and business intelligence.
Throughout his career, Sam has made notable contributions in various domains
including healthcare, retail, supply chain, banking and finance, and manufacturing.

xv
About the Author

Demonstrating his leadership skills, he has successfully managed teams of software


engineers, data scientists, and DevSecOps professionals, leading them to deliver
exceptional results. Sam earned his bachelor’s degree in engineering from Birsa Institute
of Technology (BIT) Sindri and subsequently a master’s degree from the prestigious
Indian Institute of Information Technology and Management Kerala (IIITM-K), now
known as the Digital University of Kerala.

xvi
About the Technical Reviewers
Bharath Kumar Bolla has over 12 years of experience
and is a senior data scientist at Salesforce, Hyderabad.
Bharath obtained a master’s degree in data science from
the University of Arizona and a master’s degree in life
sciences from Mississippi State University. Bharath worked
as a research scientist for seven years at the University of
Georgia, Emory University, and Eurofins LLC. At Verizon,
Bharath led a team to build a “Smart Pricing” solution, and
at Happiest Minds, he worked on AI-based digital marketing
products. Along with his day-to-day responsibilities, Bharath is a mentor and an active
researcher with more than 20 publications in conferences and journals. Bharath received
the “40 Under 40 Data Scientists 2021” award from Analytics India Magazine for his
accomplishments.

F. Brett Berlin is currently a faculty member of the George


Mason University College of Engineering and Computing
Data Analytics Engineering master’s program. He brings five
decades of professional and life experience to his passion for
investing in people with purpose. He has served as professor,
executive consultant, mentor, applied global infosystem
strategist, high-performance computing executive and
policy leader, and early Internet policy partner. Strategically,
he seeks engagements with public/private/academic
collaborations for value creation with impact. His current eighth decade passion is
investing forward, by grace, serving ethically vision-driven digital/AI innovator aspirants
seeking to engage the challenges of the times.
Mr. Berlin is a graduate of the University of Texas Austin Graduate School of Arts
and Sciences (Computer Science, “Time-Extended Petri Nets”); the USAF Academy
(Computer Science, Mathematics & Engineering), and USAF Officer leadership schools.
He is married to Kathleen Berlin, with whom he shares children and grandchildren.

xvii
Acknowledgments
I wrote this book with two primary objectives in mind. First, I aimed to comprehensively
construct the foundations of computer vision concepts, starting from the basics and
progressing to an advanced level. Secondly, I aspired to furnish a practical guide for
the application of these concepts in real-world computer vision systems by including
practical use cases and code examples.
Achieving these objectives required meticulous organization of topics, integration
of content with meaningful and practical use cases, and thorough testing of the code,
all of which demanded my undivided attention throughout the writing process. This
accomplishment wouldn’t have been possible without the unwavering support of my
family. My gratitude is immeasurable towards my wife, Shazia, who managed the care of
our two daughters (Erum and Dua), ensuring they remained engaged while I dedicated
myself to the writing of this book. She ingeniously transformed this experience into a
positive experience for both them and myself. Remarkably, my children began tracking
my progress, celebrating each completion of a section, subsection, or chapter. Their
enthusiasm became a wellspring of energy and motivation that significantly enriched my
writing experience. I still do not 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.
Working with the Apress editorial team, which includes remarkable individuals like
Mark Powers and Laura Berendson, has been an incredible experience. I want to extend
a special thank you to Shonmirin PA, the project coordinator, who has been instrumental
in coordinating with the editorial team and technical reviewers and providing prompt
and helpful responses to my questions along the way.

xix
Acknowledgments

I would like to express my appreciation to John Celestin, Executive Editor at Apress.


His thoughtfulness and quick decision-making have left a profound impression on me.
Thank you, John, for having faith in my work. I also extend my gratitude to Apress for
making the publication of this book possible.
I wish to extend my gratitude to Bharat Bolla for his dedicated technical review of
this book. Additionally, I would like to express special appreciation to Professor Brett
Berlin for his meticulous review, invaluable insights, and constructive suggestions
that have significantly enhanced the quality of this book. Thank you, Bharat and
Professor Berlin.
Finally, I extend my thanks to the readers of this book. I am eagerly interested in
receiving your feedback. Kindly share your comments, suggestions, and questions with
me at ansarisam@gmail.com. Also, given the ever-evolving nature of technology, I may
need to update some of this book’s code examples via the book’s GitHub repository. I am
committed to maintaining the code updates, so check the book’s GitHub repository for
updates. I anticipate your valuable input and look forward to engaging with you.

xx
Introduction
For over 20 years, I have had the privilege of working with distinguished data scientists
and computer vision experts, some of the finest in their field. Throughout this journey,
I’ve gained invaluable insights, particularly in the realm of building scalable computer
vision systems following the best practices. This book encapsulates the wisdom acquired
from my work experience, as well as the collective knowledge amassed from the
exceptional individuals with whom I’ve had the fortune to work or collaborate. This book
also presents knowledge I’ve gained from the works of some of the greatest contributors
and thought leaders of computer vision. I have provided references to their work at
appropriate places throughout the book.
When I hire new engineers and scientists, one of my main challenges has been giving
them effective training so that they can quickly start contributing to the development
of computer vision systems. With numerous online resources and books available on
various computer vision topics, it’s easy to feel overwhelmed by the sheer amount of
information. This is especially true since the field of computer vision is extensive and
intricate.
In this book, my aim is to offer a structured and methodical approach to learning
computer visions systems. You will learn essential concepts first and then build on
those concepts by working through practical code examples that pertain to real-world
computer vision systems. This approach will help you connect the dots as you progress
through the chapters. I’ve structured this book to be as hands-on and practical as
possible to assist you effectively.
This book begins by explaining the core concepts of computer vision. It presents
code examples to help you understand these ideas better. In the beginning, the examples
mainly use OpenCV with the Python language.
This book also covers the basic concepts of machine learning and then gradually
moves into more complex concepts like artificial neural networks and deep learning.
Every concept is reinforced with one or more practical code examples that show how
the concept is applied in practice. Machine learning–related concepts are illustrated via
code examples in TensorFlow with Python.

xxi
Introduction

This book presents 11 examples, including working code, that demonstrate how
computer vision is used in real life. These examples are from different domains like
healthcare, surveillance, security, and manufacturing. To help you understand the code,
I explain each line step by step.
Chapters 7, 8, and 9 are dedicated to building practical computer vision–based
systems. These chapters show you all stages of how to create vision systems, from
obtaining pictures or videos, to building a data pipeline, to training a model, and finally
deploying the model for real situations.
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 final chapter, Chapter 10, provides step-by-step instructions
for building machine learning–based computer vision applications on three popular
cloud infrastructures: Google Cloud Platform, Amazon AWS, and Microsoft Azure.
Even though this book starts from explaining a single pixel of an image and goes up
to teaching how to use cloud computers for neural networks training, there are certain
prerequisites to better understand the concepts presented in this book. You should
already know how to use the Python programming language.
The purpose of this book is to assist working professionals, programmers, data
scientists, and even students (undergraduate and graduate) acquire hands-on skills for
building computer vision applications using artificial neural networks.

xxii
CHAPTER 1

Prerequisites and
Software Installation
This book is a practical guide that explores the process of building computer vision
applications using the Python programming language. Throughout this book, you will
gain a comprehensive understanding of leveraging OpenCV for image manipulation and
harnessing the power of TensorFlow to build machine learning models.
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 both CPUs and GPUs.
Python is the most widely used programming language for developing machine learning
applications. Both TensorFlow and OpenCV provide Python interfaces to access their
low-level functionality. While both TensorFlow and OpenCV also offer interfaces for
other programming languages like Java, C++, and MATLAB, we will focus on the use of
Python in this book. Python’s vast community support and intuitive syntax make it an
accessible language for learners and practitioners alike.
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. If you need to brush up
on these prerequisites, the following resources can be helpful:

• 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 2023
S. Ansari, Building Computer Vision Applications Using Artificial Neural Networks,
https://doi.org/10.1007/978-1-4842-9866-4_1
Chapter 1 Prerequisites and Software Installation

The first order of business is to prepare your working environment for the exercises
presented throughout this book. You will begin by downloading and installing the
necessary software libraries and packages.

Python and PIP


As mentioned, Python is the primary programming language that is used in this book.
For the installation and management of Python packages, we’ll rely on PIP, which is a
widely accepted package installer and a standard tool in the Python ecosystem.
To set up your working environment, you will begin by installing Python and PIP
on your computer. The installation steps depend on the operating system (OS) you are
using. The following sections provide, in order, the installation steps for Ubuntu, macOS,
Red Hat Enterprise Linux, and Windows. 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.8 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.8.10.
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 20.0.2.

Installing Python and PIP on Ubuntu


Run the following commands in your Ubuntu terminal:

sudo apt update


sudo apt install python3 python3-dev python3-pip

2
Chapter 1 Prerequisites and Software Installation

Installing Python and PIP on macOS


Run the following commands on macOS:

brew update
brew install python

This will install both Python and PIP.

Installing Python and PIP on Red Hat Linux


Run the following commands on Red Hat Linux:

sudo yum update


sudo yum install python3
sudo yum groupinstall 'Development Tools'

Installing Python and PIP on Windows


Install the Microsoft Visual C++ 2017 Redistributable Update 3. This comes with Visual
Studio 2017 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 Other Tools, Frameworks, and Redistributables.

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


Redistributable Update 3.

Make sure long paths are enabled on Windows. Here are the instructions to
do that: https://www.thewindowsclub.com/how-toenable-or-disable-win
32-long-paths-in-windows-11-10.
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/.

3
Chapter 1 Prerequisites and Software Installation

virtualenv
virtualenv is a tool designed to create isolated Python environments. When you use
virtualenv, it generates a directory that includes all the necessary executables for utilizing
the packages required by a Python project. virtualenv provides the following advantages:

• It enables the coexistence of two versions of the same library,


allowing two programs running different versions of the library to
function properly. For example, if you have one program that relies
on version 1 of a Python library and another program that relies
on version 2 of the same library, virtualenv allows you to run both
programs simultaneously.

• It establishes a self-contained and independent environment for your


development work, which can be utilized in a production setting
without the need to install dependencies separately.

Next, we will install virtualenv and set up the virtual environment with all the
necessary software. The rest of the book assumes that the dependencies for our
reference program will be contained in this virtualenv.

Installing and Activating virtualenv


To install virtualenv system-wide, execute the following PIP command, which works the
same for all operating systems:

$ sudo pip3 install -U virtualenv

After the installation is complete, create a directory of your choice where you intend
to set up the virtualenv. For purposes of following the examples in this book, name this
directory cv (short for “computer vision”):

$ mkdir cv

Then create the virtualenv in this cv directory:

$ virtualenv --system-site-packages -p python3 ./cv

4
Chapter 1 Prerequisites and Software Installation

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$

Installing packages within a virtual environment does not affect the host system
setup. Start by upgrading PIP as follows. Please note that you should not execute any
command as root or sudo while inside the virtual environment.

$ pip install --upgrade pip


$ pip list  # show packages installed within the virtual environment

When you have finished your programming activities and you want to exit from
virtualenv, run the following:

$ deactivate

TensorFlow
TensorFlow is a widely used open source library for numerical computation and
large-scale machine learning. In the upcoming chapters, you will delve deeper into
TensorFlow and explore its capabilities. However, before we proceed, let’s begin by
installing TensorFlow and preparing it for our deep learning exercises. If you have a
GPU in your computer and you want to utilize it for deep learning tasks, you typically
don’t need to install both CPU and GPU versions of TensorFlow. You can install the GPU
version, which includes support for both GPU and CPU computation. TensorFlow with
GPU support automatically falls back to CPU execution when GPU resources are not

5
Chapter 1 Prerequisites and Software Installation

available or when the operations are not suitable for GPU acceleration. So, installing
TensorFlow with GPU support (tensorflow-gpu) should be sufficient. It will work on both
GPU and CPU, making it a versatile choice for most deep learning tasks.

Installing TensorFlow on Mac with M1 Chip


The steps for installing TensorFlow on an M1 chip are as follows:

1. Download the Conda environment from the following link:


https://repo.anaconda.com/miniconda/Miniconda3-latest-
MacOSX-arm64.sh.

2. Assuming that the downloaded file Miniconda3-latest-MacOSX-


arm64.sh is in the Downloads folder, execute the following
command to install Miniconda3:

$ sh Downloads/Miniconda3-latest-MacOSX-arm64.sh

3. Follow the onscreen instructions to complete the installation of


Miniconda3 on your computer. If you proceed with the default
options, Miniconda3 will be installed in your home directory.
For example, if your home directory is /Users/username, the
path for Miniconda3 after installation will be /Users/username/
miniconda3.

4. Once the installation is finished, restart the terminal.

5. Create a virtual environment using Miniconda3 by running the


following command:

$ conda create --name cv python=3.8

6. To activate or deactivate this virtual environment, use the


following commands:

$ conda activate cv
$ conda deactivate
7. Activate the virtual environment by running the command conda
activate cv, and then install TensorFlow by executing the
following commands:

6
Chapter 1 Prerequisites and Software Installation

$ conda install -c apple tensorflow-deps


$ pip install tensorflow-macos
$ pip install tensorflow-metal
$ conda install tensorflow

8. Test the TensorFlow installation by running the command:

$ python -c "import tensorflow as tf"

9. If this command executes without errors, it means that


TensorFlow has been successfully installed on your M1 chip.

10. If you encounter any errors, resolve incompatibility issues by, for
example, upgrading the Mac OS.

Installing TensorFlow for CPUs


To install the most recent version of TensorFlow from PyPI (https://pypi.org/
project/tensorflow/), specifically for CPUs, ensure that you are within the virtual
environment and execute 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.

Installing TensorFlow for GPUs


To install TensorFlow for GPUs, you need to follow a slightly different installation
process. Here are the steps:

1. Ensure that you have the appropriate NVIDIA GPU and drivers
installed on your system. You can check the TensorFlow
documentation for the specific GPU requirements and compatible
driver versions.

2. Activate the virtual environment that we created before.

7
Chapter 1 Prerequisites and Software Installation

3. Install the necessary GPU drivers and dependencies. Refer to the


TensorFlow documentation for the specific instructions based on
your operating system.

4. Install the GPU version of TensorFlow using the following command:

(cv) $ pip install --upgrade tensorflow-gpu

This command installs the latest version of TensorFlow that


supports GPU acceleration.

5. After the installation, you can test your TensorFlow-GPU setup by


running the following command:

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


list_physical_devices('GPU')"

If TensorFlow-GPU is installed correctly and GPU support is enabled, it will display


information about the available GPUs on your system.
Please note that installing TensorFlow for GPUs requires additional setup and can be
more complex compared to the CPU version. It is recommended to refer to the official
TensorFlow documentation for detailed instructions and troubleshooting guidance
specific to your system configuration.

PyCharm IDE
For consistency, the integrated development environment (IDE) used throughout this
book for writing and managing Python code is the community version of PyCharm, a
popular Python IDE. You can choose to use your preferred IDE, but if you do so, you’ll
need to adapt relevant examples and exercises to your IDE.

Installing PyCharm
To acquire PyCharm from its official website, follow these steps:
1. Visit the PyCharm website at https://www.jetbrains.com/
pycharm/download/.

2. Select the appropriate operating system that corresponds to your


machine.
8
Chapter 1 Prerequisites and Software Installation

3. Scroll down to the PyCharm Community Edition section and click


the Download button.

4. Once the download is complete, locate the downloaded package


and execute it.

5. Follow the instructions provided onscreen to complete the


installation.

Here are the direct download 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

Please note that these links may change over time, so it’s recommended to visit the
official PyCharm website to ensure you access the most up-to-date download links.

Configuring PyCharm to Use virtualenv


To use the virtualenv named cv that was created earlier, follow these steps in the
PyCharm IDE:

1. Launch PyCharm and open your project. Then choose File ➤


Settings on Windows and Linux or choose PyCharm ➤
Preferences on macOS.

2. In the Settings/Preferences dialog, navigate to Project


<project name> ➤ Project Interpreter.

3. Click the icon (usually represented by a gear or a plus sign) and


select Add from the drop-down menu.

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


Existing Environment.

9
Chapter 1 Prerequisites and Software Installation

5. Expand the Interpreter list and choose one of the existing


interpreters displayed, or click the icon to specify the path to
the Python executable in your file system, for example, /Users/
ansarisam/cv/bin/python3.8 (see Figure 1-1). This path should
correspond to the virtual environment cv that you created earlier.

Optionally, you can select the checkbox “Make available to all projects” if you want
this interpreter to be accessible for all your projects in PyCharm.
By following these steps, you will configure PyCharm to use the virtual environment
cv as the Python interpreter for your project.

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, the installation steps
presented in this section are for version 4 of OpenCV.
10
Chapter 1 Prerequisites and Software Installation

Working with OpenCV


OpenCV is primarily written in C/C++, and its installation instructions vary depending
on which operating system you are using. Since OpenCV is platform-dependent, it
needs to be built specifically for your OS to ensure smooth operation. In this book,
we will utilize Python bindings to interface with OpenCV for any image processing
requirements.
OpenCV is continuously evolving, so if the following installation instructions do not
work for your specific case, refer to the official OpenCV website for the most up-to-date
and accurate installation process.
To simplify the installation process, we will use PIP to install OpenCV 4 and its
Python 3 bindings. If you need additional OpenCV modules and features, you can install
the opencv-contrib-python package.
Now, let’s proceed with the installation process!

Installing OpenCV 4 with Python Bindings


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

$ source cv/bin/activate

Install OpenCV in a snap using the following command:

$ pip install opencv-python

To install the opencv-contrib-python package, which includes extra modules and


features that are not part of the main OpenCV package, use the following command:

$ pip install opencv-contrib-python

Once the installation is complete, you can verify it by importing OpenCV in your
Python command:

$ python -c "import cv2"

If there are no errors, it indicates that OpenCV has been successfully installed.

11
Chapter 1 Prerequisites and Software Installation

Note Package names for OpenCV may vary slightly based on your specific
operating system or Python version. If you encounter any issues during the
installation, refer to the official OpenCV documentation or the PyPI page for the
most accurate and up-to-date installation instructions.

Additional Libraries
SciPy and Matplotlib are two 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

Note 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.

Summary
The following table summarizes the installation commands for the required libraries
within your virtualenv. You can copy and paste these commands into your terminal to
install the libraries.

12
Chapter 1 Prerequisites and Software Installation

Table 1-1. Installation Commands for Required


Libraries in virtual environment
Library Command

TensorFlow pip install tensorflow


TensorFlow GPU pip install tensorflow-gpu
OpenCV pip install opencv-python
OpenCV Contrib pip install opencv-contrib-­python
SciPy pip install scipy
NumPy pip install numpy
Matplotlib pip install matplotlib

Ensure that your virtualenv is activated before running these commands. Once
you’ve installed these libraries, you’ll have all the necessary dependencies within your
virtualenv to work with the examples in the book.

13
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 write code in Python and use OpenCV to work with examples to


access and manipulate images

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


an image

Image Processing
Image processing is a method used to manipulate a digital image to obtain an improved
image or extract valuable information from it. It involves taking an image as input
and producing as output either another image or specific characteristics and features
associated with that image. Videos, being composed of a series of images or frames, can
also be processed using image processing techniques. In this chapter, we will delve into
the fundamental concepts of digital image processing. Additionally, you will acquire the
basic skills to work with images and write code to manipulate them.

15
© Shamshad Ansari 2023
S. Ansari, Building Computer Vision Applications Using Artificial Neural Networks,
https://doi.org/10.1007/978-1-4842-9866-4_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. This
chapter explains the fundamental components that make up an image and guides you
through the process of manipulating images using OpenCV and Python.

Pixels
An image can be visualized as a collection of dots arranged in rows and columns, where
each dot represents a pixel with a specific color. These pixels are assigned numerical
values, which determine their respective colors. You can imagine an image as a grid
of square cells, where each cell corresponds to a single pixel with a specific color. For
instance, if we have a 300×400-pixel image, it implies that the image is structured as a
grid with 300 rows and 400 columns, resulting in a total of 120,000 pixels.

Pixel Color
A pixel can be represented in two different 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. Other color models are available, but this book primarily
focuses on the RGB color model.

16
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.

The W3Schools website is a great place to play with different combinations of RGB
tuples to explore more patterns (https://www.w3schools.com/colors/colors_rgb.asp).
Use the RGB Calculator to explore what color is represented by each of the following tuples:

(0,0,255)

(255,255,255)

(0,0,128)

(128,0,128)

(128,128,0)

Now try to make the color 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, the RGB
tuple for yellow is (255,255,0).
Now that you have a good understanding of pixels and their color, let’s explore how
pixels are arranged in an image and how to access them. The following section discusses
the concept of coordinate systems in image processing.

Coordinate Systems
As previously mentioned, 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
forms an 8×8 or 64-pixel image. Think of it as a 2D coordinate system in which the origin
(0,0) is the top-left corner. Figure 2-1 shows our example 8×8-pixel image.

17
Chapter 2 Core Concepts of Image and Video Processing

Figure 2-1. Pixel coordinate system

With the top-left corner as the start or origin of the image coordinate system, the
pixel at the top-right corner is represented by (0,7), the bottom-left pixel 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 this concept a little clearer, consider Figure 2-2, an image that is 8×8 pixels,
with the letter H written on it. 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


pixel is represented by 255. Figure 2-3 shows the values of each of the pixels within the
8×8 grid.

18
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)?
Now, you should have a clear understanding of how images are represented as
numbers arranged in a grid. These numerical values are serialized and stored in a
computer’s storage system. When the image is displayed on the screen, these numbers
are interpreted and rendered as an actual image.
At this point, you have learned how to access individual pixels using the coordinate
system, which allows you to pinpoint specific locations within the image grid.
Additionally, you have learned how to assign colors to these pixels by manipulating their
numerical values. By grasping these concepts, you now understand how images are
structured and how to interact with them programmatically.
With a solid foundation and understanding of image representation, you are now
ready to gain practical experience through Python and OpenCV coding. In the following
section, I will guide you step-by-step through the process of writing code that loads
images from the computer’s disk, accesses individual pixels, performs manipulations,
and saves the modified images back to the disk.
Let’s delve into the exciting world of image processing and begin our hands-on journey!

19
Chapter 2 Core Concepts of Image and Video Processing

 sing Python and OpenCV Code to


U
Manipulate Images
In OpenCV, the pixel values of an image are represented using a NumPy array. (Not
familiar with NumPy? You can find a “getting started” tutorial at https://numpy.org/
devdocs/user/quickstart.html.) This NumPy array serves as a multidimensional
representation of the image grid and its color channels. It allows us to efficiently store,
access, and manipulate the pixel values of the image. By leveraging the capabilities
of NumPy arrays, OpenCV provides a powerful framework for image processing and
analysis tasks. In other words, when you read 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 returns 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. In other words, OpenCV stores the colors in BGR
sequence, not in RGB sequence. Remember this important feature of
OpenCV to avoid any confusion while working with OpenCV.

Before we write any code, let’s make sure we always use our virtual environment, in
the ~/cv directory, that we already set up with PyCharm in Chapter 1.
Launch your PyCharm IDE and make a new 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.8 (cv) selected.

20
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


In this section, we will write code to read an image from a file and explore its properties.
We will utilize the OpenCV library, which provides powerful tools for image processing
and analysis. By loading the image into our program, we will be able to access
information such as its dimensions, size, and channel information. Additionally, we
will display the image on the screen and wait for a keypress to continue execution. This
exploration will give us a better understanding of the image and set the stage for further
image processing tasks. Let’s dive into the code and start exploring the 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    import cv2
2
3    # image path
4    image_path = "images/marsrover.png"
5

21
Chapter 2 Core Concepts of Image and Video Processing

6    # Read or load image from its path


7    image = cv2.imread(image_path)
8
9    # image is a NumPy array
10    print("Dimensions of the image: ", image.ndim)
11    print("Image height: ", format(image.shape[0]))
12    print("Image width: ", format(image.shape[1]))
13    print("Image channels: ", format(image.shape[2]))
14    print("Size of the image array: ", image.size)
15
16    # Display the image and wait until a key is pressed
17    cv2.imshow("My Image", image)
18    cv2.waitKey(0)

The code in Listing 2-1 is explained here:


• Line 1: We import the OpenCV library, enabling us to utilize its
functions and capabilities.
• Line 4: We assign to a variable the path of the image that we are going
to load from the disk. If your input path is in a different directory, you
should give either the full or relative path to the image path.
• Line 7: Using the imread() function of OpenCV, we are reading the
image into a NumPy array and assigning that to a variable called
image (you can name this variable anything you like).
• Lines 10 through 14: Using NumPy features, we are printing the
dimensions of the image array, height, width, number of channels,
and size of the array (which is the number of pixels).
• Line 17: This line displays the image as is using OpenCV’s imshow()
function, which takes two arguments: the name of the image window
and the Numpy array representing the image.
• Line 18: The waitKey() function allows the program to not terminate
immediately and wait for the user to press any key. When you see the
image window that will display in line 17, press any key to terminate
the program, else the program will block.

22
Chapter 2 Core Concepts of Image and Video Processing

Note 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-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

The NumPy array representing the image has three dimensions: height × width ×
channel. The first element of the array corresponds to the height, indicating the number of
rows in the image pixel grid. Similarly, the second element represents the width, indicating
the number of columns in the grid. The three channels represent the color components in
the order of blue, green, and red (BGR), rather than the conventional RGB. The overall size
of the array is 400×640×3 = 768,000. This means that the image contains a total of 400×640
= 256,000 pixels, with each pixel consisting of three color values.

Program: OpenCV Code to Access and Manipulate Pixels


In the following program, we will explore how to access and modify pixel values using the
coordinate system described earlier. Listing 2-2 demonstrates this process and is followed
by a line-by-line explanation to help you understand each step of the implementation.

23
Chapter 2 Core Concepts of Image and Video Processing

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


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

Listing 2-2 is explained here:


• Lines 1 through 6: We import OpenCV’s cv2 package and read
the image from a directory path (as explained when discussing
Listing 2-1).
• Line 9: We are getting the BGR (not RBG) values of the pixel at
coordinates (0,0) and assigning them to the (b,g,r) tuple using the
NumPy syntax.
• Line 10: This line prints the BGR values.
• Line 13: 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)—pure blue, pure green, and no red—
to all the pixels within this square.
• Line 14: This line displays the modified image.
• Line 15: The program waits for the user to press any key for the
program to exit.
Figure 2-6 shows a sample output of Listing 2-2.
24
Chapter 2 Core Concepts of Image and Video Processing

Blue, Green and Red values at (0,0): (255, 255, 0)

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.

Drawing
OpenCV provides convenient methods to draw various shapes on an image. In the
following sections, we will explore how to draw a line, a rectangle, and a circle using the
corresponding methods provided by OpenCV:

• Line: line()

• Rectangle: rectangle()

• Circle: circle()

These methods allow us to easily add these shapes to an image, enhancing our
ability to annotate and visualize data.

Drawing a Line on an Image


To draw a line on an image using OpenCV, follow these steps:
1. Load the image into a NumPy array.
2. Determine the coordinates of the starting position of the line.
3. Determine the coordinates of the end position of the line.
4. Specify the color of the line.
5. Optionally, specify the thickness of the line.
25
Chapter 2 Core Concepts of Image and Video Processing

Let’s proceed with the implementation and explore how each step is carried out in
code. 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    import cv2
2
3     # image path
4    image_path = "images/marsrover.png"
5    # Read or load image from its path
6    image = cv2.imread(image_path)
7
8    # set start and end coordinates
9    start = (0, 0)
10   end = (image.shape[1], image.shape[0])
11   # set the color in BGR
12   color = (255,0,0)
13    # set thickness in pixel
14   thickness = 4
15   cv2.line(image, start, end, color, thickness)
16
17   # display the modified image
18   cv2.imshow("Modified Image", image)
19   cv2.waitKey(0)

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

• Lines 1 through 6: As in the previous listings, these lines import the


OpenCV package and load the image from an input directory to a
NumPy array.

• Line 9: We set 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.
• Line 10: We set the coordinates of the endpoint of the image. Notice
that the expression (image.shape[1], image.shape[0]) represents
the coordinates of the bottom-right corner of the image.
26
Other documents randomly have
different content
She little knew why Jerry valued them, and what a quantity of
wealth had been concealed in the soiled garments.
With trembling fingers, and features working with agitation, Jerry
took the clothes, and began to feel for his treasures. Alas for the old
man! His worst fears were realized. The bank books and certificate
of stock had been removed. Not a trace of them was to be found.
The poor man, for he was to be pitied, uttered a sharp cry of
anguish. The clothes dropped from his nerveless hands, and he fell
back on the bed as if stricken with a mortal wound.
“Help! Help! Police!” he ejaculated. “I’ve been robbed.”
“Robbed is it?” inquired Mrs. Hogan, puzzled. “And of what have you
been robbed, ould man?”
“There were two savings bank books in the pockets. You’ve taken
them!”
“Well, well, if I ever heard the loike!” exclaimed Mrs. Hogan,
indignantly. “So you call me a thafe, do you?”
“Give them back to me!” said the old man, imploringly. “I—I am so
poor. It will kill me if I lose my money.”
“Two savings bank books, indade!” said Mrs. Hogan. “It’s my belafe
you’re an ould humbug, you that have always called yourself so
poor. And how much money was there in them?” she asked.
“I—I—no matter. Give me the books, or I’ll send for the police.”
“Go and welcome, this minute, if you please. You ought to know
better than to call an honest woman a thafe.”
“Somebody has taken the books,” wailed Jerry.
“Very likely Paul’s taken care of them for you. He was here alone
with the clothes.”
“Where is Paul?” demanded Jerry, with peevish eagerness.
“He’s at his work, but I’m expecting him back every minute. If he
has taken the books, they are all right. Paul’s an honest boy, and a
fine boy.”
“Do you think he would rob me, Mrs. Hogan?” asked Jerry, piteously.
“It’s a shame to be askin’ such a question,” said Mrs. Hogan. “Shure
you know Paul wouldn’t demane himself by such an act. But here he
is to answer for himself.”
She heard Paul’s step on the stairs, as he came up whistling. Directly
afterwards he entered the room.
“What’s the matter?” he asked, looking from one to the other.
“The ould man’s in a great taking about bein’ robbed, Paul,”
answered Mrs. Hogan. “He says some savings bank books have been
taken from his clothes.”
“Where are they, Paul?” wailed the old man.
“They are safe, Jerry. I took them from your pockets, and the
railroad shares, too, and have left them with a Safe Deposit
Company, for safe keeping.”
“Are you sure they are safe, Paul?”
“Yes, much safer than they would be here. Of course Mrs. Hogan is
honest, but other persons might come into the room.”
“Bring them back to me, Paul. I want to see them.”
“I can if you insist upon it, Jerry. But you are too sick to look after
them. Besides, suppose your son should come in some day. He could
rob you easily, and you would never see your property again. Shall I
show you the receipt for them?”
“Yes.”
Paul drew from his pocket the receipt given him by the Safe Deposit
Company, and displayed it to the old man.
“Let me keep this?” said Jerry.
“Yes, if you like.”
This seemed to satisfy him, and he clutched the paper with a deep
sigh of relief.
“Shure, and you’ve calmed him down, Paul,” said Mrs. Hogan. “Was
it really true about the books?”
“It was really true, Mrs. Hogan. He has a good deal of money,
though he doesn’t look it.”
“Thin it’s a fool he is to live as he does, whin he might live like a
gintleman.”
“He will never live differently. When he dies it will go to his son, who
will get through with it in short order.”
Then Mrs. Hogan told Paul about the visit of Ellen Barclay, and her
discovering a relation in old Jerry.
“I wish she might have some of the money. Shure, she nades it with
her young children.”
“I would much rather she would have it than his son, who is a
ruffian and a burglar.”
“And you’ll help her to it, if you can, Paul?”
“Yes, I will. I don’t want Jerry’s money myself. I am young, and my
prospects are good. All I want is that it should go into the right
hands.”
CHAPTER XXVIII.
JERRY FINDS A NEW RELATION.

Ellen Barclay came over the next evening according to appointment,


and had an interview with Paul. She had at first been disposed to
look upon him with suspicion, as likely to divert Jerry’s money from
his legal heirs, but the interview dispelled all such ideas. The
telegraph boy was so frank and free spoken, and showed such an
interest in helping her, that she was strongly impressed in his favor.
He even told her the particulars of his first encounter with her
husband, and in what manner he had defeated his plan of gaining
possession of Mr. Cunningham’s money.
“Yes,” said Ellen, bitterly, “he is a husband to be proud of.”
“Has he always been as bad?” asked Paul.
“Yes; I had not been married to him a month before I found out that
I was wedded to a criminal. He treated me brutally, and I only
breathed freely when he was away from home. Within a year from
the wedding day, he was condemned to a year’s imprisonment, and
at least half the time since he has been in confinement.”
“Leaving you to support yourself, I suppose?”
“Yes, I have had to support myself and the children. Even when he
was a free man, he did little or nothing for the family.”
“How did you support yourself?” asked Paul.
“At first I undertook to maintain myself by the needle, but the
miserable pittance I received showed me that I must try some other
means of support. On inquiry I found that nothing paid as well as
fine laundry work for ladies. It was a trial to my pride, for I was well
brought up and educated, to take in washing for a living, but I would
rather do that than see my children suffer. So I stifled my pride and
became a laundress. I was fortunate in securing customers, and I
have wanted for nothing, neither have my children—nothing at least
that was necessary to comfort. But when my husband came home
lately, and proposed to put upon me the additional burden of his
support, I became discouraged.”
“I hope better days are in store for you,” said Paul.
“Not while my husband lives, and can find me out,” said Ellen
Barclay, sadly.
“Do you wish me to introduce you to your husband’s father?”
“Do you think it will be best?”
“We had better try the experiment at any rate. He may die, and if he
does his money ought to go to you.”
“It would be a great relief to me if my children would be provided
for.”
“Follow me, then.”
Following Paul, Ellen Barclay went into the chamber occupied by old
Jerry.
The old man looked up, noticing Paul only.
“Do you think I will get well, Paul?” he asked.
“Yes, Jerry, if you receive proper care, and have nourishing food.”
“But—I am so poor, Paul.”
“That is a mistake, Jerry, as you and I know.”
“Don’t let any one know of the few dollars I have, Paul.”
“I won’t let your son know; he is the only one of whom you need be
afraid. Did you know he was married, and had two children?”
“I—I think he said something of it.”
“Would you like to see his wife?”
“I—I don’t know,” answered the old man, in an uncertain voice.
“This lady is your son’s wife,” said Paul, beckoning Ellen to come
forward.
The old man regarded her with an uneasy look. “I hope you are not
like James,” he said; “he is a bold, bad man!”
“No one knows that better than I, Mr. Barclay. It was a sad day
when I married him.”
“You have found him out, too?”
“Yes, to my sorrow.”
“You won’t try to get my money?” asked Jerry, anxiously.
“No, but I should like to bring my children here to see their
grandfather.”
“Are they—like him?”
“No, thank Heaven!”
“Then you may bring them.”
“I will. Can I do anything for you?”
“No, except to keep James away.”
“You have made a good impression on him,” said Paul, when they
had left the room together.
“Thanks to you,” said Ellen, earnestly. “You are a good boy, and an
unselfish one. Hereafter I shall trust you fully.”
CHAPTER XXIX.
A NEW COMMISSION.

“If Number 91 is unemployed, send him to No. 75, Windsor Hotel, at


eleven o’clock.”
This message came to the telegraph office at which Paul was
enrolled.
The superintendent called him to the desk.
“Here is a call for you, Number 91,” he said. “It comes from a lady,
Mrs. Louisa Holbrook. Do you know her?”
“No, sir.”
“Are you familiar with the name?”
“No, sir; I never heard it before.”
“She has evidently heard of you. It is now ten o’clock. At half past
ten you may start for the Windsor Hotel. If you arrive there before
eleven, you may wait till the hour, and then report at the room
indicated.”
“Yes, sir.”
Paul arrived at the Windsor Hotel at ten minutes before the hour.
This magnificent hostelry is situated on Fifth Avenue, and occupies
the entire block between Forty Sixth and Forty Seventh Streets. It is
built of brick, and has an air of quiet elegance which makes it a
favorite with ladies and others who like to be spared the noise and
bustle which attend other prominent hotels in the city. On the corner
just above stands the luxurious home of Jay Gould, the railroad king.
A few blocks above is the great Catholic Cathedral, destined one day
to rank among the famous churches of the world. Still further up, on
the opposite side, are the stately houses occupied by the Vanderbilt
family. These things, however, did not occur to Paul, for he was too
familiar with the leading buildings on the avenue to give them a
special thought, further than to reflect, “The men who occupy these
fine houses were once poor boys—many of them. I wonder whether
it will ever be my fortune to live as handsomely!”
It was only a thought, not seriously entertained. Paul wanted to rise,
but an active, healthy boy seldom thinks of luxury, or craves it. That
comes later, after he has attained manhood.
Paul entered the hotel, and, going up to the office, expressed a wish
to see Mrs. Louisa Holbrook.
“Were you sent for?” asked the clerk.
“Yes, sir.”
“Then you may go up at once. Here”—to a bell boy—“show this boy
up to No. 75, Mrs. Holbrook’s room.”
Though the room was only on the second floor, Paul followed the
bell boy into the elevator. At the second landing he got out, and
followed the hotel attendant to the door of a room fronting on the
avenue. The bell boy knocked, and a voice said, “Come in!”
“It is a telegraph boy, ma’am,” said the servant.
“He may come in, and you can go.”
Paul entered the room—a large and handsome one—and found
himself in presence of a lady not much over thirty years of age, with
a pleasant face and manner.
“You are Number 91?” she asked.
“Yes, ma’am.”
“I suppose you are surprised that I should have sent specially for
you,” the lady said, with a smile.
“I wondered how you came to hear of me,” said Paul.
“That is easily explained. I am a cousin of Mr. Cunningham.”
Paul’s face brightened. It was pleasant to serve any one connected
with a family from which he had received so much kindness.
“That explains it,” he said; “all the family have treated me very
kindly.”
“I assure you that you stand very high in their estimation,” said Mrs.
Holbrook, smiling once more. “My young cousin Jennie was here
yesterday, and on learning the nature of my business urged me to
send for you.”
“I am very much obliged to Miss Jennie,” said Paul with genuine
pleasure, for though too young to be in love, he liked Jennie
Cunningham better than any girl he had ever seen.
“It is time I explained the errand on which I propose to employ you,”
said Mrs. Holbrook. “You must know, then, that I have an old aunt
living at the village of Rockville, in Connecticut. She is advanced in
years, and possessed of large wealth. She has a comfortable home,
and prefers to keep house rather than live with any of her relatives.
She does not live alone, however. She employs a housekeeper, a
Mrs. Mercer, whose son, a young man of twenty five, also finds
employment on the place. This woman, I have reason to think, is an
artful person, who, knowing my aunt to be wealthy, has ingratiated
herself with her, and is evidently scheming for her property, or at
any rate a handsome share of it. If it were any person who had a
rightful claim, I think I may say for myself and my cousins that we
would not interfere in the matter, as we are all moderately rich. But
we decidedly object to our aunt’s falling into the hands of an artful
adventurer like this housekeeper. You are wondering, no doubt, how
all this concerns you. I will come to that. Mrs. Cunningham tells me
you are a sharp, shrewd boy, and I propose to send you down as a
confidential messenger, to look about you, judge of the progress the
housekeeper has made in her designs, and, if you see anything
wrong, apprise us, or, if there is any chance, open my aunt’s eyes to
the real character of the persons she has trusted.”
Paul listened to Mrs. Holbrook’s statement with attention. Some
difficulties, however, presented themselves to his mind.
“Unless I am in the house,” he said, “I shall find it difficult to carry
out your instructions.”
“You will be in the house. I shall give you a letter to my aunt, saying
that you are a boy in whom I am interested, and that I am anxious
to have you pass a few weeks in the country. Can you drive a
horse?”
“There is nothing I like better,” answered Paul, promptly.
“Can you take care of a horse?”
“Yes, indeed.”
“How did you acquire this knowledge in the city?”
“Not far from where I live is a stable, kept by a man whom I know
well; I have been in there a good deal, and helped him when he
needed it. Sometimes I would drive out for him.”
Mrs. Holbrook nodded approvingly. “I am glad to hear it,” she said.
“My aunt is fond of riding, and has a horse and carriage. She can
make you useful in that way, and also as her secretary if she needs
any one to write for her, or read to her. I suppose you are equal to
such duties?”
“Yes, ma’am. I am not to go as a telegraph boy, I presume?”
“No; have you another suit?”
“Yes, but I am afraid it is not good enough.”
“Then I will fit you out. I may as well write a letter first to my aunt,
and then I will see about proper clothes for you. I think I will go to
Brokaw Brothers. Can you go with me at once?”
Paul answered in the affirmative.
“What is your name?”
“Paul Parton.”
“A very good name. That will do quite nicely.”
Mrs. Holbrook sat down at the desk, and wrote the following letter:

“My Dear Aunt:


“I am taking a liberty in sending you a boy in whom I am
interested, with the request that you will give him a home for a
few weeks, if he should be contented. I know you have a large
house and plenty of room. I think a young companion will help
enliven the house. Paul Parton (that is his name) will be happy
to be of service to you in any way. He understands horses, and
will drive you out any time, harness and unharness, read to you
or write for you, should you require it. I ask you to receive him
as a guest, for my sake, but to make him useful.
“I hope, my dear aunt, you are in comfortable health, and in a
condition to enjoy life, notwithstanding your advanced years.
“Your affectionate niece,
“Louisa Holbrook.”

“There,” said Mrs. Holbrook, after reading the letter to Paul, “I think
this will secure you an entrance into my aunt’s house, and should it
be read by the housekeeper, as is likely to be the case, it will tell her
nothing. Now we will go out and see about getting you a supply of
clothes.”
CHAPTER XXX.
PAUL’S RECEPTION AT ROCKVILLE.

Paul found himself unable to start for Rockville in the afternoon. He


was obliged to make arrangements at home for an indefinite
absence, and procure from the savings bank a supply of money for
current expenses, which he left in the hands of Mrs. Hogan. His
outfit was provided by Mrs. Holbrook, who made it as ample as if
Paul were the son of a well to do family, instead of a telegraph boy,
dependent upon his own exertions for a scanty living in a shabby
tenement house.
When his new patroness parted from him, she put a pocketbook into
his hands.
“This is not intended for remuneration,” she said, “for I shall pay the
telegraph company their usual charges. But I wish you to have
money to use, as you may require it.”
“Thank you,” said Paul. “You are very kind.”
“No, I am only considerate and just.”
“Have you any special directions to give, Mrs. Holbrook?”
“None beyond what I have already given. I must trust greatly to
your own good judgment and discretion. I am sure I can do so with
confidence, after the good report Mr. Cunningham has made of you.”
“Thank you; I will try to deserve your confidence.”
“You may write to me from time to time, when you have anything to
communicate.”
Paul promised to do so, and at nine o’clock took a train at the Grand
Central Depot for Rockville.
Fairly seated in the cars, he opened the pocketbook given him by
Mrs. Holbrook.
It contained three five dollar bills, and five dollars more in small
notes.
“Mrs. Holbrook is very liberal,” he reflected, complacently. “It will be
a pleasure to be in her service. I am fortunate in finding such good
friends.”
Paul was fortunate, but his good fortune was deserved. He always
tried to do his duty, was always courteous and obliging, and not
afraid to work. Such boys generally find friends. If any of my readers
think they are badly treated by their employers, and are poorly
provided with friends, let them consider whether they have taken
pains to deserve them.
Paul had never traveled, and two hours’ ride on the cars from New
York to Rockville, on a pleasant, sunny morning, interested him very
much.
He knew very little of the country, having spent most of his time in
the lower part of the city. He began to think the world was more
beautiful than he imagined.
Finally, the cars came to a stop; the conductor called out “Rockville!”
and Paul, with curious anticipation, stepped from the cars upon the
platform.
There was the usual crowd around the depot. On the platform stood
a man with a whip in his hand, evidently a driver.
“Carriage for the hotel, or any part of the village!” he called out.
Paul stepped up to him and inquired: “Can you tell me how far from
here Mrs. Granville lives?”
“The widder Granville?” queried the driver.
“I suppose so. She is an old lady.”
“Just so. Well, she lives about a mile away, on the Plainfield Road.”
“Can you take me there?”
“Well, as you ain’t over and above hefty, I guess the horses can
manage it,” added the driver, humorously. “Just hop on. We’ll be
starting directly.”
Paul got on the front seat with the driver, feeling disposed to a social
chat with that personage. There was but one other passenger, a
lady, who was bound for the hotel.
“Are you going to visit the widder?” asked the knight of the whip.
“I am expecting to stay at her house a little while.”
“I suppose you know her?”
“No, I have never seen her. I bring a letter from her niece in New
York, Mrs. Louisa Holbrook.”
“I’ve heard tell of her. She was down here a week last summer. I
guess she and the housekeeper couldn’t hitch hosses.”
“Mrs. Mercer is the housekeeper, I believe,” said Paul.
“Folks call her the housekeeper. I call her the boss,” said the driver.
“She’s got the old lady under her thumb, if all accounts are true.”
“Is she agreeable?”
Amos, the driver, emitted a short laugh. “Wait till you see her,” he
said, significantly.
“Do you think Mrs. Granville stands in dread of her?” asked Paul,
rather anxiously.
He was beginning to think his task might be a hard one.
“No; the old lady is easy goin’, that is all. If she ever got roused
she’d turn out to have a will of her own, or I’m greatly mistaken.
Bless your soul, Mrs. Mercer wouldn’t dare to go too far, for she
wants the old lady to leave her a good slice of her property. But she
gets round her in an underhand way. For instance, if her son wants
to go off anywhere, and it isn’t convenient for him to drive the old
lady out, Mrs. Mercer persuades her that she isn’t looking well, or
that the wind is cold and raw, and she’d better stay at home. I
shouldn’t be surprised if she’d get the old lady to make a will in her
favor.”
“I wonder what sort of a reception the housekeeper will give me,”
said Paul, thoughtfully.
“Very likely she will not be over glad to see you, especially when she
knows you’re a friend of Mrs. Holbrook. That lady saw through the
housekeeper’s little schemes, and did what she could to put a spoke
in her wheel—that’s why she hates her.”
“Well, all I can do is to hope for the best.”
“Be yer expectin’ to stay long?” asked Amos, curiously.
“That depends on whether the housekeeper will let me, from what
you tell me.”
“You’ll find it dreadful dull.”
“Perhaps so, but I’m going to offer to drive out Mrs. Granville, and
I’m willing to take care of the horse or horses, if she wants me to.”
“Frost will like that, for he’s lazy, and will be glad to get rid of the
work.”
“I suppose Frost is the housekeeper’s son.”
“Yes, that’s the one I mean.”
“What sort of a fellow is he?”
“Good enough for those who like him,” answered Amos, dryly. “I
don’t.”
“Does he resemble his mother?”
“He’s a chip of the old block, but not half so smart. His mother
thinks him an angel, and what she wants the old lady’s property for
is not so much for herself as for her son.”
“You think I won’t find him a pleasant companion, then?”
“I know you won’t.”
“Then I hope I shall like Mrs. Granville.”
“She’s a good old lady and awful rich. The only weak thing about her
is her trusting the housekeeper.”
“I should think she would prefer to have some relative with her.”
“She won’t get any to stay with her till she discharges Mrs. Mercer.
The housekeeper makes herself as disagreeable as possible to any
relation, because she’s afraid they will get an influence over the old
lady’s mind and interfere with her.”
“Perhaps she may think the same of me.”
“Like as not. You can tell better in a few days. But there’s the house,
the big white one on a little hill to the left.”
“It is a very nice one.”
“Oh, yes, it’s a good house. Why shouldn’t it be? The old lady’s got
plenty of money.”
“Have you any idea how much?”
“It’s risin’ a hundred thousand dollars, I heard Squire Taylor say
once. Squire Taylor is her lawyer, and he’s likely to know.”
“No wonder the housekeeper has designs upon it.”
“Just so—I shouldn’t mind if the old lady would leave me a slice. You
might put in a good word for me—Amos Drake—when you get
acquainted.”
“I’ll think of it,” answered Paul with a smile. “I owe you something
for all the information you’ve given me.”
“That’s all right. You seem a good sort of chap, and you’re welcome.”
Amos drew up in front of the house, and reined in the horses; while
Paul descended from the carriage.
“How much is the fare?” asked Number 91.
“Twenty cents.”
“That’s near enough,” said Paul, handing him a quarter.
“You’re a gentleman,” said Amos. “Now I’ll have a cigar when I get
back to the hotel.” Paul walked up the path to the front door of the
mansion and rang the bell.
In about a minute the door opened, and he found himself
confronting a tall, grim looking woman with thin face and figure, and
iron gray hair.
“Who are you, and what is your business?” she demanded in a chilly
tone. Paul had no doubt in his own mind that it was the
housekeeper.
“My name is Paul Parton, from New York, and I have a letter for Mrs.
Granville.”
“You can give me the letter.”
“Thank you, but I would prefer to give it to Mrs. Granville——”
“Humph! Are you one of her relations?”
“No, but I come from Mrs. Holbrook, her niece.”
“Oh,” said the housekeeper, grimly. “Well, I don’t think you can see
Mrs. Granville; she’s got a headache, and can’t be disturbed.”
CHAPTER XXXI.
A DEFEAT FOR THE HOUSEKEEPER.

The housekeeper held the door half way open, and evidently meant
to prevent Paul from entering. If he had been less determined, or
more easily abashed, he would have given up his purpose. But
Number 91 had a will of his own.
“I don’t accept a dismissal from you, madam,” he said, eying Mrs.
Mercer with a steady glance. “I demand to see Mrs. Granville.”
“Hoity toity! Who are you, I’d like to know?” demanded the
housekeeper, amazed and exasperated.
“A visitor to Mrs. Granville,” answered Paul; “you, I suppose, are a
servant.”
“Do you dare to call me a servant, you impudent boy?” answered
Mrs. Mercer, raising her voice.
“What are you, then?” asked Paul, calmly.
“I am Mrs. Mercer, the housekeeper, I’d have you to know.”
“So I suppose, and Mrs. Granville is your employer. By what right do
you dare to send away her visitors?”
Mrs. Mercer was quite unused to being defied so boldly, and she
could hardly express her indignation.
“Well, I never heard of such impudence!” she ejaculated.
In her anger she would have closed the door, but just at that
moment a voice was heard from the floor above—the voice of Mrs.
Granville, who had been attracted by the housekeeper’s loud tones.
“What is all this, Mrs. Mercer?” she asked, in a tone of authority.
“It’s a boy who wants to force his way in, ma’am,” said Mrs. Mercer,
in a sulky tone.
“What boy is it?” asked her mistress.
Paul answered this question himself.
“I come from New York with a letter from your niece, Mrs. Holbrook,”
he said.
“Then come in at once,” said the old lady, in an imperative tone.
“Why did you not admit him at once?”
“I didn’t know,” answered the housekeeper, confused.
“I beg your pardon,” said Paul, “I told you this, and you said Mrs.
Granville had a headache, and would not see me.”
“What do you mean by this misrepresentation, Mrs. Mercer?”
demanded the old lady, sternly.
“I offered to take the letter up to you,” said Mrs. Mercer, a little
alarmed at the evident anger of her mistress.
“When Mrs. Granville reads the letter she will understand why I
preferred to hand it to her myself.”
“Why did you say I had a headache? Why do you presume to send
away my visitors, Mrs. Mercer?” demanded the old lady, thoroughly
aroused.
“I meant it for the best,” said the woman, sulkily.
“Never presume so far again. Now, young man, come up and let me
see you.”
Paul passed the discomfited housekeeper, and, going upstairs,
followed the old lady into a pleasant sitting room.
“I am sorry to have been the means of disturbing you,” said Paul,
politely. “Mrs. Holbrook sends you this letter, and wishes me to give
you her love.”
“You are a nice looking boy,” said the old lady, letting her glance rest
approvingly on Number 91. “I hope Louisa is well.”
“Very well, thank you.”
She put on her glasses, and read the letter.
“So you are Paul Parton,” she said, as she folded up the letter.
“Yes, madam.”
“A New York boy?”
“Yes, madam.”
“I am afraid you will find it dull here.”
“O no, Mrs. Granville, I am sure I shall like the country, for a while at
least.”
“Do you know how to drive?”
“Oh, yes; I am used to horses.”
“On the whole, I am glad Louisa sent you down here. Frost Mercer,
who usually drives me, has been getting lazy of late, and makes
excuses when I want to go out.”
“I won’t do that, Mrs. Granville. I shall be only too glad to go.”
“You are sure you won’t upset me?”
“I don’t believe I shall,” answered Paul, smiling. “I don’t care about
being upset myself.”
“I think, on the whole, I shall like to have a boy about,” said the old
lady, thoughtfully.
“I am afraid Mrs. Mercer might object to me.”
“I am the mistress of the house. Mrs. Mercer is only the
housekeeper,” said the old lady, with an unwonted assumption of
dignity. “Please ring the bell, Paul.”
Paul did so.
Presently the housekeeper entered in answer to the summons. She
looked askance at Paul.
“Mrs. Mercer,” said her mistress, “you will prepare a room for this
young gentleman. He will remain here, for the present.”
Mrs. Mercer looked disagreeably surprised.
“Perhaps you had better read this letter from my niece, Mrs.
Holbrook, as it will save explanations.”
The housekeeper read the letter, and her thin lips tightened with
displeasure.
“There is no need of your getting a boy to drive you around, ma’am,”
she said. “My son is perfectly able to do it.”
“Your son is very apt to be engaged when I want to drive out,”
returned the old lady, dryly.
“I will see that it don’t happen again,” said the housekeeper, anxious
to keep Paul out of the house.
“There is no occasion for that. Mind, I don’t blame your son. Paul
here will have nothing else to do, and can drive me as well as not.
Besides, he will read to me, and spare my eyes.”
“Frost would be willing to read to you.”
Mrs. Granville smiled.
“I don’t think reading aloud is one of your son’s accomplishments,”
she said. “His voice is not exactly musical.”
This was certainly true, for Frost Mercer had a voice deep and
croaking, like a frog’s.
“I am sorry you are so prejudiced against my poor boy,” said Mrs.
Mercer, mortified and displeased.
“You are a foolish woman, Mrs. Mercer. I am only going to make it
easier for Frost, and give this young gentleman something to do.
Paul, you may go with Mrs. Mercer, and take possession of your
room. Go where you please, till half past twelve, our dinner hour.
After dinner, I may take a drive.”
“You’d better get your life insured, then, ma’am,” muttered Mrs.
Mercer. “Boys ain’t to be trusted with horses.”
“Is your horse very lively or skittish?” asked Paul.
“No,” answered Mrs. Granville. “He is very gentle and tractable.”
“Then I don’t think there is any need of insuring your life, Mrs.
Granville.”
“I wouldn’t ride out with you,” said the housekeeper, spitefully.
“Perhaps you will think better of me after a while, Mrs. Mercer,” said
Paul, good naturedly.
The housekeeper closed her lips firmly and shook her head.
“I’ve made one enemy, that’s clear,” said Paul to himself—“probably
two, for the housekeeper’s son isn’t likely to be my friend.”
Mrs. Mercer led the way to a small room on the next floor.
“You can go in there,” she said, ungraciously.
“Thank you,” said Paul.
It occurred to him to wonder why so small a room should be
assigned him, while there seemed to be plenty of larger ones. In the
arrangement of the room, however, there was nothing to be desired.
Everything was neat and comfortable. To Paul, accustomed to a
shabby tenement house, it seemed luxurious, and he was disposed
to enjoy it for the time, be it long or short.
CHAPTER XXXII.
FROST MERCER IS CONTRARY.

Mrs. Mercer, the housekeeper, was seriously annoyed by the


appearance of Paul upon the scene. For years she and her son had
had charge of Mrs. Granville’s affairs, and they had taken care to
turn the charge to profitable account. The wages which each
received formed only a part of this advantage. They bought
everything for the house, and levied tribute from every tradesman as
a compensation for turning the trade in his direction. The result was
that Mrs. Granville, without being aware of it, paid a larger price
than any one else for what articles she purchased, the storekeepers
and others compensating themselves in this way for the percentage
they had to pay the housekeeper and her son.
It is for this reason that Mrs. Mercer never cared to have any visitor
in the house. She feared her dishonesty might be found out. She
was especially afraid of any one sent by Mrs. Holbrook, who during
her stay had been bold enough to interfere with the housekeeper.
When she had ushered Paul into his chamber, she went out to the
barn, where she found her son, not at work, but sitting on an old
rocking chair which he had carried out for his convenience, smoking.
“Well, mother, what’s up?” he asked, on Mrs. Mercer’s entrance.
“We have got a visitor,” answered his mother, abruptly.
“We?”
“Well, Mrs. Granville.”
“Who is it—the Holbrook woman?” queried Frost, taking his pipe
from his mouth.
“No, but it’s some one she sent.”
“Man, woman, or child?”
“It’s a boy—about sixteen, he looks.”
“What on earth should she send a boy for?” asked Frost, in surprise.
“To make mischief, I reckon.”
“What can a boy do?”
“I read the woman’s letter. She sends him to take your place.”
“What?” exclaimed Frost, in some alarm.
“Why, she hints that he can drive out the old lady, read to her, and
make himself generally useful.”
“That will make it lighter for me,” said Frost, who was lazy, “if he
does the driving.”
“Yes, but don’t you see what a chance he will have to work himself
into the confidence of the old woman?”
“What sort of a boy does he seem to be?”
“I’ve only seen him five minutes, but I’ve found out that he is
impudent. When I didn’t want to let him in, he actually defied me—
asked by what right I sent away Mrs. Granville’s visitors.”
“So he is inclined to make trouble, is he?”
“Yes.”
“Suppose I give him a thrashing?”
“It won’t do, Frost.”
“You think I am not a match for a boy of sixteen?”
“No, not that; but we must not be imprudent. Better get rid of him
by underhand means.”
“Such as what?”
“I don’t know yet; I will consider. Meantime I thought I would come
out and put you on your guard.”
“All right, mother. I guess we can checkmate the young meddler. Is
he in the house?”
“Yes; I’ve put him in the small room.”
“Next to mine?”
“Yes.”
“All right; I’ll look him over at dinner time.”
In this, however, Frost counted without his host. Mrs. Granville was
accustomed to have her meals brought up to her own room. Today
she expressed the wish that Paul should dine with her. This
displeased the housekeeper.
“I suppose Frost and I are not good enough company for the young
man,” she said, sulkily.
“My good Mercer, you are much mistaken,” said Mrs. Granville,
soothingly. “I thought he would be company for me; besides, it will
give me a chance to ask him some questions about Louisa.”
“Very well, ma’am,” said the housekeeper, but she didn’t look
satisfied.
“What do you think, Frost?” she said, as she went downstairs.
“Master Paul—that’s his name—is to dine with the old woman
upstairs. I suppose he is too good to eat with us.”
“I don’t know as I care much, mother; I don’t want his company.”
“Nor I, for the matter of that, but it’s putting this young popinjay
over our heads. They’ll be getting thick together, and the boy will be
pulling our noses out of joint.”
“If he does, I’ll pull his out of joint,” muttered Frost.
“Bide your time, Frost. We’ll put our heads together and see if we
can’t send him packing.”
After dinner Mrs. Granville expressed a desire, as it was a fine day,
to go out for a drive.
“I shall be very happy to drive you,” said Paul, cheerfully.
“You are sure you can drive?” asked the old lady, anxiously.
“I should smile,” Paul was about to reply, when it occurred to him
that this form of expression did not sound exactly proper. “I am used
to driving, ma’am,” he said, instead.
“Then about two o’clock you may go out to the barn and ask Frost to
harness up.”
“O, I’ll do that, Mrs. Granville.”
When he went out to the barn, he found Frost Mercer sitting at his
ease, engaged at his favorite business of smoking a pipe.
“I suppose you are Frost,” he said, with a smile.
“I am Mr. Mercer,” answered Frost, in a forbidding tone.
“I beg your pardon. I will call you Mr. Mercer, if you prefer it. I am
Paul Parton.”
“I don’t know as that concerns me,” said Frost, staring at Paul in an
unfriendly manner.
“It is just as well you should know my name, as I am living in the
house,” said Paul, independently. “Mrs. Granville wishes me to drive
her out If you will show me what carriage she uses and so forth, I
will harness up.”
This was, on the whole, satisfactory to Frost, as he would not have
the trouble of harnessing.
“There’s the carriage,” he said, “and there’s the harness. You can
find the horses if you use your eyes.”
“Thank you; you are very obliging,” said Paul, with a little touch of
sarcasm.
“The old lady doesn’t seem to value her neck,” observed Frost.
“What makes you think so?”
“In letting you drive her.”
“O, that’s it. I think I shall bring her back safe.”
“I don’t know about that. You’re a city boy, ain’t you?”
“Yes.”
“What chance have you had to learn about horses?”
“I know a little about them.”
“Well, I wash my hands of it. If the team is upset, Mrs. Granville will
have herself to blame for it.”
“I don’t think you need to worry,” said Paul. “I’ll promise to bring her
back safe.”
He set to work to harness the horses. Frost surveyed him with
critical eyes, but he could see no evidence of ignorance on Paul’s
part. He did his work quickly and skillfully, and then, opening wide
the barn doors, led the horses out. Then he jumped into the carriage
and was about to drive to the house.
“Come back and shut the barn doors!” called out Frost from his
rocking chair.
Paul turned and looked back.
“I don’t think it will do you any harm to do that yourself,” he said, “if
you can spare the time from smoking.”
“Hey, what’s that?” demanded Frost, angrily.
“I don’t think it will be necessary to repeat it,” said Paul, coolly; “you
heard me.”
“None of yer sass, boy!” said Frost, wrathfully.
Paul did not deign to answer him. He saw that Frost did not intend
to be pleased with anything he did, and that there was no use in
trying to conciliate.
“I hate that boy!” reflected Frost, following Paul with a venomous
expression. “My mother is perfectly right. He’s a dangerous visitor.
We must get rid of him one way or another.”
Paul drove around to the front of the house and found Mrs. Granville
ready at the door—with the housekeeper at her side.
“I do hope you won’t meet with an accident,” said Mrs. Mercer with
an air of deep solicitude. “Frost is ready to drive you. It will be safer.”
“Thank you, my good Mercer, but Paul tells me he understands
driving.”
“I shouldn’t mind if she broke her neck,” muttered the housekeeper,
following the carriage with her eyes, “if I only knew it was all right
now in her will.”
CHAPTER XXXIII.
A STARTLING DISCOVERY.

Paul proved a satisfactory driver, and the old lady’s fears were soon
dissipated.
“You drive better than Frost Mercer,” she said in a tone of
satisfaction.
“I am glad to hear you say so, Mrs. Granville,” said Paul, well
pleased.
“Frost nearly upset me one day. I don’t think he is generally
intemperate, but I suspect he had been drinking something that
day.”
“He doesn’t seem to like me,” Paul ventured to say.
“What makes you think so?”
Hereupon Paul related his reception when he went to the barn to
harness the horses.
Mrs. Granville listened thoughtfully.
“He should not have acted so,” she said; “I presume he didn’t like
the idea of being superseded.”
“Has he been with you a long time?”
“He and his mother have been in my service for a long time. I think
Mrs. Mercer is of a jealous disposition. She never wishes me to have
any one here, but she is very faithful and loyal.”
“I wonder if that is the case,” thought Paul. The housekeeper did not
seem to him like one who would be unselfishly devoted to the
service of any one.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookmasss.com

You might also like