1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

converted user guide & tutorials from tex to rst; added them into the whole documentation tree; added html_docs target.

This commit is contained in:
Vadim Pisarevsky
2011-05-10 22:09:07 +00:00
parent 6facf8ba3b
commit b699e946b5
75 changed files with 1506 additions and 2120 deletions
+64
View File
@@ -0,0 +1,64 @@
#######
Calib3D
#######
.. highlight:: cpp
Camera calibration
==================
The goal of this tutorial is to learn how to calibrate a camera given a set of chessboard images.
*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 ``imagelist_creator`` to create an ``XML/YAML`` list of your images.
#.
Then, run ``calibration`` sample to get camera parameters. Use square size equal to 3cm.
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 known 3D geometry that you can detect in an image.
*Test data*: use chess_test*.jpg images from your data folder.
#.
Create an empty console project. Load a test image: ::
Mat img = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
#.
Detect a chessboard in this image using findChessboard function. ::
bool found = findChessboardCorners( img, boardSize, ptvec, CV_CALIB_CB_ADAPTIVE_THRESH );
#.
Now, write a function that generates a ``vector<Point3f>`` 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: ::
FileStorage fs(filename, FileStorage::READ);
Mat intrinsics, distortion;
fs["camera_matrix"] >> intrinsics;
fs["distortion_coefficients"] >> distortion;
#.
Now we are ready to find chessboard pose by running ``solvePnP``: ::
vector<Point3f> boardPoints;
// fill the array
...
solvePnP(Mat(boardPoints), Mat(foundBoardCorners), cameraMatrix,
distCoeffs, rvec, tvec, false);
#.
Calculate reprojection error like it is done in ``calibration`` sample (see ``opencv/samples/cpp/calibration.cpp``, function ``computeReprojectionErrors``).
Question: how to calculate the distance from the camera origin to any of the corners?
-56
View File
@@ -1,56 +0,0 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% 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<Point3f>} 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<Point3f> 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
+74
View File
@@ -0,0 +1,74 @@
##########
Features2D
##########
.. highlight:: cpp
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.
*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. ::
Mat img1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
#.
Detect keypoints in both images. ::
// detecting keypoints
FastFeatureDetector detector(15);
vector<KeyPoint> keypoints1;
detector.detect(img1, keypoints1);
... // do the same for the second image
#.
Compute descriptors for each of the keypoints. ::
// computing descriptors
SurfDescriptorExtractor extractor;
Mat descriptors1;
extractor.compute(img1, keypoints1, descriptors1);
... // process keypoints from the second image as well
#.
Now, find the closest matches between descriptors from the first image to the second: ::
// matching descriptors
BruteForceMatcher<L2<float> > matcher;
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);
#.
Visualize the results: ::
// drawing the results
namedWindow("matches", 1);
Mat img_matches;
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
imshow("matches", img_matches);
waitKey(0);
#.
Find the homography transformation between two sets of points: ::
vector<Point2f> points1, points2;
// fill the arrays with the points
....
Mat H = findHomography(Mat(points1), Mat(points2), CV_RANSAC, ransacReprojThreshold);
#.
Create a set of inlier matches and draw them. Use perspectiveTransform function to map points with homography:
Mat points1Projected;
perspectiveTransform(Mat(points1), points1Projected, H);
#.
Use ``drawMatches`` for drawing inliers.
-67
View File
@@ -1,67 +0,0 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% 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<KeyPoint> 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<L2<float> > matcher;
vector<DMatch> 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<Point2f> 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
-12
View File
@@ -1,12 +0,0 @@
\chapter{Prerequisites}
\renewcommand{\curModule}{Prerequisites}
\input{tutorials/prerequisites}
\chapter{Features2d}
\renewcommand{\curModule}{Features2d}
\input{tutorials/features2d}
\chapter{Calib3d}
\renewcommand{\curModule}{Calib3d}
\input{tutorials/calib3d}
+5
View File
@@ -0,0 +1,5 @@
#############
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.
-12
View File
@@ -1,12 +0,0 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% 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
+10
View File
@@ -0,0 +1,10 @@
#################
OpenCV Tutorials
#################
.. toctree::
:maxdepth: 2
prerequisites.rst
features2d.rst
calib3d.rst