Raspberry PI Computer Vision Programming 1st Edition Pajankar Ebook All Chapters PDF
Raspberry PI Computer Vision Programming 1st Edition Pajankar Ebook All Chapters PDF
com
https://ebookname.com/product/raspberry-pi-computer-vision-
programming-1st-edition-pajankar/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/raspberry-pi-gaming-2nd-edition-
design-create-and-play-all-kinds-of-video-games-on-your-
raspberry-pi-computer-shea-silverman/
https://ebookname.com/product/raspberry-pi-robotics-
essentials-1st-edition-grimmett/
https://ebookname.com/product/raspberry-pi-led-blueprints-1st-
edition-kurniawan/
https://ebookname.com/product/new-practical-chinese-reader-
vol-1-3rd-ed-3rd-edition-liu-xun/
The Fundamentals of Interior Architecture First Edition
Naomi House
https://ebookname.com/product/the-fundamentals-of-interior-
architecture-first-edition-naomi-house/
https://ebookname.com/product/environmental-impact-assessment-
methodologies-2nd-edition-y-anjaneyulu/
https://ebookname.com/product/operator-theory-functional-
analysis-and-applications-operator-theory-advances-and-
applications-282-1st-ed-2021-edition-m-amelia-bastos-editor/
https://ebookname.com/product/measure-and-integration-1st-
edition-leonard-f-richardson/
https://ebookname.com/product/a-treatise-on-universal-algebra-
with-applications-alfred-north-whitehead/
Toward Better Infrastructure Conditions Constraints and
Opportunities in Financing Public Private Partnerships
1st Edition Riham Shendy
https://ebookname.com/product/toward-better-infrastructure-
conditions-constraints-and-opportunities-in-financing-public-
private-partnerships-1st-edition-riham-shendy/
Raspberry Pi Computer Vision
Programming
Ashwin Pajankar
BIRMINGHAM - MUMBAI
Raspberry Pi Computer Vision Programming
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78439-828-6
www.packtpub.com
Credits
Reviewers Proofreaders
James Allen Stephen Copestake
Arush Kakkar Safis Editing
Luis A. Larco
Fred Stakem Indexer
Priya Sane
Aldo Vargas
Graphics
Commissioning Editor
Sheetal Aute
Amit Ghodake
Disha Haria
Acquisition Editor
Llewellyn Rozario Production Coordinator
Shantanu Zagade
Technical Editor
Edwin Moses
Copy Editors
Puja Lalwani
Vedangi Narvekar
About the Author
James Allen is a computer scientist and a teacher whose experiences run the gamut
from web and application programming to graphic design and sound engineering.
If a form of media can be produced on a computer, there is a very good chance that
he has dabbled in something along those lines.
Aldo loves to design, build, and control drones at work and during his free time.
He also enjoys scuba diving, skydiving, and riding motorcycles. If you're interested
in knowing more about his work, you can visit http://aldux.net.
www.PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.com
and as a print book customer, you are entitled to a discount on the eBook copy. Get in
touch with us at service@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign
up for a range of free newsletters and receive exclusive discounts and offers on Packt
books and eBooks.
TM
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser
[i]
Table of Contents
[ ii ]
Table of Contents
[ iii ]
Table of Contents
[ iv ]
Preface
Raspberry Pi was developed as a low-cost single-board computer with the
intention of promoting computer science education in schools. It also represents
a welcome return to a simple and fun yet effective way to learn computer science
and programming.
You can use Raspberry Pi to learn and implement concepts in computer vision.
With a $35 Raspberry Pi computer and a USB webcam, anyone can afford to become
a pro in computer vision in no time and build a real-life computer vision application
to impress friends and colleagues.
Chapter 2, Working with Images, Webcams, and GUI, teaches you how to work with
images, videos, and various cameras.
Chapter 3, Basic Image Processing, explores arithmetic and logical operations on images.
Chapter 5, Let's Make Some Noise, teaches the basics of noise in digital images and
low-pass filters. It also discussed their usage in the removal of noise from images.
Chapter 6, Edges, Circles, and Lines' Detection, explores high-pass filters and their
applications. It also explores the detection of features like edges, circles, and lines.
[v]
Preface
Chapter 7, Image Restoration, Quantization, and Depth Map, explores image restoration
by inpainting. It also teaches image segmentation, quantization, and depth maps.
[ vi ]
Preface
Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.
Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "
We are going to learn about the linspace() function now."
New terms and important words are shown in bold. Words that you see on the
screen, for example, in menus or dialog boxes, appear in the text like this: "Go to
Enable Boot to Desktop/Scratch | Desktop."
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it helps
us develop titles that you will really get the most out of.
[ vii ]
Preface
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you could report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the Errata Submission Form
link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our website or added
to any list of existing errata under the Errata section of that title.
[ viii ]
Preface
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all
media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
We appreciate your help in protecting our authors and our ability to bring you
valuable content.
Questions
If you have a problem with any aspect of this book, you can contact us at
questions@packtpub.com, and we will do our best to address the problem.
[ ix ]
Introduction to Computer
Vision and Raspberry Pi
OpenCV is a simple yet powerful tool for any computer vision enthusiast. One can
learn computer vision in an easy way by writing OpenCV programs in Python.
The Raspberry Pi family of single-board computers uses Python as the preferred
development platform. Using a Raspberry Pi computer and Python for OpenCV
programming is one of the best ways to start your journey into the world of
computer vision. We will commence our journey with this chapter by getting
ourselves familiar with the following topics:
• Computer vision
• OpenCV
• Raspberry Pi
• Setting up Raspberry Pi
• Installing OpenCV and its dependencies
• NumPy basics
Computer vision
Computer vision is an area of computer science, mathematics, and electrical
engineering. It includes ways to acquire, process, analyze, and understand images
and videos from the real world in order to mimic human vision. Also, unlike
human vision, computer vision can also be used to analyze and process depth
and infrared images.
[1]
Introduction to Computer Vision and Raspberry Pi
Computer vision is also concerned with the theory of information extraction from
images and videos. A computer vision system can accept different forms of data as
an input, including, but not limited to, images, image sequences, and videos that can
be streamed from multiple sources to further process and extract useful information
from for decision making.
Artificial intelligence and computer vision share many topics, such as image
processing, pattern recognition, and machine learning techniques, as shown
in the following diagram:
Don't worry about this jargon as of now. We will explore most of these concepts in
detail in the later chapters.
OpenCV
OpenCV (Open Source ComputerVision) is a library of programming functions
for computer vision. It was initially developed by the Intel Russia research center
in Nizhny Novgorod, and it is currently maintained by Itseez.
[2]
Chapter 1
OpenCV was released under a Berkeley Software Distribution (BSD) license and
hence, it is free for both academic and commercial use. It has interfaces for popular
programming languages, such as C/C++, Python, and Java, and it runs on a variety
of operating systems including Windows, Android, and Unix-like operating systems.
OpenCV was initially an Intel Research initiative to develop tools to analyze images.
In August 2012, support for OpenCV was taken over by a nonprofit foundation,
OpenCV.org, which is currently developing it further. It also maintains a developer
and user site for OpenCV.
[3]
Introduction to Computer Vision and Raspberry Pi
Popular single-board computers available in the market include, but are not limited
to, Raspberry Pi, Banana Pi, BeagleBone, and Cubieboard.
Raspberry Pi
Raspberry Pi is a series of low-cost, palm-sized, single-board computers developed
by the Raspberry Pi Foundation in the UK. The intention behind the creation of
Raspberry Pi was to promote the teaching of basic computer skills in schools, and
the former serves this purpose well. Raspberry Pi has expanded its footprint well
beyond its intended purpose by penetrating into the market of embedded systems
and research.
As of now, there are five major models of Raspberry Pi, which are as follows:
• Model A
• Model A+ (currently in production and available for purchase)
• Model B (available for purchase but not in production)
[4]
Chapter 1
The Raspberry Pi Foundation provides Debian and Arch variants and Linux
ARM distributions for download. Python is the main programming platform and
languages like C, C++, Java, Perl, and Ruby can be used to program Raspberry Pi.
We will use Raspberry Pi B+ for our Computer Vision learning. However, these
examples can also be executed on other Raspberry Pi Models.
Component Specification
CPU 700 MHz ARM1176JZF-S core (ARM11 family, ARM v6 instruction set)
GPU Broadcom VideoCore IV @250 MHz
Memory 512 MB SDRAM (shared with GPU—the limit of memory used by GPU
can be set using raspi-config utility)
USB 2.0 ports 4
Video output HDMI, composite video (PAL and NTSC) via 3.5 mm TRRS jack shared
with audio out (you need to use converters for VGA type displays)
Audio output Analog via 3.5 mm phone jack; digital via HDMI port
Onboard microSD
storage
Networking 10/100 Mbit/s Fast Ethernet, no onboard Wi-Fi or Bluetooth
Power 600 mA (3 W), 5 V via http://en.wikipedia.org/wiki/MicroUSB
or GPIO header (using MicroUSB for power is recommended)
Operating systems
Raspberry Pi primarily uses Unix-like, Linux-kernel-based operating systems,
like the variants of Debian and Fedora.
The Raspberry Pi models A, A+, B, and B+ are based on the ARM11 family chip,
which runs on the ARM v6 instruction set. The ARM v6 instruction set does not
support Ubuntu and Windows.
[5]
Introduction to Computer Vision and Raspberry Pi
However, the recently launched Raspberry Pi 2 is based on ARM Cortex A7, which
is capable of running both Windows 10 and Ubuntu (Snappy Core). The following
operating systems are officially supported by all the models of Raspberry Pi and are
available for download at the download page:
• OpenELEC
• Pidora (Fedora Remix)
• RASPBMC
• RISC OS
• Raspbian—we will use this with a Raspberry Pi B+ throughout this book.
Raspbian
Raspbian is an unofficial variant of Debian Wheezy armhf (ARM hard float)
that is compiled for hard float code that will run on Raspberry Pi computers.
It is a free operating system based on Debian that is optimized for the Raspberry Pi
hardware. Raspbian is more than a pure OS. It comes with over 35,000 packages
and precompiled software for Raspberry Pi.
[6]
Chapter 1
[7]
Introduction to Computer Vision and Raspberry Pi
• Raspberry Pi B+
• A micro USB power supply
Considering that we are going for a bit of power-intensive usage for our Pi
B+ (like connecting picamera), a 5V 2A power supply is recommended.
• A standard USB keyboard
• A microSD card and a microSD to SD card converter
We need a microSD card of minimum 4 GB.
• A USB mouse
• A monitor
You can either use an HDMI monitor or a standard VGA monitor.
• A monitor connection cable and a converter
If you are using an HDMI Monitor, then an HDMI cable is sufficient.
If you are using a VGA monitor, then you need to use an HDMI to VGA
converter with a VGA cable. A few special changes should be made to
/boot/config.txt if you're using a VGA monitor, which will be
explained in the next section.
• A Windows computer with a microSD card reader and a wired
Internet connection
[8]
Chapter 1
[9]
Introduction to Computer Vision and Raspberry Pi
7. If you have an HDMI monitor, then please skip this step. This additional
step is required only if you are planning to use a VGA monitor in place
of an HDMI monitor.
8. Browse the SD card. It will appear as a drive labeled boot in the Windows
file explorer. Open the config.txt file from the explorer. You will have to
edit the file in the following manner to enable a proper display on your
VGA monitor
°° Change #disable_overscan=1 to disable_overscan=1
°° Change #hdmi_force_hotplug=1 to hdmi_force_hotplug=1
°° Change #hdmi_group=1 to hdmi_group=2
°° Change #hdmi_mode=1 to hdmi_mode=16
°° Change #hdmi_drive=2 to hdmi_drive=2
°° Change #config_hdmi_boost=4 to config_hdmi_boost=4
By default, the commented options (which have # at the beginning) are disabled.
We will enable these options by uncommenting their respective lines by removing
# at the beginning of these commented lines.
[ 10 ]
Chapter 1
If you are using Linux or Mac OS, then you will find the instructions
to install the OS on your Micro SD card for these operating systems
at https://www.raspberrypi.org/documentation/
installation/installing-images/.
1. Insert the microSD card into the microSD card slot of Pi.
2. Connect the Pi to the HDMI monitor. In case you have connected the VGA
monitor, connect it using the HDMI to VGA converter.
3. Connect the USB mouse and USB keyboard.
4. Connect the Pi to the power supply with a micro USB power cable. Make
sure that the power is switched off at this point.
5. Check all the connections once and then switch on the power supply of Pi.
At this stage, your Pi will start booting up. You will see a green light blinking on the
Pi board. It means that it's working! Now, there are a few more things that you need
to do before you can really start using your Pi. Once it boots up, it will show the
raspi-config menu, as follows:
[ 11 ]
Introduction to Computer Vision and Raspberry Pi
You will have to use the arrow keys and the Enter key to select
options in the text-based menu.
If you do not enable this option, you will be asked for the
username and password every time you boot. The default
username is pi and the password is raspberry. Once you enter
the username and password, the command prompt will appear.
The default shell of Raspbian is bash. You can confirm it by typing
this in the following command:
echo $SHELL
This option decides how much RAM is used by the Graphic Processor Unit (GPU).
The more the RAM is allocated to the GPU, the more will the processing of intensive
graphics be done. 64 MB is a good value for most graphics-related purposes.
You can always invoke this tool from the command prompt with the following
command and change the settings:
sudo raspi-config
[ 12 ]
Chapter 1
This command synchronizes the package list from the source. Indexes of all
the packages are refreshed. This command must be issued before we issue
the upgrade command.
°° sudo apt-get upgrade
This will install the newest versions of the already installed software.
Obsolete packages/utilities are not removed automatically. If the
software is up to date, then it's left as it is.
°° sudo rpi-update
This command is used to upgrade the firmware. The kernel and firmware
are installed as a Debian package, and hence, we will also get the updates.
These packages are updated infrequently after extensive testing.
[ 13 ]
Introduction to Computer Vision and Raspberry Pi
5. Now, we will need to install a few necessary packages and dependencies for
OpenCV. Following is a list of packages we need to install. You just need to
connect Pi to the Internet and type in sudo apt-get install <package-
name>, where <package-name> is one of following packages:
[ 14 ]
Chapter 1
For example, if you want to install x264, you have to type sudo apt-get
install x264. This will install the necessary package. Similarly, you can
install all of the aforementioned packages in like manner. If a package is
already installed on Pi, it will show the following message:
pi@pi02 ~ $ sudo apt-get install x264
Reading package lists... Done
Building dependency tree
Reading state information... Done
x264 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not
upgraded.
In such cases, don't worry. The package you wanted to install has already
been installed, and it is up to date. Just proceed with the installation of all
the other packages in the list one-by-one.
This is the easiest way to install OpenCV for Python. However, there is a
problem with this. Raspbian repositories may not always contain the latest
version of OpenCV. For example, at the time of writing this book, Raspbian
repository contains version 2.4.1, while the latest OpenCV version is 2.4.10.
With respect to Python API, the latest version will always contain much
better support and more functionality.
Another method is to compile OpenCV from the source, which I will not
recommend for beginners as it's a bit complex and it will take a lot of time.
This will show us the version of OpenCV that was installed on Pi, which, in our case
is 2.4.1.
[ 15 ]
Introduction to Computer Vision and Raspberry Pi
NumPy
NumPy is a fundamental package that can be used to scientifically compute with
Python. It is a matrix library for linear algebra. NumPy can also be used as an
efficient multidimensional container of generic data. Arbitrary data types can be
defined and used. NumPy is an extension of the Python programming language.
It adds support for large multidimensional arrays and matrices, along with a large
library of high-level mathematical functions that can be used to operate on these
arrays. We will use NumPy arrays throughout this book to represent images and
carry out complex mathematical operations. NumPy comes with many inbuilt
functions for all of these operations. So, we do not have to worry about basic array
operations. We can directly focus on the concepts and code for computer vision. All
the OpenCV array structures are converted to and from NumPy arrays. So, whatever
operations you perform in NumPy, you can combine NumPy with OpenCV.
We will use NumPy with OpenCV a lot in this book. Let's start with some simple
example programs that will demonstrate the real power of NumPy.
Array creation
Let's see some examples on array creation. The array() method is used very
frequently in this book. There are many ways to create different types of arrays.
We will explore these ways as and when they are needed in this book. Follow
these commands for array creation:
>>> import numpy as np
>>> x=np.array([1,2,3])
>>> x
array([1, 2, 3])
>>> y=arange(10)
>>> y
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
[ 16 ]
Discovering Diverse Content Through
Random Scribd Documents
the longboat, with vessels for water, if any could be found. I desired
his leave to go with them, that I might see the country and make
what discoveries I could. When we came to land we saw no river or
spring, nor any sign of inhabitants. Our men therefore wandered on
the shore to find out some fresh water near the sea, and I walked
alone about a mile on the other side, where I observed the country
all barren and rocky. I now began to be weary, and seeing nothing
to entertain my curiosity, I returned gently down towards the creek;
and the sea being full in my view, I saw our men already got into
the boat and rowing for life to the ship. I was going to holla after
them, although it had been to little purpose, when I observed a
huge creature walking after them in the sea, as fast as he could; he
waded not much deeper than his knees, and took prodigious strides.
But our men had the start of him half a league, and the sea
thereabouts being full of sharp-pointed rocks, the monster was not
able to overtake the boat. This I was afterwards told, for I durst not
stay to see the issue of that adventure, but ran as fast as I could the
way I first went, and then climbed up a steep hill which gave me
some prospect of the country. I found it fully cultivated; but that
which first surprised me was the length of the grass, which, in those
grounds that seemed to be kept for hay, was above twenty feet
high.
I fell into a highroad, for so I took it to be, though it served to the
inhabitants only as a footpath through a field of barley. Here I
walked on for some time, but could see little on either side, it being
now near harvest, and the corn rising at least forty feet. I was an
hour walking to the end of this field, which was fenced in with a
hedge of at least one hundred and twenty feet high, and the trees
so lofty that I could make no computation of their altitude. There
was a stile to pass from this field into the next. It had four steps,
and a stone to cross over when you came to the uppermost. It was
impossible for me to climb this stile, because every step was six feet
high, and the upper stone above twenty. I was endeavoring to find
some gap in the hedge, when I discovered one of the inhabitants in
the next field advancing towards the stile, of the same size with him
whom I saw in the sea pursuing our boat. He appeared as tall as an
ordinary spire steeple, and took about ten yards at every stride, as
near as I could guess. I was struck with the utmost fear and
astonishment, and ran to hide myself in the corn, whence I saw him
at the top of the stile looking back into the next field on the right
hand, and heard him call in a voice many degrees louder than a
speaking trumpet; but the noise was so high in the air, that at first I
certainly thought it was thunder. Whereupon seven monsters like
himself came towards him with reaping hooks in their hands, each
hook about the largeness of six scythes. These people were not so
well clad as the first, whose servants or laborers they seemed to be;
for, upon some words he spoke, they went to reap the corn in the
field where I lay. I kept from them at as great a distance as I could,
but was forced to move with extreme difficulty, for the stalks of the
corn were sometimes not above a foot distant, so that I could hardly
squeeze my body betwixt them. However, I made a shift to go
forward till I came to a part of the field where the corn had been laid
by the rain and wind. Here it was impossible for me to advance a
step; for the stalks were so interwoven that I could not creep
through, and the beards of the fallen ears so strong and pointed that
they pierced through my clothes into my flesh. At the same time I
heard the reapers not above a hundred yards behind me. Being
quite dispirited with toil, and wholly overcome by grief and despair, I
lay down between two ridges, and heartily wished I might there end
my days. I bemoaned my desolate widow and fatherless children. I
lamented my own folly and willfulness in attempting a second
voyage against the advice of all my friends and relations. In this
terrible agitation of mind I could not forbear thinking of Lilliput,
whose inhabitants looked upon me as the greatest prodigy that ever
appeared in the world; where I was able to draw an imperial fleet in
my hand, and perform those other actions which will be recorded
forever in the chronicles of that empire, while posterity shall hardly
believe them, although attested by millions. I reflected what a
mortification it must prove to me to appear as inconsiderable in this
nation as one single Lilliputian would be among us. But this I
conceived was to be the least of my misfortunes; for, as human
creatures are observed to be more savage and cruel in proportion to
their bulk, what could I expect but to be a morsel in the mouth of
the first among these enormous barbarians that should happen to
seize me? Undoubtedly philosophers are in the right when they tell
us that nothing is great or little otherwise than by comparison. It
might have pleased fortune to let the Lilliputians find some nation
where the people were as diminutive with respect to them, as they
were to me. And who knows but that even this prodigious race of
mortals might be equally overmatched in some distant part of the
world, whereof we have yet no discovery? Scared and confounded
as I was, I could not forbear going on with these reflections, when
one of the reapers approaching within ten yards of the ridge where I
lay, made me apprehend that with the next step I should be
squashed to death under his foot, or cut in two with his reaping
hook. And therefore when he was again about to move, I screamed
as loud as fear could make me; whereupon the huge creature trod
short, and looking round about under him for some time, at last
espied me as I lay on the ground. He considered awhile, with the
caution of one who endeavors to lay hold on a small dangerous
animal in such a manner that it shall not be able either to scratch or
to bite him, as I myself have sometimes done with a weasel in
England. At length he ventured to take me up behind, by the middle,
between his forefinger and thumb, and brought me within three
yards of his eyes, that he might behold my shape more perfectly. I
guessed his meaning, and my good fortune gave me so much
presence of mind, that I resolved not to struggle in the least as he
held me in the air above sixty feet from the ground, although he
grievously pinched my sides, for fear I should slip through his
fingers. All I ventured was to raise my eyes towards the sun and
place my hands together in a supplicating posture, and to speak
some words in a humble melancholy tone, suitable to the condition I
then was in; for I apprehended every moment that he would dash
me against the ground, as we usually do any little hateful animal
which we have a mind to destroy. But my good star would have it,
that he appeared pleased with my voice and gestures, and began to
look upon me as a curiosity, much wondering to hear me pronounce
articulate words, although he could not understand them. In the
meantime I was not able to forbear groaning and shedding tears,
and turning my head towards my sides; letting him know, as well as
I could, how cruelly I was hurt by the pressure of his thumb and
finger. He seemed to apprehend my meaning; for, lifting up the
lappet of his coat, he put me gently into it, and immediately ran
along with me to his master, who was a substantial farmer, and the
same person I had first seen in the field.
The farmer having (as I supposed by their talk) received such an
account of me as his servant could give him, took a piece of a small
straw, about the size of a walking staff, and therewith lifted up the
lappets of my coat, which, it seems, he thought to be some kind of
covering that nature had given me. He blew my hair aside to take a
better view of my face. He called his hands about him, and asked
them, as I afterwards learned, whether they had ever seen in the
fields any little creature that resembled me. He then placed me
softly on the ground upon all fours, but I got immediately up, and
walked slowly backwards and forwards, to let those people see I had
no intent to run away. They all sat down in a circle about me, the
better to observe my motions. I pulled off my hat, and made a low
bow towards the farmer. I fell on my knees, and lifted up my hands
and eyes, and spoke several words as loud as I could. I took a purse
of gold out of my pocket, and humbly presented it to him. He
received it on the palm of his hand, then applied it close to his eye
to see what it was, and afterwards turned it several times with the
point of a pin (which he took out of his sleeve), but could make
nothing of it. Whereupon I made a sign that he should place his
hand on the ground. I then took the purse, and opening it, poured
all the gold into his palm. There were six Spanish pieces of four
pistoles each, besides twenty or thirty smaller coins. I saw him wet
the tip of his little finger upon his tongue, and take up one of my
largest pieces, and then another, but he seemed to be wholly
ignorant what they were. He made me a sign to put them again into
my purse, and the purse again into my pocket, which after offering it
to him several times, I thought it best to do.
The farmer by this time was convinced I must be a rational
creature. He spoke often to me, but the sound of his voice pierced
my ears like that of a watermill, yet his words were articulate
enough. I answered as loud as I could in several languages, and he
often laid his ear within two yards of me, but all in vain, for we were
wholly unintelligible to each other. He then sent his servants to their
work, and taking his handkerchief out of his pocket, he doubled and
spread it on his left hand, which he placed flat on the ground with
the palm upwards, making me a sign to step into it, as I could easily
do, for it was not above a foot in thickness. I thought it my part to
obey, and, for fear of falling, laid myself at full length upon the
handkerchief, with the remainder of which he lapped me up to the
head for further security, and in this manner carried me home to his
house. There he called his wife, and showed me to her; but she
screamed and ran back, as women in England do at the sight of a
toad or a spider. However, when she had awhile seen my behavior,
and how well I observed the signs her husband made, she was soon
reconciled, and by degrees grew extremely tender of me.
It was about twelve at noon and a servant brought in dinner. It
was only one substantial dish of meat (fit for the plain condition of a
husbandman), in a dish of about four-and-twenty feet diameter. The
company were the farmer and his wife, three children, and an old
grandmother. When they were sat down, the farmer placed me at
some distance from him on the table, which was thirty feet high
from the floor. I was in a terrible fright, and kept as far as I could
from the edge for fear of falling. The wife minced a bit of meat, then
crumbled some bread on a trencher, and placed it before me. I made
her a low bow, took out my knife and fork, and fell to eat, which
gave them exceeding delight. The mistress sent her maid for a small
dram cup, which held about three gallons, and filled it with drink; I
took up the vessel with much difficulty in both hands, and in a most
respectful manner drank to her ladyship’s health, expressing the
words as loud as I could in English, which made the company laugh
so heartily that I was almost deafened with the noise. This liquor
tasted like a small cider, and was not unpleasant. Then the master
made me a sign to come to his trencher side; but as I walked on the
table, being in great surprise all the time, as the indulgent reader
will easily conceive and excuse, I happened to stumble against a
crust, and fell flat on my face, but received no hurt. I got up
immediately, and observing the good people to be in much concern,
I took my hat (which I held under my arm out of good manners),
and waving it over my head, gave three huzzas, to show I had got
no mischief by my fall. But advancing forwards towards my master
(as I shall henceforth call him), his youngest son, who sat next to
him, an arch boy of about ten years old, took me up by the legs, and
held me so high in the air that I trembled in every limb; but his
father snatched me from him, and at the same time gave him such a
box on the left ear as would have felled a European troop of horse
to the earth, ordering him to be taken from the table. But being
afraid the boy might owe me a spite, and well remembering how
mischievous all children among us naturally are to sparrows, rabbits,
young kittens, and puppy dogs, I fell on my knees, and pointing to
the boy, made my master to understand as well as I could, that I
desired his son might be pardoned. The father complied, and the lad
took his seat again, whereupon I went to him and kissed his hand,
which my master took, and made him stroke me gently with it.
In the midst of dinner, my mistress’s favorite cat leaped into her
lap. I heard a noise behind me like that of a dozen stocking weavers
at work; and turning my head, I found it proceeded from the purring
of this animal, who seemed to be three times larger than an ox, as I
computed by the view of her head, and one of her paws, while her
mistress was feeding and stroking her. The fierceness of this
creature’s countenance altogether discomposed me, though I stood
at the further end of the table, above fifty feet off; and though my
mistress held her fast, for fear she might give a spring, and seize me
in her talons. But it happened there was no danger, for the cat took
not the least notice of me when my master placed me within three
yards of her. And as I have been always told, and found true by
experience in my travels, that flying, or discovering fear, before a
fierce animal is a certain way to make it pursue or attack you; so I
resolved, in this dangerous juncture, to show no manner of concern.
I walked with intrepidity five or six times before the very head of the
cat, and came within half a yard of her; whereupon she drew herself
back, as if she were more afraid of me. I had less apprehension
concerning the dogs, whereof three or four came into the room, as it
is usual in farmers’ houses; one of which was a mastiff equal in bulk
to four elephants, and a grey-hound somewhat taller than the
mastiff, but not so large.
When dinner was almost done, the nurse came in with a child of a
year old in her arms, who immediately spied me, and began a squall
that you might have heard from London Bridge to Chelsea, after the
usual oratory of infants, to get me for a plaything. The mother, out
of pure indulgence, took me up, and put me towards the child, who
presently seized me by the middle, and got my head in his mouth,
where I roared so loud that the urchin was frighted, and let me
drop; and I should infallibly have broke my neck, if the mother had
not held her apron under me. The nurse, to quiet her babe, made
use of a rattle, which was a kind of hollow vessel filled with great
stones, and fastened by a cable to the child’s waist; but all in vain,
so that she was forced to apply the last remedy by giving it suck. I
must confess no object ever disgusted me so much as the sight of
her monstrous breast, which I cannot tell what to compare with, so
as to give the curious reader an idea of its bulk, shape, and color. I
had a near sight of her, she sitting down the more conveniently to
give suck, and I standing on the table. This made me reflect upon
the fair skins of our English ladies, who appear so beautiful to us
only because they are of our own size, and their defects not to be
seen but through a magnifying glass; where we find by experiment
that the smoothest and whitest skins look rough and coarse, and ill
colored.
I remember when I was at Lilliput, the complexions of those
diminutive people appeared to me the fairest in the world; and
talking upon this subject with a person of learning there, who was
an intimate friend of mine, he said that my face appeared much
fairer and smoother when he looked on me from the ground, than it
did upon a nearer view when I took him up in my hand and brought
him close, which he confessed was at first a very shocking sight. He
said he could discover great holes in my skin; that the stumps of my
beard were ten times stronger than the bristles of a boar, and my
complexion made up of several colors, altogether disagreeable.
Although I must beg leave to say for myself, that I am as fair as
most of my sex and country, and very little sunburned by all my
travels. On the other side, discoursing of the ladies in that emperor’s
court, he used to tell me one had freckles, another too wide a
mouth, a third too large a nose; nothing of which I was able to
distinguish. I confess this reflection was obvious enough; which,
however, I could not forbear, lest the reader might think those vast
creatures were actually deformed: for I must do them the justice to
say they are a comely race of people; and particularly the features of
my master’s countenance, although he were but a farmer, when I
beheld him from the height of sixty feet, appeared very well
proportioned.
“These horrible animals had the boldness to attack me on both
sides”
Page 98
When dinner was done, my master went out to his laborers, and
as I could discover by his voice and gesture, gave his wife a strict
charge to take care of me. I was very much tired and disposed to
sleep, which my mistress perceiving, she put me on her own bed,
and covered me with a clean white handkerchief, but larger and
coarser than the mainsail of a man of war.
I slept about two hours, and dreamed I was at home with my wife
and children, which aggravated my sorrows when I awaked and
found myself alone in a vast room, between two and three hundred
feet wide, and above two hundred high, lying in a bed twenty yards
wide. My mistress was gone about her household affairs, and had
locked me in. The bed was eight yards from the floor. While I was
under these circumstances, two rats crept up the curtains, and ran
smelling backwards and forwards on the bed. One of them came up
almost to my face, whereupon I rose in a fright, and drew out my
hanger to defend myself. These horrible animals had the boldness to
attack me on both sides, and one of them held his forefeet at my
collar; but I had the good fortune to rip up his belly before he could
do me any mischief. He fell down at my feet, and the other, seeing
the fate of his comrade, made his escape, but not without one good
wound on the back, which I gave him as he fled, and made the
blood run trickling from him. After this exploit I walked gently to and
fro on the bed, to recover my breath and loss of spirits. These
creatures were of the size of a large mastiff, but infinitely more
nimble and fierce; so that if I had taken off my belt before I went to
sleep, I must have infallibly been torn to pieces and devoured. I
measured the tail of the dead rat, and found it to be two yards long,
wanting an inch; but it went against my stomach to drag the carcass
off the bed, where it lay still bleeding. I observed it had yet some
life, but with a strong slash across the neck I thoroughly dispatched
it.
Soon after, my mistress came into the room, who seeing me all
bloody, ran and took me up in her hand. I pointed to the dead rat,
smiling and making other signs to show I was not hurt, whereat she
was extremely rejoiced, calling the maid to take up the dead rat with
a pair of tongs, and throw it out of the window. Then she set me on
a table, where I showed her my hanger all bloody, and wiping it on
the lappet of my coat returned it to the scabbard.
I hope the gentle reader will excuse me for dwelling on
particulars, which, however insignificant they may appear to
groveling vulgar minds, yet will certainly help a philosopher to
enlarge his thoughts and imagination, and apply them to the benefit
of public as well as private life, which was my sole design in
presenting this and other accounts of my travels to the world;
wherein I have been chiefly studious of truth, without affecting any
ornaments of learning or of style. But the whole scene of this voyage
made so strong an impression on my mind, and is so deeply fixed in
my memory, that in committing it to paper I did not omit one
material circumstance; however, upon a strict review, I blotted out
several passages of less moment which were in my first copy, for
fear of being censured as tedious and trifling, whereof travelers are
often, perhaps not without justice, accused.
CHAPTER II
A DESCRIPTION OF THE FARMER’S DAUGHTER—THE AUTHOR CARRIED
TO A MARKET TOWN, AND THEN TO THE METROPOLIS—THE
PARTICULARS OF HIS JOURNEY.