diff --git a/doc/opencv_tutorials.pdf b/doc/opencv_tutorials.pdf new file mode 100644 index 0000000000..0d8be941c2 Binary files /dev/null and b/doc/opencv_tutorials.pdf differ diff --git a/doc/opencv_tutorials.tex b/doc/opencv_tutorials.tex new file mode 100644 index 0000000000..2ed515e42c --- /dev/null +++ b/doc/opencv_tutorials.tex @@ -0,0 +1,107 @@ +\documentclass[11pt]{book} + +\usepackage{cite} +\usepackage[pdftex]{graphicx} +\usepackage{titlesec} +\usepackage{listings} +\usepackage{fancyvrb} +\usepackage[svgnames]{xcolor} +\usepackage{framed} +\usepackage{amsmath} +\usepackage{amssymb} +\usepackage{bbm} +\usepackage{hyperref} +\usepackage{makeidx} +\usepackage{color} +\usepackage{verbatim} + +\setcounter{secnumdepth}{1} + +\definecolor{shadecolor}{gray}{0.95} % Background color of title bars +\lstset{ +language=C, +basicstyle=\small\ttfamily, +backgroundcolor=\color{shadecolor} +} + +\definecolor{cvlinkcolor}{rgb}{0.0 0.3 0.8} + +% taken from http://en.wikibooks.org/wiki/LaTeX/Hyperlinks +\hypersetup{ + bookmarks=true, % show bookmarks bar? + unicode=false, % non-Latin characters in Acrobat’s bookmarks + %pdftoolbar=true, % show Acrobat’s toolbar? + %pdfmenubar=true, % show Acrobat’s menu? + %pdffitwindow=false, % window fit to page when opened + %pdfstartview={FitH}, % fits the width of the page to the window + %pdftitle={My title}, % title + %pdfauthor={Author}, % author + %pdfsubject={Subject}, % subject of the document + %pdfcreator={Creator}, % creator of the document + %pdfproducer={Producer}, % producer of the document + %pdfkeywords={keywords}, % list of keywords + %pdfnewwindow=true, % links in new window + colorlinks=true, % false: boxed links; true: colored links + linkcolor=cvlinkcolor, % color of internal links + citecolor=cvlinkcolor, % color of links to bibliography + filecolor=magenta, % color of file links + urlcolor=cyan % color of external links +} + +\makeindex + +\newcommand{\piRsquare}{\pi r^2} % This is my own macro !!! + +\usepackage{helvetica} +\usepackage{ifthen} +\usepackage{alltt} +\usepackage{opencv} + +%%% Margins %%% +\oddsidemargin 0.0in +\evensidemargin 0.0in +\textwidth 6.5in +%\headheight 1.0in +%\topmargin 0.5in +%\textheight 9.0in +%\footheight 1.0in +%%%%%%%%%%%%%%% + +\title{OpenCV Tutorials} % used by \maketitle +\author{v2.2} % used by \maketitle +\date{February, 2011} % used by \maketitle + +\begin{document} +\maketitle % automatic title! + +\setcounter{tocdepth}{8} +\tableofcontents + +\titleformat{\subsection} +{\titlerule +\vspace{.8ex}% +\normalfont\bfseries\Large} +{\thesection.}{.5em}{} + +%%% Define these to get rid of warnings +\def\genc{true} +\def\genpy{true} +\def\gencpp{true} + +\newif\ifC +\newif\ifPy +\newif\ifCpp +\newif\ifCPy + +\Cfalse +\Cpptrue +\Pyfalse +\CPyfalse +\def\targetlang{cpp} +\part{C++ API tutorials} +\input{tutorials/opencv_tutorials_body} + +\addcontentsline{toc}{part}{Index} +\printindex + +\end{document} % End of document. diff --git a/doc/tutorials/calib3d.tex b/doc/tutorials/calib3d.tex new file mode 100644 index 0000000000..d6e9ce8a53 --- /dev/null +++ b/doc/tutorials/calib3d.tex @@ -0,0 +1,56 @@ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% C++ % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\ifCpp +\section{Camera calibration} +The goal of this tutorial is to learn how to calibrate a camera given a set of chessboard images. + +\texttt{Test data}: use images in your data/chess folder. + +Compile opencv with samples by setting BUILD\_EXAMPLES to ON in cmake configuration. + +Go to bin folder and use \texttt{imagelist\_creator} to create an xml/yaml list of your images. Then, run \texttt{calibration} sample to get camera parameters. Use square size equal to 3cm. + +\section{Pose estimation} +Now, let us write a code that detects a chessboard in a new image and finds its distance from the camera. You can apply the same method to any object with knwon 3d geometry that you can detect in an image. + +\texttt{Test data}: use chess\_test*.jpg images from your data folder. + +Create an empty console project. Load a test image: +\begin{lstlisting} +Mat img = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE); +\end{lstlisting} + +Detect a chessboard in this image using findChessboard function. +\begin{lstlisting} +bool found = findChessboardCorners( img, boardSize, ptvec, CV_CALIB_CB_ADAPTIVE_THRESH ); +\end{lstlisting} + +Now, write a function that generates a \texttt{vector} array of 3d coordinates of a chessboard in any coordinate system. For simplicity, let us choose a system such that one of the chessboard corners is in the origin and the board is in the plane \(z = 0\). + +Read camera parameters from xml/yaml file: +\begin{lstlisting} +FileStorage fs(filename, FileStorage::READ); +Mat intrinsics, distortion; +fs["camera_matrix"] >> intrinsics; +fs["distortion_coefficients"] >> distortion; +\end{lstlisting} + +Now we are ready to find chessboard pose by running solvePnP: +\begin{lstlisting} +vector boardPoints; +// fill the array +... + +solvePnP(Mat(boardPoints), Mat(foundBoardCorners), cameraMatrix, + distCoeffs, rvec, tvec, false); +\end{lstlisting} + +Calculate reprojection error like it is done in \texttt{calibration} sample (see textttt{opencv/samples/cpp/calibration.cpp}, function \texttt{computeReprojectionErrors}). + +How to calculate the distance from the camera origin to any of the corners? +\fi \ No newline at end of file diff --git a/doc/tutorials/features2d.tex b/doc/tutorials/features2d.tex new file mode 100644 index 0000000000..6d0a4c5441 --- /dev/null +++ b/doc/tutorials/features2d.tex @@ -0,0 +1,67 @@ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% C++ % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\ifCpp +\section{Detection of planar objects} +The goal of this tutorial is to learn how to use features2d and calib3d modules for detecting known planar objects in scenes. + +\texttt{Test data}: use images in your data folder, for instance, box.png and box\_in\_scene.png. + +Create a new console project. Read two input images. Example: +\begin{lstlisting} +Mat img1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE); +\end{lstlisting} + +Detect keypoints in both images. Example: +\begin{lstlisting} +// detecting keypoints +FastFeatureDetector detector(15); +vector keypoints1; +detector.detect(img1, keypoints1); +\end{lstlisting} + +Compute descriptors for each of the keypoints. Example: +\begin{lstlisting} +// computing descriptors +SurfDescriptorExtractor extractor; +Mat descriptors1; +extractor.compute(img1, keypoints1, descriptors1); +\end{lstlisting} + +Now, find the closest matches between descriptors from the first image to the second: +\begin{lstlisting} +// matching descriptors +BruteForceMatcher > matcher; +vector matches; +matcher.match(descriptors1, descriptors2, matches); +\end{lstlisting} + +Visualize the results: +\begin{lstlisting} +// drawing the results +namedWindow("matches", 1); +Mat img_matches; +drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches); +imshow("matches", img_matches); +waitKey(0); +\end{lstlisting} + +Find the homography transformation between two sets of points: +\begin{lstlisting} +vector points1, points2; +// fill the arrays with the points +.... +Mat H = findHomography(Mat(points1), Mat(points2), CV_RANSAC, ransacReprojThreshold); +\end{lstlisting} + +Create a set of inlier matches and draw them. Use perspectiveTransform function to map points with homography: +\begin{lstlisting} +Mat points1Projected; +perspectiveTransform(Mat(points1), points1Projected, H); +\end{lstlisting} +Use drawMatches for drawing inliers. +\fi \ No newline at end of file diff --git a/doc/tutorials/opencv_tutorials_body.tex b/doc/tutorials/opencv_tutorials_body.tex new file mode 100644 index 0000000000..e8b45df015 --- /dev/null +++ b/doc/tutorials/opencv_tutorials_body.tex @@ -0,0 +1,12 @@ +\chapter{Prerequisites} +\renewcommand{\curModule}{Prerequisites} +\input{tutorials/prerequisites} + + +\chapter{Features2d} +\renewcommand{\curModule}{Features2d} +\input{tutorials/features2d} + +\chapter{Calib3d} +\renewcommand{\curModule}{Calib3d} +\input{tutorials/calib3d} diff --git a/doc/tutorials/prerequisites.tex b/doc/tutorials/prerequisites.tex new file mode 100644 index 0000000000..3ed1cb4c0f --- /dev/null +++ b/doc/tutorials/prerequisites.tex @@ -0,0 +1,12 @@ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% C++ % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\ifCpp +\section{Prerequisites} +Download the latest release of opencv from \url{http://sourceforge.net/projects/opencvlibrary/}. You will need cmake and your favorite compiler environment in order to build opencv from sources. Please refer to the installation guide \url{http://opencv.willowgarage.com/wiki/InstallGuide} for detailed instructions. + +\fi \ No newline at end of file