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

Reading/writing images


After the introduction of this matrix, we are going to start with the basics of the OpenCV code. Firstly, we need to learn how to read and write images:

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

// OpenCV includes
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;

int main( int argc, const char** argv )
{
  // Read images
  Mat color= imread("../lena.jpg");
  Mat gray= imread("../lena.jpg", 0);
  
  // Write images
  imwrite("lenaGray.jpg", gray);
  
  // Get same pixel with opencv function
  int myRow=color.cols-1;
  int myCol=color.rows-1;
  Vec3b pixel= color.at<Vec3b>(myRow, myCol);
  cout << "Pixel value (B,G,R): (" << (int)pixel[0] << "," << (int)pixel[1] << "," << (int)pixel[2] << ")" << endl;
  
  // show images
  imshow("Lena BGR", color);
  imshow("Lena Gray", gray);
  // wait for any key press
  waitKey(0);
  return 0;...
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}