<script src="utils.js" type="text/javascript"></script>
<script id="codeSnippet" type="text/code-snippet">
let src = cv.imread('canvasInput');
-let dst = cv.Mat.zeros(src.rows, src.cols, cv.CV_8U);
+let dst = cv.Mat.zeros(src.rows, src.cols, cv.CV_8UC3);
let lines = new cv.Mat();
cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0);
cv.Canny(src, src, 50, 200, 3);
<script src="utils.js" type="text/javascript"></script>
<script id="codeSnippet" type="text/code-snippet">
let src = cv.imread('canvasInput');
-let dst = cv.Mat.zeros(src.rows, src.cols, cv.CV_8U);
+let dst = cv.Mat.zeros(src.rows, src.cols, cv.CV_8UC3);
let lines = new cv.Mat();
let color = new cv.Scalar(255, 0, 0);
cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0);
The first thing consists to detect the chessboard corners, the chessboard size (`patternSize`), here `9x6`, is required:
-@snippet tutorial_homography_ex1_pose_from_homography.cpp find-chessboard-corners
+@snippet pose_from_homography.cpp find-chessboard-corners
![](images/homography_pose_chessboard_corners.jpg)
The object points expressed in the object frame can be computed easily knowing the size of a chessboard square:
-@snippet tutorial_homography_ex1_pose_from_homography.cpp compute-chessboard-object-points
+@snippet pose_from_homography.cpp compute-chessboard-object-points
The coordinate `Z=0` must be removed for the homography estimation part:
-@snippet tutorial_homography_ex1_pose_from_homography.cpp compute-object-points
+@snippet pose_from_homography.cpp compute-object-points
The image points expressed in the normalized camera can be computed from the corner points and by applying a reverse perspective transformation using the camera intrinsics and the distortion coefficients:
-@snippet tutorial_homography_ex1_pose_from_homography.cpp load-intrinsics
+@snippet pose_from_homography.cpp load-intrinsics
-@snippet tutorial_homography_ex1_pose_from_homography.cpp compute-image-points
+@snippet pose_from_homography.cpp compute-image-points
The homography can then be estimated with:
-@snippet tutorial_homography_ex1_pose_from_homography.cpp estimate-homography
+@snippet pose_from_homography.cpp estimate-homography
A quick solution to retrieve the pose from the homography matrix is (see \ref pose_ar "5"):
-@snippet tutorial_homography_ex1_pose_from_homography.cpp pose-from-homography
+@snippet pose_from_homography.cpp pose-from-homography
\f[
\begin{align*}
The first step consists to detect the chessboard corners in the source and desired images:
-@snippet tutorial_homography_ex2_perspective_correction.cpp find-corners
+@snippet perspective_correction.cpp find-corners
The homography is estimated easily with:
-@snippet tutorial_homography_ex2_perspective_correction.cpp estimate-homography
+@snippet perspective_correction.cpp estimate-homography
To warp the source chessboard view into the desired chessboard view, we use @ref cv::warpPerspective
-@snippet tutorial_homography_ex2_perspective_correction.cpp warp-chessboard
+@snippet perspective_correction.cpp warp-chessboard
The result image is:
To compute the coordinates of the source corners transformed by the homography:
-@snippet tutorial_homography_ex2_perspective_correction.cpp compute-transformed-corners
+@snippet perspective_correction.cpp compute-transformed-corners
To check the correctness of the calculation, the matching lines are displayed:
In this example, we will compute the camera displacement between two camera poses with respect to the chessboard object. The first step consists to compute the camera poses for the two images:
-@snippet tutorial_homography_ex3_homography_from_camera_displacement.cpp compute-poses
+@snippet homography_from_camera_displacement.cpp compute-poses
![](images/homography_camera_displacement_poses.jpg)
The camera displacement can be computed from the camera poses using the formulas above:
-@snippet tutorial_homography_ex3_homography_from_camera_displacement.cpp compute-c2Mc1
+@snippet homography_from_camera_displacement.cpp compute-c2Mc1
The homography related to a specific plane computed from the camera displacement is:
Here the normal vector `n` is the plane normal expressed in the camera frame 1 and can be computed as the cross product of 2 vectors (using 3 non collinear points that lie on the plane) or in our case directly with:
-@snippet tutorial_homography_ex3_homography_from_camera_displacement.cpp compute-plane-normal-at-camera-pose-1
+@snippet homography_from_camera_displacement.cpp compute-plane-normal-at-camera-pose-1
The distance `d` can be computed as the dot product between the plane normal and a point on the plane or by computing the [plane equation](http://mathworld.wolfram.com/Plane.html) and using the D coefficient:
-@snippet tutorial_homography_ex3_homography_from_camera_displacement.cpp compute-plane-distance-to-the-camera-frame-1
+@snippet homography_from_camera_displacement.cpp compute-plane-distance-to-the-camera-frame-1
The projective homography matrix \f$ \textbf{G} \f$ can be computed from the Euclidean homography \f$ \textbf{H} \f$ using the intrinsic matrix \f$ \textbf{K} \f$ (see @cite Malis), here assuming the same camera between the two plane views:
\textbf{G} = \gamma \textbf{K} \textbf{H} \textbf{K}^{-1}
\f]
-@snippet tutorial_homography_ex3_homography_from_camera_displacement.cpp compute-homography
+@snippet homography_from_camera_displacement.cpp compute-homography
In our case, the Z-axis of the chessboard goes inside the object whereas in the homography figure it goes outside. This is just a matter of sign:
^{2}\textrm{H}_{1} = \hspace{0.2em} ^{2}\textrm{R}_{1} + \hspace{0.1em} \frac{^{2}\textrm{t}_{1} \cdot n^T}{d}
\f]
-@snippet tutorial_homography_ex3_homography_from_camera_displacement.cpp compute-homography-from-camera-displacement
+@snippet homography_from_camera_displacement.cpp compute-homography-from-camera-displacement
We will now compare the projective homography computed from the camera displacement with the one estimated with @ref cv::findHomography
OpenCV 3 contains the function @ref cv::decomposeHomographyMat which allows to decompose the homography matrix to a set of rotations, translations and plane normals.
First we will decompose the homography matrix computed from the camera displacement:
-@snippet tutorial_homography_ex4_decompose_homography.cpp compute-homography-from-camera-displacement
+@snippet decompose_homography.cpp compute-homography-from-camera-displacement
The results of @ref cv::decomposeHomographyMat are:
-@snippet tutorial_homography_ex4_decompose_homography.cpp decompose-homography-from-camera-displacement
+@snippet decompose_homography.cpp decompose-homography-from-camera-displacement
```
Solution 0:
*/
CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
+/** @example pose_from_homography.cpp
+ An example program about pose estimation from coplanar points
+
+ Check @ref tutorial_homography "the corresponding tutorial" for more details
+ */
+
/** @brief Finds a perspective transformation between two planes.
@param srcPoints Coordinates of the points in the original plane, a matrix of the type CV_32FC2
@sa
getAffineTransform, estimateAffine2D, estimateAffinePartial2D, getPerspectiveTransform, warpPerspective,
perspectiveTransform
-
-
-@note
- - A example on calculating a homography for image matching can be found at
- opencv_source_code/samples/cpp/video_homography.cpp
-
*/
CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints,
int method = 0, double ransacReprojThreshold = 3,
OutputArray jacobian = noArray(),
double aspectRatio = 0 );
+/** @example homography_from_camera_displacement.cpp
+ An example program about homography from the camera displacement
+
+ Check @ref tutorial_homography "the corresponding tutorial" for more details
+ */
+
/** @brief Finds an object pose from 3D-2D point correspondences.
@param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or
#include <opencv2/objdetect.hpp>
#include <stdio.h>
-#include <string>
-#include <vector>
using namespace std;
using namespace cv;
do
{
VideoStream >> ReferenceFrame;
- cvtColor(ReferenceFrame, GrayFrame, COLOR_RGB2GRAY);
+ cvtColor(ReferenceFrame, GrayFrame, COLOR_BGR2GRAY);
Detector.process(GrayFrame);
Detector.getObjects(Faces);
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
Mat src, dst;
const char* equalized_window = "Equalized Image";
/// Load image
- src = imread( argv[1], IMREAD_COLOR );
-
+ CommandLineParser parser( argc, argv, "{@input | ../data/lena.jpg | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
if( src.empty() )
- { cout<<"Usage: ./EqualizeHist_Demo <path_to_image>"<<endl;
- return -1;
- }
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
+ return -1;
+ }
/// Convert to grayscale
cvtColor( src, src, COLOR_BGR2GRAY );
*/
#include "opencv2/imgproc.hpp"
-#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
+#include <iostream>
using namespace cv;
+using namespace std;
/// Global variables
Mat src, erosion_dst, dilation_dst;
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
/// Load an image
- src = imread( argv[1], IMREAD_COLOR );
-
+ CommandLineParser parser( argc, argv, "{@input | ../data/chicky_512.png | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
if( src.empty() )
- { return -1; }
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
+ return -1;
+ }
/// Create windows
namedWindow( "Erosion Demo", WINDOW_AUTOSIZE );
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
+#include <iostream>
using namespace cv;
int main( int argc, char** argv )
{
//![load]
- String imageName("../data/baboon.jpg"); // by default
- if (argc > 1)
+ CommandLineParser parser( argc, argv, "{@input | ../data/baboon.jpg | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
+ if (src.empty())
{
- imageName = argv[1];
+ std::cout << "Could not open or find the image!\n" << std::endl;
+ std::cout << "Usage: " << argv[0] << " <Input image>" << std::endl;
+ return -1;
}
- src = imread(imageName, IMREAD_COLOR); // Load an image
-
- if( src.empty() )
- { return -1; }
//![load]
//![window]
using namespace std;
using namespace cv;
-int main(int, char** argv)
+int main(int argc, char** argv)
{
//! [load_image]
- // Load the image
- Mat src = imread(argv[1]);
-
- // Check if image is loaded fine
- if(src.empty()){
- printf(" Error opening image\n");
- printf(" Program Arguments: [image_path]\n");
+ CommandLineParser parser(argc, argv, "{@input | ../data/notes.png | input image}");
+ Mat src = imread(parser.get<String>("@input"), IMREAD_COLOR);
+ if (src.empty())
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
return -1;
}
*/
#include "opencv2/imgproc.hpp"
-#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
+#include <iostream>
using namespace cv;
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
//![load]
- src = imread( argv[1], IMREAD_COLOR ); // Load an image
+ CommandLineParser parser( argc, argv, "{@input | ../data/fruits.jpg | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR ); // Load an image
if( src.empty() )
- { return -1; }
+ {
+ std::cout << "Could not open or find the image!\n" << std::endl;
+ std::cout << "Usage: " << argv[0] << " <Input image>" << std::endl;
+ return -1;
+ }
//![load]
//![create_mat]
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
Point2f srcTri[3];
Point2f dstTri[3];
Mat src, warp_dst, warp_rotate_dst;
/// Load the image
- src = imread( argv[1], IMREAD_COLOR );
+ CommandLineParser parser( argc, argv, "{@input | ../data/lena.jpg | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
+ if( src.empty() )
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
+ return -1;
+ }
/// Set the dst image the same type and size as src
warp_dst = Mat::zeros( src.rows, src.cols, src.type() );
int main(int argc, char** argv)
{
//![load]
- const char* filename = argc >=2 ? argv[1] : "../../../data/smarties.png";
+ const char* filename = argc >=2 ? argv[1] : "../data/smarties.png";
// Loads an image
Mat src = imread( filename, IMREAD_COLOR );
Mat dst, cdst, cdstP;
//![load]
- const char* default_file = "../../../data/sudoku.png";
+ const char* default_file = "../data/sudoku.png";
const char* filename = argc >=2 ? argv[1] : default_file;
// Loads an image
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
//![setup]
/// Load source image
- src = imread( argv[1], IMREAD_COLOR );
+ CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
+ if( src.empty() )
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "usage: " << argv[0] << " <Input image>" << endl;
+ return -1;
+ }
/// Convert image to gray and blur it
cvtColor( src, src_gray, COLOR_BGR2GRAY );
//![allthework]
for( size_t i = 0; i < contours.size(); i++ )
{
- approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
- boundRect[i] = boundingRect( Mat(contours_poly[i]) );
+ approxPolyDP( contours[i], contours_poly[i], 3, true );
+ boundRect[i] = boundingRect( contours_poly[i] );
minEnclosingCircle( contours_poly[i], center[i], radius[i] );
}
//![allthework]
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
/// Load source image and convert it to gray
- src = imread( argv[1], IMREAD_COLOR );
+ CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
+ if( src.empty() )
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
+ return -1;
+ }
/// Convert image to gray and blur it
cvtColor( src, src_gray, COLOR_BGR2GRAY );
vector<RotatedRect> minEllipse( contours.size() );
for( size_t i = 0; i < contours.size(); i++ )
- { minRect[i] = minAreaRect( Mat(contours[i]) );
+ { minRect[i] = minAreaRect( contours[i] );
if( contours[i].size() > 5 )
- { minEllipse[i] = fitEllipse( Mat(contours[i]) ); }
+ { minEllipse[i] = fitEllipse( contours[i] ); }
}
/// Draw contours + rotated rects + ellipses
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
/// Load source image and convert it to gray
- src = imread( argv[1], IMREAD_COLOR );
+ CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
+ if( src.empty() )
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
+ return -1;
+ }
/// Convert image to gray and blur it
cvtColor( src, src_gray, COLOR_BGR2GRAY );
/// Find the convex hull object for each contour
vector<vector<Point> >hull( contours.size() );
for( size_t i = 0; i < contours.size(); i++ )
- { convexHull( Mat(contours[i]), hull[i], false ); }
+ { convexHull( contours[i], hull[i], false ); }
/// Draw contours + hull results
Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
/// Load source image and convert it to gray
- src = imread( argv[1], IMREAD_COLOR );
+ CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
+
+ if( src.empty() )
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "usage: " << argv[0] << " <Input image>" << endl;
+ exit(0);
+ }
/// Convert image to gray and blur it
cvtColor( src, src_gray, COLOR_BGR2GRAY );
{
Mat canny_output;
vector<vector<Point> > contours;
- vector<Vec4i> hierarchy;
/// Detect edges using canny
Canny( src_gray, canny_output, thresh, thresh*2, 3 );
/// Find contours
- findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
+ findContours( canny_output, contours, RETR_TREE, CHAIN_APPROX_SIMPLE );
/// Get the moments
vector<Moments> mu(contours.size() );
for( size_t i = 0; i< contours.size(); i++ )
{
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
- drawContours( drawing, contours, (int)i, color, 2, 8, hierarchy, 0, Point() );
+ drawContours( drawing, contours, (int)i, color, 2, LINE_8 );
circle( drawing, mc[i], 4, color, -1, 8, 0 );
}
{
printf(" * Contour[%d] - Area (M_00) = %.2f - Area OpenCV: %.2f - Length: %.2f \n", (int)i, mu[i].m00, contourArea(contours[i]), arcLength( contours[i], true ) );
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
- drawContours( drawing, contours, (int)i, color, 2, 8, hierarchy, 0, Point() );
+ drawContours( drawing, contours, (int)i, color, 2, LINE_8 );
circle( drawing, mc[i], 4, color, -1, 8, 0 );
}
}
{ line( src, vert[j], vert[(j+1)%6], Scalar( 255 ), 3, 8 ); }
/// Get the contours
- vector<vector<Point> > contours; vector<Vec4i> hierarchy;
- Mat src_copy = src.clone();
+ vector<vector<Point> > contours;
- findContours( src_copy, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);
+ findContours( src, contours, RETR_TREE, CHAIN_APPROX_SIMPLE);
/// Calculate the distances to the contour
Mat raw_dist( src.size(), CV_32FC1 );
}
}
- /// Create Window and show your results
- const char* source_window = "Source";
- namedWindow( source_window, WINDOW_AUTOSIZE );
- imshow( source_window, src );
- namedWindow( "Distance", WINDOW_AUTOSIZE );
+ /// Show your results
+ imshow( "Source", src );
imshow( "Distance", drawing );
waitKey(0);
* @author OpenCV team
*/
-#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
/// Load source image and convert it to gray
- src = imread( argv[1], IMREAD_COLOR );
+ CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
+ if ( src.empty() )
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
+ return -1;
+ }
cvtColor( src, src_gray, COLOR_BGR2GRAY );
/// Set some parameters
* @author OpenCV team
*/
-#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
/// Load source image and convert it to gray
- src = imread( argv[1], IMREAD_COLOR );
+ CommandLineParser parser( argc, argv, "{@input | ../data/building.jpg | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
+ if ( src.empty() )
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
+ return -1;
+ }
cvtColor( src, src_gray, COLOR_BGR2GRAY );
/// Create a window and a trackbar
* @author OpenCV team
*/
-#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
/// Load source image and convert it to gray
- src = imread( argv[1], IMREAD_COLOR );
+ CommandLineParser parser( argc, argv, "{@input | ../data/pic3.png | input image}" );
+ src = imread(parser.get<String>( "@input" ), IMREAD_COLOR);
+ if ( src.empty() )
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
+ return -1;
+ }
cvtColor( src, src_gray, COLOR_BGR2GRAY );
/// Create Window
/**
* @function main
*/
-int main( int, char** argv )
+int main( int argc, char** argv )
{
/// Load source image and convert it to gray
- src = imread( argv[1], IMREAD_COLOR );
+ CommandLineParser parser( argc, argv, "{@input | ../data/pic3.png | input image}" );
+ src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
+ if( src.empty() )
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
+ return -1;
+ }
cvtColor( src, src_gray, COLOR_BGR2GRAY );
/// Create Window
#include <opencv2/features2d.hpp>
-#include <opencv2/imgcodecs.hpp>
-#include <opencv2/opencv.hpp>
-#include <vector>
+#include <opencv2/imgproc.hpp>
+#include <opencv2/highgui.hpp>
#include <iostream>
using namespace std;
const float inlier_threshold = 2.5f; // Distance threshold to identify inliers
const float nn_match_ratio = 0.8f; // Nearest neighbor matching ratio
-int main(void)
+int main(int argc, char* argv[])
{
- Mat img1 = imread("../data/graf1.png", IMREAD_GRAYSCALE);
- Mat img2 = imread("../data/graf3.png", IMREAD_GRAYSCALE);
+ CommandLineParser parser(argc, argv,
+ "{@img1 | ../data/graf1.png | input image 1}"
+ "{@img2 | ../data/graf3.png | input image 2}"
+ "{@homography | ../data/H1to3p.xml | homography matrix}");
+ Mat img1 = imread(parser.get<String>("@img1"), IMREAD_GRAYSCALE);
+ Mat img2 = imread(parser.get<String>("@img2"), IMREAD_GRAYSCALE);
Mat homography;
- FileStorage fs("../data/H1to3p.xml", FileStorage::READ);
+ FileStorage fs(parser.get<String>("@homography"), FileStorage::READ);
fs.getFirstTopLevelNode() >> homography;
vector<KeyPoint> kpts1, kpts2;
//! [decompose-homography-estimated-by-findHomography]
}
-const char* about = "Code for homography tutorial.\n"
- "Example 4: decompose the homography matrix.\n";
-
const char* params
- = "{ h help | false | print usage }"
- "{ image1 | | path to the source chessboard image (left02.jpg) }"
- "{ image2 | | path to the desired chessboard image (left01.jpg) }"
- "{ intrinsics | | path to camera intrinsics (left_intrinsics.yml) }"
- "{ width w | 9 | chessboard width }"
- "{ height h | 6 | chessboard height }"
+ = "{ help h | | print usage }"
+ "{ image1 | ../data/left02.jpg | path to the source chessboard image }"
+ "{ image2 | ../data/left01.jpg | path to the desired chessboard image }"
+ "{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }"
+ "{ width bw | 9 | chessboard width }"
+ "{ height bh | 6 | chessboard height }"
"{ square_size | 0.025 | chessboard square size }";
}
{
CommandLineParser parser(argc, argv, params);
- if (parser.get<bool>("help"))
+ if ( parser.has("help") )
{
- cout << about << endl;
+ parser.about( "Code for homography tutorial.\n"
+ "Example 4: decompose the homography matrix.\n" );
parser.printMessage();
return 0;
}
Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
float squareSize = (float) parser.get<double>("square_size");
- decomposeHomography(parser.get<string>("image1"),
- parser.get<string>("image2"),
+ decomposeHomography(parser.get<String>("image1"),
+ parser.get<String>("image2"),
patternSize, squareSize,
- parser.get<string>("intrinsics"));
+ parser.get<String>("intrinsics"));
return 0;
}
waitKey();
}
-const char* about = "Code for homography tutorial.\n"
- "Example 3: homography from the camera displacement.\n";
-
const char* params
- = "{ h help | false | print usage }"
- "{ image1 | | path to the source chessboard image (left02.jpg) }"
- "{ image2 | | path to the desired chessboard image (left01.jpg) }"
- "{ intrinsics | | path to camera intrinsics (left_intrinsics.yml) }"
- "{ width w | 9 | chessboard width }"
- "{ height h | 6 | chessboard height }"
+ = "{ help h | | print usage }"
+ "{ image1 | ../data/left02.jpg | path to the source chessboard image }"
+ "{ image2 | ../data/left01.jpg | path to the desired chessboard image }"
+ "{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }"
+ "{ width bw | 9 | chessboard width }"
+ "{ height bh | 6 | chessboard height }"
"{ square_size | 0.025 | chessboard square size }";
}
{
CommandLineParser parser(argc, argv, params);
- if (parser.get<bool>("help"))
+ if (parser.has("help"))
{
- cout << about << endl;
+ parser.about("Code for homography tutorial.\n"
+ "Example 3: homography from the camera displacement.\n");
parser.printMessage();
return 0;
}
Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
float squareSize = (float) parser.get<double>("square_size");
- homographyFromCameraDisplacement(parser.get<string>("image1"),
- parser.get<string>("image2"),
+ homographyFromCameraDisplacement(parser.get<String>("image1"),
+ parser.get<String>("image2"),
patternSize, squareSize,
- parser.get<string>("intrinsics"));
+ parser.get<String>("intrinsics"));
return 0;
}
//! [compute-transformed-corners]
}
-const char* about = "Code for homography tutorial.\n"
- "Example 2: perspective correction.\n";
-
const char* params
- = "{ h help | false | print usage }"
- "{ image1 | | path to the source chessboard image (left02.jpg) }"
- "{ image2 | | path to the desired chessboard image (left01.jpg) }"
- "{ width w | 9 | chessboard width }"
- "{ height h | 6 | chessboard height }";
+ = "{ help h | | print usage }"
+ "{ image1 | ../data/left02.jpg | path to the source chessboard image }"
+ "{ image2 | ../data/left01.jpg | path to the desired chessboard image }"
+ "{ width bw | 9 | chessboard width }"
+ "{ height bh | 6 | chessboard height }";
}
int main(int argc, char *argv[])
cv::RNG rng( 0xFFFFFFFF );
CommandLineParser parser(argc, argv, params);
- if (parser.get<bool>("help"))
+ if (parser.has("help"))
{
- cout << about << endl;
+ parser.about("Code for homography tutorial.\n"
+ "Example 2: perspective correction.\n");
parser.printMessage();
return 0;
}
Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
- perspectiveCorrection(parser.get<string>("image1"),
- parser.get<string>("image2"),
+ perspectiveCorrection(parser.get<String>("image1"),
+ parser.get<String>("image2"),
patternSize, rng);
return 0;
//! [display-pose]
}
-const char* about = "Code for homography tutorial.\n"
- "Example 1: pose from homography with coplanar points.\n";
-
const char* params
- = "{ h help | false | print usage }"
- "{ image | | path to a chessboard image (left04.jpg) }"
- "{ intrinsics | | path to camera intrinsics (left_intrinsics.yml) }"
- "{ width w | 9 | chessboard width }"
- "{ height h | 6 | chessboard height }"
+ = "{ help h | | print usage }"
+ "{ image | ../data/left04.jpg | path to a chessboard image }"
+ "{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }"
+ "{ width bw | 9 | chessboard width }"
+ "{ height bh | 6 | chessboard height }"
"{ square_size | 0.025 | chessboard square size }";
}
{
CommandLineParser parser(argc, argv, params);
- if (parser.get<bool>("help"))
+ if (parser.has("help"))
{
- cout << about << endl;
+ parser.about("Code for homography tutorial.\n"
+ "Example 1: pose from homography with coplanar points.\n");
parser.printMessage();
return 0;
}
Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
float squareSize = (float) parser.get<double>("square_size");
- poseEstimationFromCoplanarPoints(parser.get<string>("image"),
- parser.get<string>("intrinsics"),
+ poseEstimationFromCoplanarPoints(parser.get<String>("image"),
+ parser.get<String>("intrinsics"),
patternSize, squareSize);
return 0;
* @author OpenCV team
*/
+#include "opencv2/core.hpp"
+#include "opencv2/imgproc.hpp"
+#include "opencv2/highgui.hpp"
#include <iostream>
-#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
// Here we lengthen the arrow by a factor of scale
q.x = (int) (p.x - scale * hypotenuse * cos(angle));
q.y = (int) (p.y - scale * hypotenuse * sin(angle));
- line(img, p, q, colour, 1, CV_AA);
+ line(img, p, q, colour, 1, LINE_AA);
// create the arrow hooks
p.x = (int) (q.x + 9 * cos(angle + CV_PI / 4));
p.y = (int) (q.y + 9 * sin(angle + CV_PI / 4));
- line(img, p, q, colour, 1, CV_AA);
+ line(img, p, q, colour, 1, LINE_AA);
p.x = (int) (q.x + 9 * cos(angle - CV_PI / 4));
p.y = (int) (q.y + 9 * sin(angle - CV_PI / 4));
- line(img, p, q, colour, 1, CV_AA);
+ line(img, p, q, colour, 1, LINE_AA);
//! [visualization1]
}
}
//Perform PCA analysis
- PCA pca_analysis(data_pts, Mat(), CV_PCA_DATA_AS_ROW);
+ PCA pca_analysis(data_pts, Mat(), PCA::DATA_AS_ROW);
//Store the center of the object
Point cntr = Point(static_cast<int>(pca_analysis.mean.at<double>(0, 0)),
{
//! [pre-process]
// Load image
- String imageName("../data/pca_test1.jpg"); // by default
- if (argc > 1)
- {
- imageName = argv[1];
- }
- Mat src = imread( imageName );
+ CommandLineParser parser(argc, argv, "{@input | ../data/pca_test1.jpg | input image}");
+ parser.about( "This program demonstrates how to use OpenCV PCA to extract the orienation of an object.\n" );
+ parser.printMessage();
+
+ Mat src = imread(parser.get<String>("@input"));
// Check if image is loaded successfully
- if(!src.data || src.empty())
+ if(src.empty())
{
cout << "Problem loading image!!!" << endl;
return EXIT_FAILURE;
// Convert image to binary
Mat bw;
- threshold(gray, bw, 50, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);
+ threshold(gray, bw, 50, 255, THRESH_BINARY | THRESH_OTSU);
//! [pre-process]
//! [contours]
// Find all the contours in the thresholded image
- vector<Vec4i> hierarchy;
vector<vector<Point> > contours;
- findContours(bw, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
+ findContours(bw, contours, RETR_LIST, CHAIN_APPROX_NONE);
for (size_t i = 0; i < contours.size(); ++i)
{
if (area < 1e2 || 1e5 < area) continue;
// Draw each contour only for visualisation purposes
- drawContours(src, contours, static_cast<int>(i), Scalar(0, 0, 255), 2, 8, hierarchy, 0);
+ drawContours(src, contours, static_cast<int>(i), Scalar(0, 0, 255), 2, LINE_8);
// Find the orientation of each shape
getOrientation(contours[i], src);
}
#include "opencv2/objdetect.hpp"
-#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
-#include <iostream>
#include <stdio.h>
using namespace std;
"{face_cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|}"
"{eyes_cascade|../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|}");
- cout << "\nThis program demonstrates using the cv::CascadeClassifier class to detect objects (Face + eyes) in a video stream.\n"
- "You can use Haar or LBP features.\n\n";
+ parser.about( "\nThis program demonstrates using the cv::CascadeClassifier class to detect objects (Face + eyes) in a video stream.\n"
+ "You can use Haar or LBP features.\n\n" );
parser.printMessage();
- face_cascade_name = parser.get<string>("face_cascade");
- eyes_cascade_name = parser.get<string>("eyes_cascade");
+ face_cascade_name = parser.get<String>("face_cascade");
+ eyes_cascade_name = parser.get<String>("eyes_cascade");
VideoCapture capture;
Mat frame;
//-- 3. Apply the classifier to the frame
detectAndDisplay( frame );
- char c = (char)waitKey(10);
- if( c == 27 ) { break; } // escape
+ if( waitKey(10) == 27 ) { break; } // escape
}
return 0;
}
equalizeHist( frame_gray, frame_gray );
//-- Detect faces
- face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(30, 30) );
+ face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(60, 60) );
for ( size_t i = 0; i < faces.size(); i++ )
{
using namespace std;
using namespace cv;
-int main(int argc, char *argv[])
+int main( int argc, char *argv[] )
{
- CV_Assert(argc == 2);
- Mat src;
- src = imread(argv[1], IMREAD_COLOR);
+ CommandLineParser parser( argc, argv, "{@input | ../data/HappyFish.jpg | input image}" );
+ Mat src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
+ if ( src.empty() )
+ {
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
+ return -1;
+ }
+ Mat gray = Mat( src.size(), CV_8UC1 );
+ Mat color_boost = Mat( src.size(), CV_8UC3 );
- Mat gray = Mat(src.size(),CV_8UC1);
- Mat color_boost = Mat(src.size(),CV_8UC3);
-
- decolor(src,gray,color_boost);
- imshow("grayscale",gray);
- imshow("color_boost",color_boost);
+ decolor( src, gray, color_boost );
+ imshow( "grayscale", gray );
+ imshow( "color_boost", color_boost );
waitKey(0);
}
*
*/
-#include <signal.h>
#include "opencv2/photo.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
-#include "opencv2/core.hpp"
#include <iostream>
-#include <stdlib.h>
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
- if(argc < 2)
- {
- cout << "usage: " << argv[0] << " <Input image> " << endl;
- exit(0);
- }
-
int num,type;
-
- Mat src = imread(argv[1], IMREAD_COLOR);
+ CommandLineParser parser(argc, argv, "{@input | ../data/lena.jpg | input image}");
+ Mat src = imread(parser.get<String>("@input"), IMREAD_COLOR);
if(src.empty())
{
- cout << "Image not found" << endl;
+ cout << "Could not open or find the image!\n" << endl;
+ cout << "Usage: " << argv[0] << " <Input image>" << endl;
exit(0);
}
void DrawHistogram3D(Histo3DData &h)
{
//! [get_cube_size]
- int planSize = h.histogram.step1(0);
- int cols = h.histogram.step1(1);
- int rows = planSize / cols;
- int plans = h.histogram.total() / planSize;
+ int planSize = (int)h.histogram.step1(0);
+ int cols = (int)h.histogram.step1(1);
+ int rows = (int)planSize / cols;
+ int plans = (int)h.histogram.total() / planSize;
h.fen3D->removeAllWidgets();
h.nbWidget=0;
if (h.nbWidget==0)
{
/* Rotation using rodrigues */
/// Rotate around (1,1,1)
- rot_vec.at<float>(0,0) += CV_PI * 0.01f;
- rot_vec.at<float>(0,1) += CV_PI * 0.01f;
- rot_vec.at<float>(0,2) += CV_PI * 0.01f;
+ rot_vec.at<float>(0,0) += (float)CV_PI * 0.01f;
+ rot_vec.at<float>(0,1) += (float)CV_PI * 0.01f;
+ rot_vec.at<float>(0,2) += (float)CV_PI * 0.01f;
/// Shift on (1,1,1)
- translation_phase += CV_PI * 0.01f;
+ translation_phase += (float)CV_PI * 0.01f;
translation = sin(translation_phase);
Mat rot_mat;
const float inlier_threshold = 2.5f; // Distance threshold to identify inliers
const float nn_match_ratio = 0.8f; // Nearest neighbor matching ratio
-int main(void)
+int main(int argc, char* argv[])
{
- Mat img1 = imread("../data/graf1.png", IMREAD_GRAYSCALE);
- Mat img2 = imread("../data/graf3.png", IMREAD_GRAYSCALE);
-
+ CommandLineParser parser(argc, argv,
+ "{@img1 | ../data/graf1.png | input image 1}"
+ "{@img2 | ../data/graf3.png | input image 2}"
+ "{@homography | ../data/H1to3p.xml | homography matrix}");
+ Mat img1 = imread(parser.get<String>("@img1"), IMREAD_GRAYSCALE);
+ Mat img2 = imread(parser.get<String>("@img2"), IMREAD_GRAYSCALE);
Mat homography;
- FileStorage fs("../data/H1to3p.xml", FileStorage::READ);
-
+ FileStorage fs(parser.get<String>("@homography"), FileStorage::READ);
fs.getFirstTopLevelNode() >> homography;
vector<KeyPoint> kpts1, kpts2;
using namespace cv;
using namespace dnn;
-const char* about = "This sample is used to run Faster-RCNN object detection "
- "models from https://github.com/rbgirshick/py-faster-rcnn with OpenCV.";
-
const char* keys =
"{ help h | | print help message }"
"{ proto p | | path to .prototxt }"
{
// Parse command line arguments.
CommandLineParser parser(argc, argv, keys);
+ parser.about( "This sample is used to run Faster-RCNN object detection with OpenCV.\n"
+ "You can get required models from https://github.com/rbgirshick/py-faster-rcnn" );
+
if (argc == 1 || parser.has("help"))
{
- std::cout << about << std::endl;
+ parser.printMessage();
return 0;
}