100% found this document useful (13 votes)
24 views

Immediate download (Ebook) OpenCV 3 computer vision application programming cookbook recipes to help you build computer vision applications that make the most of the popular C++ library OpenCV 3 by Laganière, Robert ISBN 9781786469113, 9781786469717, 1786469111, 1786469715 ebooks 2024

The document is a promotional overview of various eBooks related to OpenCV, particularly focusing on the 'OpenCV 3 Computer Vision Application Programming Cookbook' by Robert Laganiere. It provides links to download the eBooks in different formats and highlights the author's credentials and contributions to the field of computer vision. Additionally, it mentions other related titles and offers information about the publisher, Packt Publishing.

Uploaded by

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

Immediate download (Ebook) OpenCV 3 computer vision application programming cookbook recipes to help you build computer vision applications that make the most of the popular C++ library OpenCV 3 by Laganière, Robert ISBN 9781786469113, 9781786469717, 1786469111, 1786469715 ebooks 2024

The document is a promotional overview of various eBooks related to OpenCV, particularly focusing on the 'OpenCV 3 Computer Vision Application Programming Cookbook' by Robert Laganiere. It provides links to download the eBooks in different formats and highlights the author's credentials and contributions to the field of computer vision. Additionally, it mentions other related titles and offers information about the publisher, Packt Publishing.

Uploaded by

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

Download Full Version ebook - Visit ebooknice.

com

(Ebook) OpenCV 3 computer vision application


programming cookbook recipes to help you build
computer vision applications that make the most of
the popular C++ library OpenCV 3 by Laganière,
Robert ISBN 9781786469113, 9781786469717,
https://ebooknice.com/product/opencv-3-computer-vision-
1786469111, 1786469715
application-programming-cookbook-recipes-to-help-you-build-
computer-vision-applications-that-make-the-most-of-the-
popular-c-library-opencv-3-11651822

Click the button below to download

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebooknice.com


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

Start reading on any device today!

(Ebook) Opencv 3 Computer Vision Application Programming


Cookbook, Third Edition by Robert Laganiere ISBN
9781786469717, 1786469715
https://ebooknice.com/product/opencv-3-computer-vision-application-
programming-cookbook-third-edition-7164870

ebooknice.com

(Ebook) OpenCV 3 Computer Vision with Python Cookbook:


Leverage the power of OpenCV 3 and Python to build
computer vision applications by Alexey Spizhevoy,
Aleksandr Rybnikov ISBN 9781788474443, 1788474449
https://ebooknice.com/product/opencv-3-computer-vision-with-python-
cookbook-leverage-the-power-of-opencv-3-and-python-to-build-computer-
vision-applications-10447758
ebooknice.com

(Ebook) Learning OpenCV 3: Computer Vision in C++ with the


OpenCV Library by Adrian Kaehler, Gary Bradski ISBN
9781491937990, 1491937998
https://ebooknice.com/product/learning-opencv-3-computer-vision-in-c-
with-the-opencv-library-5693510

ebooknice.com

(Ebook) OpenCV Computer Vision Application Programming


Cookbook, 2nd Edition by Robert Laganiere ISBN
9781782161486, 1782161481
https://ebooknice.com/product/opencv-computer-vision-application-
programming-cookbook-2nd-edition-6675636

ebooknice.com
(Ebook) Biota Grow 2C gather 2C cook by Loucas, Jason;
Viles, James ISBN 9781459699816, 9781743365571,
9781925268492, 1459699815, 1743365578, 1925268497
https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374

ebooknice.com

(Ebook) Learning OpenCV: Computer Vision with the OpenCV


Library by Gary Bradski, Adrian Kaehler ISBN
9780596516130, 0596516134
https://ebooknice.com/product/learning-opencv-computer-vision-with-
the-opencv-library-1763016

ebooknice.com

(Ebook) Learning OpenCV, 2nd Edition: Computer Vision in


C++ with the OpenCV Library by Adrian Kaehler, Gary
Bradski ISBN 9781449314651, 1449314651
https://ebooknice.com/product/learning-opencv-2nd-edition-computer-
vision-in-c-with-the-opencv-library-5474200

ebooknice.com

(Ebook) Learning Opencv 3 Computer Vision with Python by


Joe Minichino, Joseph Howse ISBN 9781785283840, 1785283847

https://ebooknice.com/product/learning-opencv-3-computer-vision-with-
python-7295256

ebooknice.com

(Ebook) OpenCV Computer Vision with Python by Howse,


Joseph ISBN 9781782163923, 1782163921

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

ebooknice.com
OpenCV 3 Computer Vision
Application Programming
Cookbook
Third Edition

Recipes to help you build computer vision applications that


make the most of the popular C++ library OpenCV 3

Robert Laganiere

BIRMINGHAM - MUMBAI
OpenCV 3 Computer Vision Application
Programming Cookbook
Third Edition

Copyright © 2017 Packt Publishing

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.

First published: May 2011

Second edition: August 2014

Third edition: February 2017

Production reference: 1070217


Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78646-971-7
www.packtpub.com
Credits

Author Copy Editor

Robert Laganiere Safis Editing

Reviewer Project Coordinator

Luca Del Tongo Ulhas Kambali

Commissioning Editor Proofreader

Edward Gordon Safis Editing

Acquisition Editor Indexer

Nitin Dasan Tejal Daruwale Soni

Content Development Editor Graphics

Nikhil Borkar Kirk D'Penha


Jason Monteiro

Technical Editor Production Coordinator

Subhalaxmi Nadar Shantanu Zagade


About the Author
Robert Laganiere is a professor at the School of Electrical Engineering and Computer
Science of the University of Ottawa, Canada. He is also a faculty member of the VIVA
research lab and is the co-author of several scientific publications and patents in content-
based video analysis, visual surveillance, driver-assistance, object detection, and tracking.
Robert authored the OpenCV2 Computer Vision Application Programming Cookbook in
2011 and co-authored Object Oriented Software Development published by McGraw Hill in
2001. He co-founded Visual Cortek in 2006, an Ottawa-based video analytics startup that
was later acquired by http://iwatchlife.com/ in 2009. He is also a consultant in
computer vision and has assumed the role of Chief Scientist in a number of startups
companies such as Cognivue Corp, iWatchlife, and Tempo Analytics. Robert has a Bachelor
of Electrical Engineering degree from Ecole Polytechnique in Montreal (1987) and MSc and
PhD degrees from INRS-Telecommunications, Montreal (1996). Visit the author’s website at
http://www.laganiere.name/.

I wish to thank all my students at the VIVA lab; I learn so much from them.
About the Reviewer
Luca Del Tongo is a computer engineer with a strong passion for algorithms, computer
vision, and image processing techniques. He's the coauthor of a free e-book called Data
Structures and Algorithms (DSA) with over 100k downloads so far and has published
several image processing tutorials on his YouTube channel using Emgu CV. During his
master's thesis, he developed an image forensic algorithm published in a scientific paper
called Copy Move forgery detection and localization by means of robust clustering with J-
Linkage. Currently, Luca works as a software engineer in the ophthalmology field
developing corneal topography, processing algorithms, IOL calculation, and computerized
chart projector. He loves to play sport and follow MOOC courses in his spare time.

You can contact him through his blog at http://blogs.ugidotnet.org/wetblog.


www.PacktPub.com
For support files and downloads related to your book, please visit 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.

https://www.packtpub.com/mapt

Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt
books and video courses, as well as industry-leading tools to help you plan your personal
development and advance your career.

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
Customer Feedback
Thank you for purchasing this Packt book. We take our commitment to improving our
content and products to meet your needs seriously—that's why your feedback is so
valuable. Whatever your feelings about your purchase, please consider leaving a review on
this book's Amazon page. Not only will this help us, more importantly it will also help
others in the community to make an informed decision about the resources that they invest
in to learn.

You can also review for us on a regular basis by joining our reviewers' club. If you're
interested in joining, or would like to learn more about the benefits we offer, please
contact us: customerreviews@packtpub.com.
Table of Contents
Preface 1
Chapter 1: Playing with Images 8
Introduction 8
Installing the OpenCV library 9
Getting ready 9
How to do it… 9
How it works… 14
There's more… 15
The Visualization Toolkit and the cv::viz module 15
The OpenCV developer site 16
See also 16
Loading, displaying, and saving images 16
Getting ready 17
How to do it… 17
How it works… 20
There's more… 21
Clicking on images 22
Drawing on images 23
See also 24
Exploring the cv::Mat data structure 24
How to do it… 25
How it works… 27
There's more… 31
The input and output arrays 31
Manipulating small matrices 31
See also 32
Defining regions of interest 32
Getting ready 32
How to do it… 33
How it works… 34
There's more… 34
Using image masks 35
See also 36
Chapter 2: Manipulating Pixels 37
Introduction 37
Accessing pixel values 38
Getting ready 39
How to do it… 39
How it works… 41
There's more… 42
The cv::Mat_ template class 42
See also 42
Scanning an image with pointers 42
Getting ready 43
How to do it… 43
How it works… 45
There's more… 46
Other color reduction formulas 46
Having input and output arguments 47
Efficient scanning of continuous images 49
Low-level pointer arithmetic 50
See also 51
Scanning an image with iterators 51
Getting ready 51
How to do it… 51
How it works… 52
There's more… 54
See also 54
Writing efficient image-scanning loops 54
How to do it… 55
How it works… 55
There's more… 57
See also 58
Scanning an image with neighbor access 58
Getting ready 58
How to do it… 59
How it works… 60
There's more… 61
See also 62
Performing simple image arithmetic 63
Getting ready 63
How to do it… 63
How it works… 64
There's more… 65
Overloaded image operators 65
Splitting the image channels 66

[ ii ]
Remapping an image 67
How to do it… 67
How it works… 68
See also 70
Chapter 3: Processing the Colors of an Image 71
Introduction 71
Comparing colors using the Strategy design pattern 72
How to do it… 72
How it works… 74
There's more… 78
Computing the distance between two color vectors 78
Using OpenCV functions 79
The floodFill function 80
Functor or function object 82
The OpenCV base class for algorithms 82
See also 83
Segmenting an image with the GrabCut algorithm 83
How to do it… 84
How it works… 86
See also 87
Converting color representations 87
How to do it… 88
How it works… 89
See also 91
Representing colors with hue, saturation, and brightness 91
How to do it… 91
How it works… 94
There's more… 97
Using colors for detection – skin tone detection 97
See also 100
Chapter 4: Counting the Pixels with Histograms 101
Introduction 101
Computing an image histogram 102
Getting ready 102
How to do it… 103
How it works… 107
There's more… 108
Computing histograms of color images 109
See also 110
Applying look-up tables to modify the image's appearance 111

[ iii ]
How to do it… 111
How it works… 112
There's more… 112
Stretching a histogram to improve the image contrast 113
Applying a look-up table to color images 115
See also 115
Equalizing the image histogram 115
How to do it… 116
How it works… 117
Backprojecting a histogram to detect specific image content 118
How to do it… 118
How it works… 121
There's more… 121
Backprojecting color histograms 121
See also 125
Using the mean shift algorithm to find an object 125
How to do it… 126
How it works… 129
See also 130
Retrieving similar images using the histogram comparison 130
How to do it… 130
How it works… 132
See also 133
Counting pixels with integral images 133
How to do it… 134
How it works… 135
There's more… 137
Adaptive thresholding 137
Visual tracking using histograms 141
See also 145
Chapter 5: Transforming Images with Morphological Operations 146
Introduction 146
Eroding and dilating images using morphological filters 147
Getting ready 147
How to do it… 148
How it works… 150
There's more… 152
See also 152
Opening and closing images using morphological filters 152
How to do it… 152

[ iv ]
How it works… 154
See also 155
Applying morphological operators on gray-level images 155
How to do it… 156
How it works… 157
See also 158
Segmenting images using watersheds 159
How to do it… 159
How it works… 164
There's more… 165
See also 167
Extracting distinctive regions using MSER 167
How to do it… 167
How it works… 170
See also 172
Chapter 6: Filtering the Images 173
Introduction 173
Filtering images using low-pass filters 174
How to do it… 174
How it works… 176
See also 179
Downsampling images with filters 179
How to do it… 180
How it works… 182
There's more… 183
Interpolating pixel values 183
See also 185
Filtering images using a median filter 185
How to do it… 186
How it works… 186
Applying directional filters to detect edges 187
How to do it… 188
How it works… 191
There's more… 194
Gradient operators 195
Gaussian derivatives 197
See also 198
Computing the Laplacian of an image 198
How to do it… 198

[v]
How it works… 200
There's more… 204
Enhancing the contrast of an image using the Laplacian 204
Difference of Gaussians 204
See also 205
Chapter 7: Extracting Lines, Contours, and Components 206
Introduction 206
Detecting image contours with the Canny operator 207
How to do it… 207
How it works… 209
See also 211
Detecting lines in images with the Hough transform 211
Getting ready 211
How to do it… 212
How it works… 217
There's more… 220
Detecting circles 221
See also 223
Fitting a line to a set of points 223
How to do it… 223
How it works… 226
There's more… 226
Extracting connected components 226
How to do it… 227
How it works… 229
There's more… 230
Computing components' shape descriptors 232
How to do it… 232
How it works… 234
There's more… 235
Quadrilateral detection 235
Chapter 8: Detecting Interest Points 238
Introduction 238
Detecting corners in an image 238
How to do it… 239
How it works… 245
There's more… 247
Good features to track 247
See also 249

[ vi ]
Detecting features quickly 250
How to do it… 250
How it works… 251
There's more… 253
See also 255
Detecting scale-invariant features 256
How to do it… 256
How it works… 258
There's more… 260
The SIFT feature-detection algorithm 260
See also 262
Detecting FAST features at multiple scales 263
How to do it… 263
How it works… 264
There's more… 265
The ORB feature-detection algorithm 265
See also 266
Chapter 9: Describing and Matching Interest Points 267
Introduction 267
Matching local templates 268
How to do it… 269
How it works… 272
There's more… 274
Template matching 274
See also 275
Describing and matching local intensity patterns 275
How to do it… 276
How it works… 278
There's more… 281
Cross-checking matches 281
The ratio test 282
Distance thresholding 283
See also 284
Matching keypoints with binary descriptors 285
How to do it… 285
How it works… 287
There's more… 288
FREAK 288
See also 290
Chapter 10: Estimating Projective Relations in Images 291

[ vii ]
Introduction 291
Image formation 292
Computing the fundamental matrix of an image pair 295
Getting ready 295
How to do it… 296
How it works… 300
See also 301
Matching images using random sample consensus 301
How to do it… 302
How it works… 305
There's more… 307
Refining the fundamental matrix 307
Refining the matches 308
Computing a homography between two images 308
Getting ready 309
How to do it… 310
How it works… 313
There's more… 313
Generating image panoramas with the cv::Stitcher module 314
See also 315
Detecting a planar target in images 315
How to do it… 315
How it works… 319
See also 322
Chapter 11: Reconstructing 3D Scenes 323
Introduction 323
Digital image formation 324
Calibrating a camera 326
How to do it… 326
How it works… 332
There's more… 335
Calibration with known intrinsic parameters 335
Using a grid of circles for calibration 335
See also 335
Recovering camera pose 336
How to do it… 336
How it works… 339
There's more… 340
cv::Viz, a 3D Visualizer module 340
See also 342

[ viii ]
Reconstructing a 3D scene from calibrated cameras 342
How to do it… 342
How it works… 348
There's more… 350
Decomposing a homography 350
Bundle adjustment 351
See also 351
Computing depth from stereo image 351
Getting ready 352
How to do it… 353
How it works… 355
See also 357
Chapter 12: Processing Video Sequences 358
Introduction 358
Reading video sequences 359
How to do it… 359
How it works… 360
There's more… 362
See also 362
Processing the video frames 362
How to do it… 363
How it works… 364
There's more… 368
Processing a sequence of images 368
Using a frame processor class 370
See also 371
Writing video sequences 371
How to do it… 372
How it works… 373
There's more… 375
The codec four-character code 376
See also 377
Extracting the foreground objects in a video 377
How to do it… 379
How it works… 381
There's more… 381
The Mixture of Gaussian method 381
See also 384
Chapter 13: Tracking Visual Motion 385

[ ix ]
Introduction 385
Tracing feature points in a video 386
How to do it… 386
How it works… 391
See also 392
Estimating the optical flow 393
Getting ready 394
How to do it… 395
How it works… 397
See also 398
Tracking an object in a video 399
How to do it… 399
How it works… 403
See also 406
Chapter 14: Learning from Examples 407
Introduction 407
Recognizing faces using nearest neighbors of local binary patterns 408
How to do it… 408
How it works… 411
See also 415
Finding objects and faces with a cascade of Haar features 416
Getting ready 416
How to do it… 418
How it works… 422
There's more… 424
Face detection with a Haar cascade 425
See also 426
Detecting objects and people with Support Vector Machines and
histograms of oriented gradients 426
Getting ready 427
How to do it… 428
How it works… 431
There's more… 434
HOG visualization 435
People detection 437
Deep learning and Convolutional Neural Networks 439
See also 440
Index 441

[x]
Preface
Augmented reality, driving assistance, video monitoring; more and more applications are
now using computer vision and image analysis technologies, and yet we are still in the
infancy of the development of new computerized systems capable of understanding our
worlds through the sense of vision. And with the advent of powerful and affordable
computing devices and visual sensors, it has never been easier to create sophisticated
imaging applications. A multitude of software tools and libraries manipulating images and
videos are available, but for anyone who wishes to develop smart vision-based applications,
the OpenCV library is the tool to use. OpenCV (Open source Computer Vision) is an open
source library containing more than 500 optimized algorithms for image and video analysis.
Since its introduction in 1999, it has been largely adopted as the primary development tool
by the community of researchers and developers in computer vision. OpenCV was
originally developed at Intel by a team led by Gary Bradski as an initiative to advance
research in vision and promote the development of rich vision-based, CPU-intensive
applications. After a series of beta releases, version 1.0 was launched in 2006. A second
major release occurred in 2009 with the launch of OpenCV 2 that proposed important
changes, especially the new C++ interface, which we use in this book. In 2012, OpenCV
reshaped itself as a non-profit foundation (http://opencv.org/) relying on crowdfunding
for its future development. OpenCV3 was introduced in 2013; changes were made mainly to
improve the usability of library. Its structure has been revised to remove the unnecessary
dependencies, large modules have been split into smaller ones and the API has been
refined. This book is the third edition of the OpenCV Computer Vision Application
Programming Cookbook and the first one that covers OpenCV version 3. All the programming
recipes of the previous editions have been reviewed and updated. We also have added new
content and new chapters to provide readers with even better coverage of the essential
functionalities of the library. This book covers many of the library’s features and
explains how to use them to accomplish specific tasks. Our objective is not to provide
detailed coverage of every option offered by the OpenCV functions and classes but rather to
give you the elements you need to build your applications from the ground up. We also
explore, in this book, fundamental concepts in image analysis and we describe some of the
important algorithms in computer vision. This book is an opportunity for you to get
introduced to the world of image and video analysis. But this is just the beginning. The
good news is that OpenCV continues to evolve and expand. Just consult the OpenCV online
documentation at http://opencv.org/ to stay updated about what the library can do for
you. You can also visit the author’s website at http://www.laganiere.name/ for updated
information about this cookbook.
Preface

What this book covers


Chapter 1, Playing with Images, introduces the OpenCV library and shows you how to build
simple applications that can read and display images. It also introduces the basic OpenCV
data structures.

Chapter 2, Manipulating Pixels, explains how an image can be read. It describes different
methods for scanning an image in order to perform an operation on each of its pixels.

Chapter 3, Processing the Colors of an Image, consists of recipes presenting various object-
oriented design patterns that can help you to build better computer vision applications. It
also discusses the concept of colors in images.

Chapter 4, Counting the Pixels with Histograms, shows you how to compute image
histograms and how they can be used to modify an image. Different applications based on
histograms are presented that achieve image segmentation, object detection, and image
retrieval.

Chapter 5, Transforming Images with Morphological Operations, explores the concept of


mathematical morphology. It presents different operators and how they can be used to
detect edges, corners, and segments in images.

Chapter 6, Filtering the Images, teaches you the principle of frequency analysis and image
filtering. It shows how low-pass and high-pass filters can be applied to images and presents
the concept of derivative operators.

Chapter 7, Extracting Lines, Contours, and Components, focuses on the detection of geometric
image features. It explains how to extract contours, lines and connected components in an
image.

Chapter 8, Detecting Interest Points, describes various feature point detector in images.

Chapter 9, Describing and Matching Interest Points, explains how descriptors of interest
points can be computed and used to match points between images.

Chapter 10, Estimating Projective Relations in Images, explores the projective relations that
exist between two images in the same scene. It also describes how to detect specific targets
in an image.

Chapter 11, Reconstructing 3D scenes, allows you to reconstruct the 3D elements of a scene
from multiple images and recover the camera pose. It also includes a description of the
camera calibration process.

[2]
Preface

Chapter 12, Processing Video Sequences, provide a framework to read and write a video
sequence and to process its frames. It shows you also how it is possible to extract the
foreground objects moving in front of a camera.

Chapter 13, Tracking Visual Motion, addresses the visual tracking problem. It shows you
how to compute the apparent motion in videos. It also explains how to track moving objects
in an image sequence.

Chapter 14, Learning from Examples, introduces basic concepts in machine learning. It shows
how object classifiers can be built from image samples.

What you need for this book


This cookbook is based on the C++ API of the OpenCV library. It is therefore assumed that
you have some experience with the C++ language. In order to run the examples presented in
the recipes and experiment with them, you need a good C++ development environment.
Microsoft Visual Studio and Qt are two popular choices.

Who this book is for


This cookbook is appropriate for novice C++ programmers who want to learn how to use
the OpenCV library to build computer vision applications. It is also suitable for professional
software developers who wants to be introduced to the concepts of computer vision
programming. It can be used as a companion book in university-level computer vision
courses. It constitutes an excellent reference for graduate students and researchers in image
processing and computer vision.

Sections
In this book, you will find several headings that appear frequently (Getting ready, How to
do it, How it works, There's more, and See also). To give clear instructions on how to
complete a recipe, we use these sections as follows:

Getting ready
This section tells you what to expect in the recipe, and describes how to set up any software
or any preliminary settings required for the recipe.

[3]
Preface

How to do it…
This section contains the steps required to follow the recipe.

How it works…
This section usually consists of a detailed explanation of what happened in the previous
section.

There's more…
This section consists of additional information about the recipe in order to make the reader
more knowledgeable about the recipe.

See also
This section provides helpful links to other useful information for the recipe.

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 can
include other contexts through the use of the include directive."

A block of code is set as follows:


// Compute Laplacian using LaplacianZC class
LaplacianZC laplacian;
laplacian.setAperture(7); // 7x7 laplacian
cv::Mat flap= laplacian.computeLaplacian(image);
laplace= laplacian.getLaplacianImage();

When we wish to draw your attention to a particular part of a code block, the relevant lines
or items are set in bold:
// Compute Laplacian using LaplacianZC class
LaplacianZC laplacian;
laplacian.setAperture(7); // 7x7 laplacian
cv::Mat flap= laplacian.computeLaplacian(image);
laplace= laplacian.getLaplacianImage();

[4]
Preface

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: "Clicking the Next button
moves you to the next screen."

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.

To send us general feedback, simply e-mail feedback@packtpub.com, and mention the


book's title in the subject of your message.

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.

Downloading the example code


You can download the example code files for this book from your account at http://www.p
acktpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.c
om/supportand register to have the files e-mailed directly to you.

You can download the code files by following these steps:

1. Log in or register to our website using your e-mail address and password.
2. Hover the mouse pointer on the SUPPORT tab at the top.
3. Click on Code Downloads & Errata.
4. Enter the name of the book in the Search box.
5. Select the book for which you're looking to download the code files.
6. Choose from the drop-down menu where you purchased this book from.
7. Click on Code Download.

[5]
Preface

You can also download the code files by clicking on the Code Files button on the book's
webpage at the Packt Publishing website. This page can be accessed by entering the book's
name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:

WinRAR / 7-Zip for Windows


Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at


https://github.com/PacktPublishing/OpenCV3-Computer-Vision-Application-Programm
ing-Cookbook-Third-Edition. We also have other code bundles from our rich catalog of
books and videos available at https://github.com/PacktPublishing/. Check them out!

The source code files of the examples presented in this cookbook are also hosted in the
author's Github repository. You can visit the author's repository at https://github.com/la
ganiereto obtain the latest version of the code.

Downloading the color images of this book


We also provide you with a PDF file that has color images of the screenshots/diagrams used
in this book. The color images will help you better understand the changes in the output.
You can download this file from https://www.packtpub.com/sites/default/files/down
loads/OpenCV3ComputerVisionApplicationProgrammingCookbookThirdEdition_ColorI
mages.pdf.

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.

[6]
Preface

To view the previously submitted errata, go to https://www.packtpub.com/books/conten


t/supportand enter the name of the book in the search field. The required information will
appear under the Errata section.

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.

Please contact us at copyright@packtpub.com with a link to the suspected pirated


material.

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.

[7]
Playing with Images
1
In this chapter, we will get you started with the OpenCV library. You will learn how to
perform the following tasks:

Installing the OpenCV library


Loading, displaying, and saving images
Exploring the cv::Mat data structure
Defining regions of interest

Introduction
This chapter will teach you the basic elements of OpenCV and will show you how to
accomplish the most fundamental image processing tasks: reading, displaying, and saving
images. However, before you start with OpenCV, you need to install the library. This is a
simple process that is explained in the first recipe of this chapter.

All your computer vision applications will involve the processing of images. This is why
OpenCV offers you a data structure to handle images and matrices. It is a powerful data
structure with many useful attributes and methods. It also incorporates an advanced
memory management model that greatly facilitates the development of applications. The
last two recipes of this chapter will teach you how to use this important data structure of
OpenCV.
Playing with Images

Installing the OpenCV library


OpenCV is an open source library for developing computer vision applications that can run
on multiple platforms, such as Windows, Linux, Mac, Android, and iOS. It can be used in
both academic and commercial applications under a BSD license that allows you to freely
use, distribute, and adapt it. This recipe will show you how to install the library on your
machine.

Getting ready
When you visit the OpenCV official website at http://opencv.org/, you will find the latest
release of the library, the online documentation describing the Application Programming
Interface (API), and many other useful resources on OpenCV.

How to do it…
From the OpenCV website, find the latest available downloads and select the one that
corresponds to the platform of your choice (Windows, Linux/Mac, or iOS). Once the
OpenCV package is downloaded, run the WinZip self-extractor and select the location of
your choice. An opencv directory will be created; it is a good idea to rename it in a way that
will show which version you are using (for example, in Windows, your final directory
could be C:\opencv-3.2). This directory will contain a collection of files and directories
that constitute the library. Notably, you will find the sources directory that will contain all
the source files (yes, it is open source!).

In order to complete the installation of the library and have it ready for use, you need to
take an important step: generate the binary files of the library for the environment of your
choice. This is indeed the point where you have to make a decision on the target platform
you wish to use to create your OpenCV applications. Which operating system do you prefer
to use? Which compiler should you select? Which version? 32-bit or 64-bit? As you can see,
there are many possible options, and this is why you have to build the library that fits your
needs.

[9]
Playing with Images

The Integrated Development Environment (IDE) you will use in your project development
will also guide you to make these choices. Note that the library package also comes with
precompiled binaries that you can directly use if they correspond to your situation (check
the build directory adjacent to the sources directory). If one of the precompiled binaries
satisfies your requirements, then you are ready to go.

One important remark, however. Since version 3, OpenCV has been split into two major
components. The first one is the main OpenCV source repository that includes the mature
algorithms. This is the one you have downloaded. A separate contribution repository also
exists, and it contains the new computer vision algorithm, recently added by the OpenCV
contributors. If your plan is to use only the core functions of OpenCV, you do not need the
contrib package. But if you want to play with the latest state-of-the-art algorithms, then
there is a good chance that you will need this extra module. As a matter of fact, this
cookbook will show you how to use several of these advanced algorithms. You therefore
need the contrib modules to follow the recipes of this book. So you have to go to
https://github.com/opencv/opencv_contrib and download OpenCV's extra modules
(download the ZIP file). You can unzip the extra modules into the directory of your choice;
these modules should be found at opencv_contrib-master/modules. For simplicity, you
can rename this directory as contrib and copy it directly inside the sources directory of
the main package. Note that you can also pick the extra modules of your choice and only
save them; however, you will probably find it easier, at this point, to simply keep
everything.

You are now ready to proceed with the installation. To build the OpenCV binaries, it is
highly suggested that you use the CMake tool, available at http://cmake.org. CMake is
another open source software tool designed to control the compilation process of a software
system using platform-independent configuration files. It generates the required makefile
or solution files needed for compiling a software library in your environment. Therefore,
you have to download and install CMake. Also see the There's more… section of this recipe
for an additional software package, the Visualization Toolkit (VTK), that you may want to
install before compiling the library.

[ 10 ]
Playing with Images

You can run cmake using a command-line interface, but it is easier to use CMake with its
graphical interface (cmake-gui). In the latter case, all you need to do is specify the folder
containing the OpenCV library source and the one that will contain the binaries. Now click
on Configure and select the compiler of your choice:

[ 11 ]
Exploring the Variety of Random
Documents with Different Content
Midőn Pistától elvált, utolsó harczát küzdötte végig, arczát
megmelegíté a nagylelkűség, – legyőzte gőgjét, megismerte, hogy
ámbár Pista sem bátrabb, de szive nemesebb, – s ezen pillanattól
nem kivánt az emberek közt élni, hogy közönséges gyarlóságot
lásson, s e dibdáb népnek lábainál annyi legyen, mint a forgács, mit
vagy megtipornak, vagy odább löknek.
Kiment az erdőnek mélyébe, s néha födetlen fővel állt meg a
viharban, jól esett neki, mikor a szél összekóczolá, s ilyenkor
felnézett a százados tölgyre, melynek gyengébb ágait tépi meg a
vihar, maga pedig rendületlenül áll.
Télben a kályha szájánál ült, fütötte a kályhát, s az izzó parázsok
közé tekintve, agyában lerajzolá magát a harczos élet zaja, a
pattogó fának egyhangú zörejében a puskaropogás s olykor egy
hatalmas csattanásban kiegészítve lőn az ágyú, s még így
gondolatban is jól esett neki, hogy annyiszor röpült ő Pistával legelől,
s minő hátra marad el tőle a többi!
Történetünk idejében még a vad is szivesen húzódott volna el
valami sürűbe, ha az éhség ki nem veri szegény párát eledel után,
miért a rengetegeket igen gyakran messzire kellett összeszaladgálni;
mert tél és kegyetlen hideg volt, s a hótömeg ölnyire feküdt a föld
rétege fölött.
Alig törték meg az utat, már ismét behordta a szél, s a
«Kenyeretlen» csárda előtt hamarabb megállt a kocsi, mint máskor,
s a mi kis szénát összekotort nyáron a gazda, a beszorult emberek
mind elrimánkodták, hogy megkínzott barmaik valamikép éhen ne
veszszenek.
Pista volt a legutolsó vendég és látván, hogy a csárdában a
tüzelő-szalma is kifogyott, megigérte a szabadosnak, hogy másnap
estig legfölebb, megjön egy forduló szalmával, s azonkívül a
megfogyott élelmet megint kipótolja.
Néhány órával később az éjszaki szél ujabb vihart hozott, s nem
maradt embernyom az úton, csak a széles erdőnyilás vezette az
embert, ha ezen órában még az úton maradt volna, melyen a vadak
is eszeveszetten rohantak, mert vagy a vihar, vagy az éhség
kergethette őket.
A szabados hanyatlani érzé az erőt, sebeit elevenné tette a
kemény idő, melynek mérgétől nem kimélte magát, s néha órákig
elácsorgott a csárda előtt, vagy még messzebb is, ha tán valamely
megszorult utast a viharok künn szorítottak volna, – és Pista nagyon
észrevette, hogy a szabados önmagával birkózik, midőn
szenvedéseit tagadja, tehát föltette magában, hogy másnap
visszajön, nehogy inségben feledje az erdőn.
Fáradtan húzkodott be a konyhára néhány darab fát, mit előbb
vagdalt össze, – nehogy tűz nélkül maradjon, mert az utolsó szál
szalmát Pistának lovai ették meg, s míg az Keszthelyről megfordul,
ilyen zivatarban akár meg is fagyhat.
Alig veté le az utolsó fadarabot, s alig helyezkedék el egy
bundán, kegyetlen fájások rohanták meg, s majdnem elfásultan
hevert ott néhány óráig; – midőn pedig megszünvén a fájdalom, az
álom is lefogta szemét, a kályhában a parázs lassankint elhamvadt,
s mire fölébredt, már a hamu is megfázott.
Van-e valaki eleven ember ebben a házban? – szól egy ember,
kinek bajusza, szakálla jégcsappá dermedt, s mint egy csoda nézett
be a konyhaajtón.
– Itt vagyok! – mondja a szabados, fölkapaszkodván nagy kínnal,
hogy a betévedt embernek segéljen, ha tán segítségre lenne
szükség.
Az ajtó nyilásán át látta a gazda, hogy egy szánra rakott hintó áll
a félszer alatt, – előtte négy ló gőzölögve várja az enyhelyet, a
hintóból pedig két úrhölgyet segít ki egy úr és karjára fogva vezeti
őket az egykori borivóba.
– Irgalmas Isten, csakhogy megmenekülhettünk; – mondja az
idősebb hölgy, kiről a szépség virágai nem szálltak el, ámbár az
ifjabb hölgy gyermeke, de a két hölgy között alig van több különbség,
mint egy ágnak két virága közt, melyek közől az egyik a nyilott virág
egész pompájában, a másik pedig a most fakadó bimbó.
Utasaink gróf Dunay nejével és leányával, kik az egyezségre
indulának s a zivatar az útban kapta őket s ha a csárdához nem
érnek, a fáradt lovak már az úton összerogynak.
– Anyám, – édes szép anyám! – mondja a gyermeteg hölgy,
anyját átölelve, – már azt hittem, hogy az út közepén fagyunk meg
valamennyien.
A szabados megdöbbent a szóra és sietve botorkált a konyhába,
hogy a kályhában éleszsze a tüzet, de midőn kemény ujjaival a
hamuba markolt, egészen hidegnek találta.
Tűzszerszáma után kotorászott, egyetlen kénpapir darabnál
többet nem talált, de tudta azt, hogy egy szál szalma sincsen a
csárdában, mi lángot ereszszen a fa alá, hogy tüzet fogjon, aggódva
kérdé a bejövő kocsistól:
– Jó barátom, nincs széna a bakon?
– Csakhogy magunk ide értünk, hisz utóbb már a kocsiládákat is
lecsavartam és a hóba hánytam, mert a lovak alig birták el a terhet,
hanem fél zsákra való abrakom van.
– Adja a lovaknak barátom! – mondja a szabados és egy
törzsökre hanyatlott, mert megriadt a gondolattól, hogy ennyi embert
az isten hidege vegyen meg, s az istálló sokkal tágasabb volt,
minthogy azt a négy darab ló megmelegíteni birja.
Dunay kijött a szobából, hihetőleg megérezte a melegnek fogytát,
s azt mondja a gazdának:
– Van-e fája, édes jó barátom?
– Az erdőnek legmélyében vagyunk uram, hisz a fára látok ki az
ajtón.
– Szokták füteni a kályhát?
– Ma reggel még ökröt is megsüthettem volna benne, de
lenyomott a fájdalom, – beszéli a szabados, – s míg később
elszunnyadtam, az alatt elhamvadt az utolsó szikra is.
– Rakunk újra tüzet – mondja a gróf.
– Nem vártam volna a parancsolást uram; de nincs mit elgyújtani.
– Hisz akkor megfagyunk! – véli a gróf rémülten.
– Nekem jótétemény lenne uram; de szánom ott benn azt a két
ártatlan cselédet.
– Barátom!… mondja a gróf megriadva… ez igazság vagy tréfa?
– Uram, már mondám, hogy azokat sajnálom ott benn; mert hisz
mi férfiak nem ijedünk meg a haláltól, akár ma érjen el, akár holnap
– fejezi be a szabados, a kénpapir-szeletet forgatván kezében.
– Barátom, – mondja a gróf, – egy könnyű kendő meggyúl még
ettől!
– Nem hiszem, – okoskodik amaz, – alig akkora a papir, hogy a
ként rámázolhatták, – azonban próbáljuk meg, ha meg nem gyúl, –
megfagyni akkor is ráérünk.
A gróf beszaladt, de a téli ruhák között nem akadt egy darab,
mely használhatott volna, azért mielőtt a nőknek szólna, újra kiment
a konyhára, hogy finom ingét próbálja meg letépni, tán az megfogja
majd a lángot.
A szabados kiment a csárda elejére, hogyha tán elszóródott
valahol néhány szalmaszál, azonban a hó már a házoldalon kezdett
összegyülekezni, hanem midőn az erdőnyiláson végig nézne,
három-négy puskalövésnyire lát egy elakadt hintót, s valamivel idább
négy ember törtetett egyik fától a másikig.
– Nem hittem, hogy ennyien lesznek a temetésemen! – dörmögi
a szabados, ki után a gróf kisietett, s minthogy a jövőket meglátta, a
pihentebb lovakat elővezetteté, ha még megtennék a szolgálatot, és
a hóban bukdácsolókat egyenkint elhoznák.
A kocsis az első; a gróf a hátulsó lovak egyikére kapott, s az alsó
útra gázolának szél után, s ámbár elég kínnal, de mégis elég jókor
elérték a négy gyalogoló embert.
Az ösmerkedés nem sokáig tartott, – az inség előtt a lenyujtott
kéz a legnemesebb emberbarát keze, s midőn az ember halódni
készül, utolsónak vélt órájában önként nyúl leghalálosabb ellenének
keze után s a végső végórában felebarátjait látja.
Baltayt fölsegíté a gróf a lóra, s mind a négyet átengedték a
lihegő utasoknak, a gróf pedig kocsisával a törésen ballagott, s mire
a két nő akart a gróf után tekinteni, hatan nyitottak be.
Baltay és Imre, valamint András és a kocsis volt az ujon érkezett
vendég, kik bámulva néztek egymásra a szoba közepén, de itt is
András törte meg a csöndet, levetvén hóna alól egy nagy csomót,
aztán pedig a nagyságos urat kezdé kiszedni a fagyból.
– Most már itt vagyunk valamennyien, – dörmögi András, – csak
a prókátorok hiányzanak ebben a farkasordítóban, hanem találunk
majd helyettük farkasokat.
Mindenki hallgatott, egyik sem tudta folytatni a beszédet, s
minthogy sokáig tartott a hallgatás, Dunay gróf kihívta Andrást a
konyhába.
– András! – mondja a gróf, – mi itt abban a veszedelemben
vagyunk, hogy az erdőben a fa között fagyunk meg; mert nincsen
mivel alágyujtsuk a fát.
– Itt van minden gyújtószerünk, – mondja a szabados a kis
kénpapirt előmutatva, – pedig ezzel a nyers fát tudom meg nem
gyújtjuk.
– Hála légyen a jó úristenek, – mondja András, – csakhogy itt
vagyunk.
– De megkivánta kend a halódást, atyafi, – boszankodik a
szabados, – hogy így megörült kend neki.
– De még nem kivánkozom kihordozóskodni ebből a világból,
hallja, jó barátom, – mondja András, – majd csinálok én tüzet, ha
még olyan nedves is a kelmed fája.
– Az angyalok szólnak belőle, édes öregem, – véli a gróf, –
hanem ne késsék vele, fogjon rögtön hozzá, mert már a nők nagyon
érzik a hideget.
– Csak fél órát várjunk méltóságos uram, – hadd adjam meg a
módját, – azért menjen csak be, majd én az én uraimat hívom ki.
A gróf Andrásra hagyta a dolgot, – bement a nőkhöz, kik a kályha
mellett foglaltak helyet, az öreg úr pedig Imrét akarta kiküldeni, hogy
nézzen körül a házánál, hogy meg ne fagyjanak.
András kihívta a férfiakat, kik a hívásnak engedtek, s az öreg úr
Andrástól kérdezte:
– Mi a baj, András?
– Az, hogy itt fogunk megfagyni! – mondja András egész
komolysággal nézve szemközt, s elmondván, hogy nincs mit
meggyújtani.
– Ne kiáltson kend olyan hangosan! – mondja Baltay, – hisz én is
megijedtem, hát még azok a szerencsétlen asszonyok!
– No hát elhiszi a nagyságos úr, a mit mondtam? – kérdezkedék
András.
– El hát, – mondja kínosan, – csak azt sajnálom, hogy ezek a
szegény nők itt vannak.
– Magát sajnálja a nagyságos úr, jobb lesz!
– Legyen kendnek esze a pokolban, engem már elevenen
kinyújtóztathat kend!
András nem birta könyű nélkül megállni az öreg úrnak
lemondását, kivált mikor egy hosszú hallgatás után Baltay Imrére
nézett, s annak kezét részvéttel fogta meg.
– Imre, – mondja az öreg, – remélem emberré neveltelek, hanem
ha, mint remélem, tovább kibirod, mint mi, ezt a kis lányt megőrzöd,
a mig lehet.
– Bátyám, – nem tagadom, – érette szivesen meghalok.
– Szereted?
– Nem mertem eddig megmondani! – vallja be a fiú.
– Régen vártam erre, s én nem mertelek rákényszeríteni; –
mondja az öreg is megkönnyezve a végszót, s midőn kendőjeért
nyúlna, hogy könyűjét letörülje, oldalzsebében nem lelé, hanem a
helyett Kisfaludy munkáit húzta ki, mit a kilépő gróf is meglátott már.
– Nagyságos uram, – mondja András, – még van egy szál
kéngyertyánk.
– Hát aztán!
– Nem bánná meg, ha az úrfi a kisasszonyt elvenné?
– Ne támaszsza föl kend az embert, – András! – szól
reménykedve az öreg.
– Ha azt a Kisfaludyt meggyújtom ezzel a kéngyertyával, mindjárt
lesz tüzünk.
– Nem ezt akarta kend mondani, András? – véli az öreg, – tudja
kend, hogy ez legkedvesebb jószágom.
Dunay meghatottan állt az öreg háta mögött, – s láthatta, hogy
remegnek az öregnek kezei, melyekben a könyveket tartja.
– Hát nem adja oda, nagyságos uram?
– Meggyújtaná kend az imádságos könyvét? – kérdi átható
hangon Baltay.
– Nem tudom, nagyságos uram! – mondja meglepetve a hajdú.
– Nekem ez imádságos könyvem! – bizonykolja az öreg, mire
Dunay elébe lép és először annyi idő után megszólítja az öreget.
– Most meg én faragok róvást! – mondja Dunay a multakra
czélozva, mire Baltay a gróf kezét megfogván, mondja:
– Nem fogja azt tenni, – egyszersmind Andrásnak azt mondja: –
láttam, hogy elhozta kend azt a nagy pört, – gyújtsa meg kend azt, –
de Kisfaludyt el nem pörköli kend.
– Inkább a pört, mint a könyvet? – kérdi Dunay boldogságtól
csillogó arczczal.
– Megadom magamat! – vallja be az öreg, helyet adván
Andrásnak, ki a nagy csomó papirt a kályha szájához vitte, hol az
aprófa készen volt, azután egy ütet taplóval föllobbanták a
kéngyertyát, s a kis szelet papirról a láng a pörhalmaznak egyes
csomóiba kapott, s mire egy része elégett, a nedves fát is megjárta a
láng, durrogva égvén a kályhában, melyhez a didergő vendégek egy
nagy körbe ültek.
Midőn András a tűzbe lökte a pörnek utolsó levelét, azt mondja:
– Mondtam ugy-e, nagyságos uram, hogy én vetem ezt tűzbe!
– No, hogy jobban égjen, – teszi hozzá az öreg, – itt még a rovás
is, – mondja, kihúzván oldalzsebéből a rovást, mit oly régóta
hordozgat magával, – szent a béke köztünk.
Mire bemelegedett a kályha, Baltay megösmerkedett a kis
lánynyal, kit ma ölelt meg legelőször s kezét Imréébe adván, azt
mondja:
– Édes kis hugocskám, rég neked szántam én már ezt a fiút.
– Azt gondolja a nagyságos úr, – kiált közbe András, – hogy én
azt már régen nem tudtam?
– De nem tudta kend.
– Dehogy nem tudtam, – csak hogy nem akartam mondani a
nagyságos úrnak, hogy szivesen megbékülne, – csak valaki szép
módjával elkezdeni tudná.
– Semmit sem tud kend! – mondja Baltay, nagy diadallal szedvén
elő tárczájából egy rég meggyűrt levelet, s odaadá Dunaynak, ki
rögtön megismerte a boldogult herczeg írását, melynek hiányzó
sorai következők valának:
«– – – – – – – – – –
A végóra nagy későn mondja meg, édes jó barátom, hogy rövid
életünkben is temérdek jót tehettünk volna, s higyj nekem, nagy
nyugalom tudni, hogy sokan szerettek bennünket igazán, s elfeledni
akarva sem tudnak.
Öcséd, mint Dunaytól tudom, szép lelkü gyermek – Dunaynak
leánygyermeke van, ne engedd, hogy hajlékodból idegenek tanyája
legyen, a míg lehet; – vezesd össze a két gyermeket, hogy
szeretteid úgy sirassanak meg, mint az enyéim most engemet. – Ez
első és utolsó kérelme annak, ki hű barátod a sírig Herczeg
Batthyányi Lajos m. k.»
A sorokat Dunay hangosan olvasá, a két gyermek
összefogózkodék, s a nyomorult viskóban ölelkezék össze a rég
küzködő család, mely nem lelt elég helyet a széles birtokon egy
istenáldott szóra, míg a közös veszedelem egy csárda falai közt
hozta őket össze.
András három lépésről nézte őket, mint a fáradt művész nézte
ezt a munkát, mely nélküle nem tudott megkészülni, s melyből neki
csak az az osztaléka volt, a mi becsületes embernek mindenütt jut, s
miért a gazember fáradni nem akar; – az egyiknek kevés, a
másiknak pedig az öntudat végtelen jutalom.
– András! – kiált örömében Baltay, – ha haza megyünk, minden
rovást égessen kend össze.
– Senkire sem haragszik meg ezután nagyságos úr?
– Nem én, még kendre sem! – Tréfálódzék az öreg.
– Azt hiszi nagyságos uram, hogy nem lesz még olyan magyar
ember, kinek rováson a helye?
– Azt már ezután nem mi rójuk meg, hallja kend; de a
közvélemény.
XI.
(Egyezség prókátorok nélkül.)

Pista csak esteledésig maradt otthon, aztán megrakodván


élelemmel és szalmával, visszaindult, de az erdőbe nem mert
behatolni, hanem a szélső faluk egyikében meghált.
Reggelre megszünt már az orkán, de a hótömeg oly nagy volt,
hogy egyes mélyedéseken lehetetlen volt átmenni, de a becsületes
falubeliek nagy csoportban indultak meg az erdőségnek, hogy a
«Kenyeretlen» csárdást éhen veszni ne hagyják, – s ámbár a sok
mélyedés adott elég dolgot, déltájban szerencsésen megnyítottak
minden gátot, és a hű barát a csárdához ért; de nagyot csudálkozott,
midőn azt egészen megnépesedve találta.
Megösmerték egymást, mindenik örvendett a viszontlátásnak, s
midőn az első kérdezkedéseken átestek, a szabados félre hívta
Pistát.
– Pajtás! megvan még az írás, mit a kórházban átadtam?
– Megtartottam eddig.
– Barátom! – szólal meg újra a szabados, – nagyon elfáradtam
már e földön – s míg ez a bűn rajtam fekszik, nem tudok elvergődni
a más világra, – azért, ha hazatérsz, az öreg Baltaynak mutasd meg
az írást.
– Korán lesz még, Józsi!
– Láttál már engemet szaladni? – kérdé büszkén a szabados.
– Sem én, sem más! – nyugtatja meg őt a másik, megfogván
bajtársának kezét.
– Lásd, Pista, szebb úgy meghalni, ha a halálnak magam
megyek szemközt.
– Tehát mit cselekedjem?
– Add át az öregnek az írást, most már talán ő is közelebb áll
oda, hova haragos képpel belépni nem engednek senkit, mondd,
hogy bocsásson meg!
– Hisz itt van a csárdában.
– Nem bántom, – mondja a szabados, – tudom, régen örült
ennyit; minek rikassam meg?
– A mint te akarod, pajtás, – nyugtatja meg amaz, – tehát
hazamenet.
Pista kocsiját a fiatalabb urak foglalák el és az öreg András, a
másikon pedig a nők és Baltay foglalának helyet, hogy estére még
Keszthelyre érjenek.
Az elválás előtt beszólíták a szabadost s a gróf kérdi tőle:
– Édes jó barátom, adósok nem akarunk maradni! – mondja, egy
erszényt húzva ki, melyben aranyok valának, – de a szabados
hunyászkodás vagy kevélység nélkül mondja:
– Méltóságos uram, én sem fizetek senkinek, nekem sem fizet
senki.
– De tőlünk mégis elveszen valamit.
– Semmit sem, méltóságos uram! Mi haszonra is adná, elkölteni
úgy sem tudnám, maradékom nincsen, veszendőnek pedig kár volna
itt hagyni.
– Barátom, – unszolá a grófné, – gyermekem boldogságát e
helyen értem meg.
– Adós voltam vele; – mondja hirtelen a szabados, látván, hogy
az öreg Baltay kiment, – mit Pista is észrevett, s a grófnak sietve
mondja.
– Hiába kinál ennek valamit, – méltóságos uram, – ez már ilyen
ember.
A gróf sajátszerűnek, de egyszersmind megmagyarázhatlannak
találván a dolgot, – nem unszolá tovább, hanem kezet szoríta vele,
mire aztán azt mondja a szabados:
– Egy kérésem volna méltóságos uram, ha szószólómmá lenne.
– Édes örömest – felel rögtön a gróf, – hadd hallom, mit kiván?
– A méltóságos asszonyságok kezeit szeretném megcsókolni, ha
tán megengednék.
A két hölgy örömmel nyújtá oda a kezét, s midőn mindkettőt
megcsókolá, a grófné érzé, hogy egy könycsepp csordult ki a rideg
ember szemeiből, mit a grófné nem tudott megérteni, azért
megilletődve kérdi:
– Barátom, könnyezik?
– Jól esik ez nekem, méltóságos asszonyom; mert akkor sem
tudtam sirni, mikor apámat temették.
Minden oly megfoghatatlan, hogy a család maradni szeretne, –
de bejött az öreg, s unszolja őket a menésre, minek az a sikere lőn,
hogy egy bucsúköszöntés után a nők és a gróf kimenének. Baltay
pedig azt mondja a szabadosnak:
– Nem feledkeztem el, becsületes ember; – hanem addig is isten
velünk, hadd szorítom meg a kezét.
– Nem lehet, nagyságos uram, nem érdemlettem meg.
– A patvarba, – kinek szoríthatnám meg a kezét szivesebben,
mint a kendét?
– Nagyságos uram, – várjuk meg a holnapi napot.
– De én most menni akarok s holnapig nem várok.
– Nem tartóztatom a nagyságos urat, – huzakodék a szabados, –
hanem holnap ilyenkor gondoljon rám, és ha akkor azt gondolja, a
mit most, nékem annyi, mintha kezet szorítana velem.
– Holnap is csak azt gondolom, a mit ma!
– Megtudom én azt is, – hanem éppen azért várjuk el a holnapi
napot.
– Na, legyen! – mondja Baltay; – agyafurt ember kend, – hanem
azért derék ember, ezt én mondom, Baltay.
– Bárcsak holnap is azt mondaná, nagyságos uram.
– Jó éjszakát! – búcsúzik Baltay; – tehát holnap ilyenkor
egymásra gondolunk.
– Azért jót állok, hogy nem feledjük el egymást, – végzi be a szót
a szabados, aztán pedig kiállt a csárda elejére s a távozó kocsik
után nézett mindaddig, míg az erdőnyilásból ki nem tértek, aztán
pedig a kályha szája elé ült le, folytatta a munkát: nézte a kályhában
a tüzet s mintha összeszámolt volna a világgal, könnyebbült kebellel
piszkálta az izzó szenet, s újra lerajzolódának emlékében az egykori
csaták, melyeket látni alig lesz már többé alkalma: de a régiekből
valamit feledni nem tud és nem akar.
Tán én is találtam volna egy bitófát, hová ezt az embert
kiköthetném s hű maradtam volna a nagy világ büntető törvényéhez,
mely addig nem talál megnyugvást, míg a bűnöst agyon nem veri.
Oh, mily érdekes olvasmány, látni egy embert, kinek lelkét az író
végighúzkodja a sáron, aztán pedig kilöki a szemétre, hogy még
több undokság ragadjon rá s mikor már egészen bizonyos, hogy
minden jó gyomrú ember megundorodik tőle, a szellemdús író
készen van elmondani azt, mi a varjúknak dobatik, – hisz mi köze
hozzá az írónak, hogy a tolvajt fel szokták kötni, – ő megtette a
magáét, földhöz verte a lelket, a testet miért kimélnék? – a közönség
érdekes olvasmányt akar, – ime, nyársba van már húzva egy ember,
tisztelt olvasó közönség, tessék ordítani!
A húsz esztendős gyermek egy bolond órájában elvét egy lépést,
nincsen ember, ki utána nyúljon, hogy negyven-ötven esztendőnek
megmentse. Minek is! megbotlott vagy szántszándékkal esett el,
mindegy: kötözd meg. Ha ló lenne, s a lovat megcsipné egy légy és
kínjában kirugván, a kocsist is eléri, összeszamarazzák a kocsist, s
a ló – abrakot kap megint. – A pénzdarab leesik, felveszik a porból,
lefujják róla a port, zsebre teszik megint, – senki sem emlegeti
többé, hogy elesett; – csak az embert lökik vissza a sárba; – egygyel
több vagy kevesebb – az mindegy!
Utálom e lelketlen eljárást, s ha már a többség ilyen bolond,
tegyünk kivételt is, bizony-bizony ráértünk már egyszer.
Mire beesteledett volna végképen, Keszthelyre értek a vendégek.
Festetics a kocsizörejre lesietett s a nagy lépcsőhöz érve bámult
el, midőn a haragos atyafiakat együtt jönni látta, – azonban nem
sokáig késtek a megmagyarázással, s általános öröm lőn a
keszthelyi kastélyban.
Másnap reggel együtt reggelizett a család. András az
előteremben beszélgetett Pistával, kit a gróf felkéretett, mert hitte,
hogy a «Kenyeretlen» csárdának lakójáról többet tud mondani, –
különösen pedig azt akarta tudni, miért volna adósa nejének még
boldogságával is?
A reggelizés után Baltay kezét a grófnak nyujtván, átment saját
szobájába, hová András Pistát vezette be.
– Mi jót hozott, édes barátom? – kérdi nagy szivességgel az
öreg.
– Ezt a kis papirdarabot hoztam el, nagyságos uram, – mondja
Pista, – most már nincs mit titkolódznom, tessék elolvasni.
Baltay elhalaványult, valamint a gróf is, és az öreg remegő kézzel
nyult a papiros után, mely jól megöregedett, mióta Pista tartogatta;
hanem azért a belseje tisztán olvasható s az öreg úr elolvasta a
vallomást.
– Ki írta alá mint tanú? – kérdi az öreg.
– Én és a kórházi felügyelő, – felel Pista, – hisz ott van az én
nevem mellett a főorvosé, tisztán ki van írva.
– Semmi kétség! – mondja az öreg, – a főorvos kezeírását
ösmerem, ő általa tudtam meg, hogy a pör a körmendi levéltárban
van letéve.
– A másik tanú pedig én vagyok.
– S a ki megölte?
– Ott a neve, nagyságos uraim, – a boldogtalan nekem szánta a
golyót és az úrfit találta el!
– Bocsásson meg neki a jó isten, én nem átkozhatom el.
– Nagyságos uram! – mondja Pista, – én még más szót is várok.
– Mit mondjak még, édes jó barátom?
– Hogy nemcsak nem átkozza el, de meg is bocsát neki.
– Tehát megbocsátok neki!
– Tüstént megyek, nagyságos uram, megviszem neki ezt a
vigasztalást.
– És még élne ez az ember?
– Tegnap valamennyien vendégei voltunk a csárdában,
nagyságos uram!
– Az a sánta ember?
– Kit úgy vert meg a sors, hogy az enyém helyett az ő lábát vágta
el az orvos, – mondja Pista, egyszersmind elbeszélvén az egész
dolgot, mint a hogy az Pécsett megtörtént velük.
– Úgy ez az az ember, kivel a hadjáratban az erdőnyilásban
álltak? kérdi a gróf.
– Ott kaptuk a sebeket s az ágyúzás után kerültünk kórházba.
– Nem avatkozom az isten dolgába, – mondja az öreg, – látom,
büntető keze hamarabb elérte, mint én tudtam volna; ha az ég
megelégelé e szenvedést, én meg is sokallom és megbocsátok neki.
– Isten velünk! – mondja Pista s egy negyed mulva már megint
az erdő felé tartott. Baltay nem birt megválni a gondolattól, mely
néhány óráig nyomta, de midőn újra visszaélte a multat s elért a
jelenig, mely boldogságot kinált öreg napjainak, lassankint
lemaradozott a bánat s a két fiatalnak boldogsága félretolta az utolsó
ködöt is.
Alkonyatkor utólszor emlékezék a dologról s midőn elérte azt a
pontot, mely a tegnapi órának ideje volt, a mogorva szabados arczát
maga előtt látta, – megérté, hogy e vad vonásokon az erő duzzadt ki
egykoron s bár nagyot hibázott egyszer a kéz, elszenvedte azt
százszor és megrettenés nélkül vádolja el magát.
– Derék ember! – mondja hangosan az öreg, bemenvén
kedvenczeihez, kik a háborítatlan látás boldog örömeit érzék, – míg
a szabados étlen-szomjan várta Pistát a csárda előtt, mert megigérte
Pista, hogy hírmondónak bármi későn megjön.
Az időnek rideg képe lassankint elhomályosodott, hanem még
tisztán látta az úton a fekete pontot, mely fához mérve mindinkább
közeleg s néhány óranegyed mulva megérkezett a nagy kínnal várt
vendég.
– Megbocsátott! – mondja Pista a szabadosnak, ki egy szót nem
tudott felelni, hanem állva maradt egy helyben, míg Pista gőzölgő
lovait a nyughelyre vezette s a nagy istállóban tüzet rakott, hogy
szegény párákat meg ne ölje majd a hideg.
Magunk is érezzük, hogy e pillanatban lehető legkevesebbet kell
mondanunk s magunk is habozunk, nem tudván megosztani e
fejezetet, melybe két különvált képet kell illesztenünk, – az egyik a
mogorva szabados, kit a bocsánat fogott le, a másik a boldog
család, melyből most már az öreg anya sem hiányzik, hanem
szerettei között ül, nem gondolván a multnak szenvedéseire, ajkára
nem fért egyetlen szemrehányás, hanem áhítatos buzgalommal
bámulta a gondviselés művét, mely a szétszakadt szálakat ily nem
várt módon illesztette össze.
Alakjainkkal nem fogunk többé találkozni, sorsuk most már nem
érdekel bennünket, – küzdelmük közben megérett az az eszme,
melyért tollat fogánk: az irodalom nem árva többé, hanem egy
harczos, mely eszméivel hódít.
Baltay hű maradt Kisfaludyjához; András megelégedett
önmagával, hisz ő azon emberek közé tartozott, kik nem várnak
dicséretet, – mert az igazságot gorombán is megmondja, ha máskép
meg nem hallgatják, – s midőn egyedül maradt, egyet ránt dolmánya
szárán, mi nála körülbelül annyit tesz, mintha valami nálánál is
külömb ember megveregetné a vállát.
Festetics végighallgatván a történetet, midőn Baltayval megint
végignézék a keszthelyi intézetet, elégülten mondja:
– Barátom! – a mi szerepünk eddig tart; a többi a fiatalok dolga.
*
Midőn a Bakony erdején oly sűrű lőn a falevél, hogy a
madárfészek elrejtőzködhetett, Pista megint az erdő felé megyen; de
lovait most már nem ereszté meg oly sebesen, mint máskor, hisz
nincsen, ki vendégképen várja, meghalt a kifáradt ember s ma már a
nyughely várakozik reá.
Pista néhány csonka vitézt rakott föl kocsira s ezekkel adta meg
a legutolsó tiszteletet, a hidegült tetemet visszaadván a földnek.
A csárdától nem messze, a forráshoz is közel kikereste a
legárnyékosabb helyet s elkészíté az öröktanyát, míg az ébredésnek
órája el nem jön.
Nem volt ének, nem volt búcsúztató; nem volt osztozkodó nép,
hogy a temetésről visszajövén, elosztozzék a maradékon és még
össze is marakodjanak az aprólékon, hol a gombostűt is
megválogatják, nehogy egygyel többet vagy jobbat hordjon el a
másik.
A legszebb hantokat válogatták s nyirfának ágából illesztettek
össze egy keresztet s a mező virágaiból még koszorú is került.
Ledült a fa, árnyéka sincs többé, elrothadt porát fogja majd csak
egykor széthordani a szél, messze, mindenfelé; ki szedi megint azt
össze?
A hitetlennek nagyobb kínja nem lehet végórájában, mint hogy a
léleknek halhatatlanságát nem meri elhinni, pedig de szívesen
elhinné!
Higyjetek és üdvözülni fogtok!
XII.
(Fele enyém, fele meg tied.)

Olvasóm lámpája elalvófélben van, tán nem is látja meg a vékony


fonalat, melynek vége mindjárt kezembe jő, pedig még egy csomót
kell eloldanom, s még egyszer meghurczolom azt a türelmet, mely e
fonaleregetést három köteten keresztül végigvárni tudta.
Még egyszer keressük föl az egykori bérest, kitől láttatlanban
magam sem tudnék elbúcsúzni, ki tán mai napig is csak olyan erős,
mint az ozorai búcsún, csakhogy a ki izengetne neki, a föld alatt
nyugszik már.
Sümeg felől jön a grófi fogat, a négy táltos tajtékot ver az úton, s
Holvagy Pistának lakása előtt száll ki a kocsiból Kisfaludy Sándor, s
a gazdát az udvaron találja.
– Megint látjuk egymást! – mondja Kisfaludy, megszorítván a
megkeresett jobbot.
– Hála legyen érte a felséges úristennek, – válaszol rá Pista.
– Gondolja-e, miért jöttem ily sebes vágtatást?
– Ellenséget nem láttam erre jönni, – véli Pista, – különben azt
hinném, hogy vitéz őrnagy uram talán ellenséget hajtott.
– Budáról jövök, még pedig egyenesen a nádor ő fönségétől.
– Bizony odáig is hosszú az út, hát még onnét vissza! – üres
kocsinak is elég.
– Én pedig nem jöttem üresen! mondja Kisfaludy.
– Okos embernek a fejében is elég hordani valója van.
– Emlékszik-e barátom azon napra, midőn az erdőszélen
legelőször láttuk egymást?
– Egy kicsit emlékszem még az ágyúszóról, – mondja a másik, –
egy pár ágyút elsütöttek ránk emlékezet okáért.
– No hát, hogy még bizonyosabban megemlékezzék, kedves jó
barátom, – mondja Kisfaludy, oldalzsebébe nyúlva, – ime ez arany
érdempénz, ezt a nádor küldi.
Kisfaludy a bámuló embernek mellére tűzte az érdempénzt, s az
egyszerű embert oly remegés fogta el, mintha éppen most állítanák
szemközt azon ágyúkkal, melyeket egykor az erdőszélen rájok
sütögettek, s mintha a mellére azért tennének olyan fényes
aranykarikát, hogy az ágyúsütögetők odalőhessenek.
Míg Kisfaludy a feltűzéssel vesződött, a ház népe összeszaladt,
előbb a kapu mellől bámulták a dolgot, később megközelíték őket,
utóbb a férfiak levett kalappal álltak meg, utoljára pedig egyik sem
tudta megállni a sirást, hanem megeresztette a könyűt, mely
törületlenül folydogált le, s midőn még közelebb mertek jőni, Pista
kinyujtá kezét, melyet sorban szorongattak, és ránéztek a tündöklő
pénzre, melyért az ágyúk közé kell napszámba menni, s mit nem
szokás apróbbra váltani, mert ilyen mellett éhen is szivesen
meghalhat az ember.
Tudta az egyszerű nép, hogy azt a csillogó aranyat azért tették a
mellére, hogy az nem a költőpénz közé való s milyen szépen odaillik
a széles mellre, legalább mikor a gazda nagy ünnepen második
harangszóra szentegyházba indul, jobbról-balról kitér a sok ember,
és még a szentegyházban is a legelső padig eresztik, hogy minden
ember lássa példának okáért!
Mire föltűzte Kisfaludy az érdempénzt, a hátulsók közül kiszalad
egy surjány legény az utczára s minden arra menőt becsődített,
hogy a nagy becsületnek több nézője legyen. Pista pedig még
mindig egy helyben állt, mint a gyermek, kit husvétnapra öltöztet az
anyja.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like