Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
OpenCV By Example

You're reading from  OpenCV By Example

Product type Book
Published in Jan 2016
Publisher Packt
ISBN-13 9781785280948
Pages 296 pages
Edition 1st Edition
Languages
Authors (3):
Prateek Joshi Prateek Joshi
Profile icon Prateek Joshi
David Millán Escrivá David Millán Escrivá
Profile icon David Millán Escrivá
Vinícius G. Mendonça Vinícius G. Mendonça
Profile icon Vinícius G. Mendonça
View More author details

Table of Contents (18) Chapters

OpenCV By Example
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Getting Started with OpenCV An Introduction to the Basics of OpenCV Learning the Graphical User Interface and Basic Filtering Delving into Histograms and Filters Automated Optical Inspection, Object Segmentation, and Detection Learning Object Classification Detecting Face Parts and Overlaying Masks Video Surveillance, Background Modeling, and Morphological Operations Learning Object Tracking Developing Segmentation Algorithms for Text Recognition Text Recognition with Tesseract Index

The preprocessing step


Software that identifies letters do so by comparing text with a previously recorded data. Classification results can be improved greatly if the input text is clear, if the letters are in a vertical position, and if there are no other elements, such as images that are sent to the classification software. In this section, we'll learn how to adjust text. This stage is called preprocessing.

Thresholding the image

We usually start the preprocessing stage by thresholding the image. This eliminates all the color information. Most OpenCV functions require information to be the written in white and the background to be black. So, let's start with creating a threshold function to match this criterion:

#include <opencv2/opencv.hpp>
#include <vector>

using namespace std;
using namespace cv;

Mat binarize(Mat input)
{
  //Uses otsu to threshold the input image
  Mat binaryImage;
  cvtColor(input, input, CV_BGR2GRAY);
  threshold(input, binaryImage, 0, 255, THRESH_OTSU...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}