Commit 1654dfe3 authored by Suleyman TURKMEN's avatar Suleyman TURKMEN Committed by Vadim Pisarevsky

Update samples (#10333)

* Update samples

* Update calib3d.hpp

* Update calib3d.hpp

* Update calib3d.hpp

* Update calib3d.hpp
parent d3a124c8
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
<script src="utils.js" type="text/javascript"></script> <script src="utils.js" type="text/javascript"></script>
<script id="codeSnippet" type="text/code-snippet"> <script id="codeSnippet" type="text/code-snippet">
let src = cv.imread('canvasInput'); 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 lines = new cv.Mat();
cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0); cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0);
cv.Canny(src, src, 50, 200, 3); cv.Canny(src, src, 50, 200, 3);
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
<script src="utils.js" type="text/javascript"></script> <script src="utils.js" type="text/javascript"></script>
<script id="codeSnippet" type="text/code-snippet"> <script id="codeSnippet" type="text/code-snippet">
let src = cv.imread('canvasInput'); 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 lines = new cv.Mat();
let color = new cv.Scalar(255, 0, 0); let color = new cv.Scalar(255, 0, 0);
cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0); cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0);
......
...@@ -89,31 +89,31 @@ This can be tested easily using a chessboard object and `findChessboardCorners() ...@@ -89,31 +89,31 @@ This can be tested easily using a chessboard object and `findChessboardCorners()
The first thing consists to detect the chessboard corners, the chessboard size (`patternSize`), here `9x6`, is required: 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) ![](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: 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: 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: 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: 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"): 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[ \f[
\begin{align*} \begin{align*}
...@@ -164,15 +164,15 @@ The following image shows the source image (left) and the chessboard view that w ...@@ -164,15 +164,15 @@ The following image shows the source image (left) and the chessboard view that w
The first step consists to detect the chessboard corners in the source and desired images: 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: 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 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: The result image is:
...@@ -180,7 +180,7 @@ The result image is: ...@@ -180,7 +180,7 @@ The result image is:
To compute the coordinates of the source corners transformed by the homography: 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: To check the correctness of the calculation, the matching lines are displayed:
...@@ -295,13 +295,13 @@ To transform a 3D point expressed in the camera 1 frame to the camera 2 frame: ...@@ -295,13 +295,13 @@ To transform a 3D point expressed in the camera 1 frame to the camera 2 frame:
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: 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) ![](images/homography_camera_displacement_poses.jpg)
The camera displacement can be computed from the camera poses using the formulas above: 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: The homography related to a specific plane computed from the camera displacement is:
...@@ -320,11 +320,11 @@ the translation vector between the two camera frames. ...@@ -320,11 +320,11 @@ the translation vector between the two camera frames.
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: 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: 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: 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:
...@@ -332,7 +332,7 @@ The projective homography matrix \f$ \textbf{G} \f$ can be computed from the Euc ...@@ -332,7 +332,7 @@ The projective homography matrix \f$ \textbf{G} \f$ can be computed from the Euc
\textbf{G} = \gamma \textbf{K} \textbf{H} \textbf{K}^{-1} \textbf{G} = \gamma \textbf{K} \textbf{H} \textbf{K}^{-1}
\f] \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: 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:
...@@ -340,7 +340,7 @@ In our case, the Z-axis of the chessboard goes inside the object whereas in the ...@@ -340,7 +340,7 @@ In our case, the Z-axis of the chessboard goes inside the object whereas in the
^{2}\textrm{H}_{1} = \hspace{0.2em} ^{2}\textrm{R}_{1} + \hspace{0.1em} \frac{^{2}\textrm{t}_{1} \cdot n^T}{d} ^{2}\textrm{H}_{1} = \hspace{0.2em} ^{2}\textrm{R}_{1} + \hspace{0.1em} \frac{^{2}\textrm{t}_{1} \cdot n^T}{d}
\f] \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 We will now compare the projective homography computed from the camera displacement with the one estimated with @ref cv::findHomography
...@@ -368,11 +368,11 @@ Visually, it is hard to distinguish a difference between the result image from t ...@@ -368,11 +368,11 @@ Visually, it is hard to distinguish a difference between the result image from t
OpenCV 3 contains the function @ref cv::decomposeHomographyMat which allows to decompose the homography matrix to a set of rotations, translations and plane normals. 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: 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: 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: Solution 0:
......
...@@ -306,6 +306,12 @@ optimization procedures like calibrateCamera, stereoCalibrate, or solvePnP . ...@@ -306,6 +306,12 @@ optimization procedures like calibrateCamera, stereoCalibrate, or solvePnP .
*/ */
CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() ); 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. /** @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 @param srcPoints Coordinates of the points in the original plane, a matrix of the type CV_32FC2
...@@ -364,12 +370,6 @@ cannot be estimated, an empty one will be returned. ...@@ -364,12 +370,6 @@ cannot be estimated, an empty one will be returned.
@sa @sa
getAffineTransform, estimateAffine2D, estimateAffinePartial2D, getPerspectiveTransform, warpPerspective, getAffineTransform, estimateAffine2D, estimateAffinePartial2D, getPerspectiveTransform, warpPerspective,
perspectiveTransform 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, CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints,
int method = 0, double ransacReprojThreshold = 3, int method = 0, double ransacReprojThreshold = 3,
...@@ -525,6 +525,12 @@ CV_EXPORTS_W void projectPoints( InputArray objectPoints, ...@@ -525,6 +525,12 @@ CV_EXPORTS_W void projectPoints( InputArray objectPoints,
OutputArray jacobian = noArray(), OutputArray jacobian = noArray(),
double aspectRatio = 0 ); 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. /** @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 @param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
#include <opencv2/objdetect.hpp> #include <opencv2/objdetect.hpp>
#include <stdio.h> #include <stdio.h>
#include <string>
#include <vector>
using namespace std; using namespace std;
using namespace cv; using namespace cv;
...@@ -84,7 +82,7 @@ int main(int , char** ) ...@@ -84,7 +82,7 @@ int main(int , char** )
do do
{ {
VideoStream >> ReferenceFrame; VideoStream >> ReferenceFrame;
cvtColor(ReferenceFrame, GrayFrame, COLOR_RGB2GRAY); cvtColor(ReferenceFrame, GrayFrame, COLOR_BGR2GRAY);
Detector.process(GrayFrame); Detector.process(GrayFrame);
Detector.getObjects(Faces); Detector.getObjects(Faces);
......
...@@ -15,7 +15,7 @@ using namespace std; ...@@ -15,7 +15,7 @@ using namespace std;
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
Mat src, dst; Mat src, dst;
...@@ -23,12 +23,14 @@ int main( int, char** argv ) ...@@ -23,12 +23,14 @@ int main( int, char** argv )
const char* equalized_window = "Equalized Image"; const char* equalized_window = "Equalized Image";
/// Load 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() ) 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 /// Convert to grayscale
cvtColor( src, src, COLOR_BGR2GRAY ); cvtColor( src, src, COLOR_BGR2GRAY );
......
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
*/ */
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include <iostream>
using namespace cv; using namespace cv;
using namespace std;
/// Global variables /// Global variables
Mat src, erosion_dst, dilation_dst; Mat src, erosion_dst, dilation_dst;
...@@ -27,13 +28,17 @@ void Dilation( int, void* ); ...@@ -27,13 +28,17 @@ void Dilation( int, void* );
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
/// Load an image /// 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() ) 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 /// Create windows
namedWindow( "Erosion Demo", WINDOW_AUTOSIZE ); namedWindow( "Erosion Demo", WINDOW_AUTOSIZE );
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp" #include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include <iostream>
using namespace cv; using namespace cv;
...@@ -32,15 +33,14 @@ void Morphology_Operations( int, void* ); ...@@ -32,15 +33,14 @@ void Morphology_Operations( int, void* );
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
//![load] //![load]
String imageName("../data/baboon.jpg"); // by default CommandLineParser parser( argc, argv, "{@input | ../data/baboon.jpg | input image}" );
if (argc > 1) 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] //![load]
//![window] //![window]
......
...@@ -11,16 +11,15 @@ void show_wait_destroy(const char* winname, cv::Mat img); ...@@ -11,16 +11,15 @@ void show_wait_destroy(const char* winname, cv::Mat img);
using namespace std; using namespace std;
using namespace cv; using namespace cv;
int main(int, char** argv) int main(int argc, char** argv)
{ {
//! [load_image] //! [load_image]
// Load the image CommandLineParser parser(argc, argv, "{@input | ../data/notes.png | input image}");
Mat src = imread(argv[1]); Mat src = imread(parser.get<String>("@input"), IMREAD_COLOR);
if (src.empty())
// Check if image is loaded fine {
if(src.empty()){ cout << "Could not open or find the image!\n" << endl;
printf(" Error opening image\n"); cout << "Usage: " << argv[0] << " <Input image>" << endl;
printf(" Program Arguments: [image_path]\n");
return -1; return -1;
} }
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
*/ */
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include <iostream>
using namespace cv; using namespace cv;
...@@ -56,13 +56,18 @@ static void CannyThreshold(int, void*) ...@@ -56,13 +56,18 @@ static void CannyThreshold(int, void*)
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
//![load] //![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() ) 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] //![load]
//![create_mat] //![create_mat]
......
...@@ -20,7 +20,7 @@ const char* warp_rotate_window = "Warp + Rotate"; ...@@ -20,7 +20,7 @@ const char* warp_rotate_window = "Warp + Rotate";
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
Point2f srcTri[3]; Point2f srcTri[3];
Point2f dstTri[3]; Point2f dstTri[3];
...@@ -30,7 +30,14 @@ int main( int, char** argv ) ...@@ -30,7 +30,14 @@ int main( int, char** argv )
Mat src, warp_dst, warp_rotate_dst; Mat src, warp_dst, warp_rotate_dst;
/// Load the image /// 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 /// Set the dst image the same type and size as src
warp_dst = Mat::zeros( src.rows, src.cols, src.type() ); warp_dst = Mat::zeros( src.rows, src.cols, src.type() );
......
...@@ -12,7 +12,7 @@ using namespace std; ...@@ -12,7 +12,7 @@ using namespace std;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
//![load] //![load]
const char* filename = argc >=2 ? argv[1] : "../../../data/smarties.png"; const char* filename = argc >=2 ? argv[1] : "../data/smarties.png";
// Loads an image // Loads an image
Mat src = imread( filename, IMREAD_COLOR ); Mat src = imread( filename, IMREAD_COLOR );
......
...@@ -16,7 +16,7 @@ int main(int argc, char** argv) ...@@ -16,7 +16,7 @@ int main(int argc, char** argv)
Mat dst, cdst, cdstP; Mat dst, cdst, cdstP;
//![load] //![load]
const char* default_file = "../../../data/sudoku.png"; const char* default_file = "../data/sudoku.png";
const char* filename = argc >=2 ? argv[1] : default_file; const char* filename = argc >=2 ? argv[1] : default_file;
// Loads an image // Loads an image
......
...@@ -23,11 +23,18 @@ void thresh_callback(int, void* ); ...@@ -23,11 +23,18 @@ void thresh_callback(int, void* );
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
//![setup] //![setup]
/// Load source image /// 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 /// Convert image to gray and blur it
cvtColor( src, src_gray, COLOR_BGR2GRAY ); cvtColor( src, src_gray, COLOR_BGR2GRAY );
...@@ -84,8 +91,8 @@ void thresh_callback(int, void* ) ...@@ -84,8 +91,8 @@ void thresh_callback(int, void* )
//![allthework] //![allthework]
for( size_t i = 0; i < contours.size(); i++ ) for( size_t i = 0; i < contours.size(); i++ )
{ {
approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true ); approxPolyDP( contours[i], contours_poly[i], 3, true );
boundRect[i] = boundingRect( Mat(contours_poly[i]) ); boundRect[i] = boundingRect( contours_poly[i] );
minEnclosingCircle( contours_poly[i], center[i], radius[i] ); minEnclosingCircle( contours_poly[i], center[i], radius[i] );
} }
//![allthework] //![allthework]
......
...@@ -23,10 +23,17 @@ void thresh_callback(int, void* ); ...@@ -23,10 +23,17 @@ void thresh_callback(int, void* );
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
/// Load source image and convert it to gray /// 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 /// Convert image to gray and blur it
cvtColor( src, src_gray, COLOR_BGR2GRAY ); cvtColor( src, src_gray, COLOR_BGR2GRAY );
...@@ -63,9 +70,9 @@ void thresh_callback(int, void* ) ...@@ -63,9 +70,9 @@ void thresh_callback(int, void* )
vector<RotatedRect> minEllipse( contours.size() ); vector<RotatedRect> minEllipse( contours.size() );
for( size_t i = 0; i < contours.size(); i++ ) 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 ) if( contours[i].size() > 5 )
{ minEllipse[i] = fitEllipse( Mat(contours[i]) ); } { minEllipse[i] = fitEllipse( contours[i] ); }
} }
/// Draw contours + rotated rects + ellipses /// Draw contours + rotated rects + ellipses
......
...@@ -23,10 +23,17 @@ void thresh_callback(int, void* ); ...@@ -23,10 +23,17 @@ void thresh_callback(int, void* );
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
/// Load source image and convert it to gray /// 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 /// Convert image to gray and blur it
cvtColor( src, src_gray, COLOR_BGR2GRAY ); cvtColor( src, src_gray, COLOR_BGR2GRAY );
...@@ -62,7 +69,7 @@ void thresh_callback(int, void* ) ...@@ -62,7 +69,7 @@ void thresh_callback(int, void* )
/// Find the convex hull object for each contour /// Find the convex hull object for each contour
vector<vector<Point> >hull( contours.size() ); vector<vector<Point> >hull( contours.size() );
for( size_t i = 0; i < contours.size(); i++ ) 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 /// Draw contours + hull results
Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 ); Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
......
...@@ -23,10 +23,18 @@ void thresh_callback(int, void* ); ...@@ -23,10 +23,18 @@ void thresh_callback(int, void* );
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
/// Load source image and convert it to gray /// 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 /// Convert image to gray and blur it
cvtColor( src, src_gray, COLOR_BGR2GRAY ); cvtColor( src, src_gray, COLOR_BGR2GRAY );
...@@ -51,12 +59,11 @@ void thresh_callback(int, void* ) ...@@ -51,12 +59,11 @@ void thresh_callback(int, void* )
{ {
Mat canny_output; Mat canny_output;
vector<vector<Point> > contours; vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
/// Detect edges using canny /// Detect edges using canny
Canny( src_gray, canny_output, thresh, thresh*2, 3 ); Canny( src_gray, canny_output, thresh, thresh*2, 3 );
/// Find contours /// 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 /// Get the moments
vector<Moments> mu(contours.size() ); vector<Moments> mu(contours.size() );
...@@ -73,7 +80,7 @@ void thresh_callback(int, void* ) ...@@ -73,7 +80,7 @@ void thresh_callback(int, void* )
for( size_t i = 0; i< contours.size(); i++ ) for( size_t i = 0; i< contours.size(); i++ )
{ {
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) ); 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 ); circle( drawing, mc[i], 4, color, -1, 8, 0 );
} }
...@@ -87,7 +94,7 @@ void thresh_callback(int, void* ) ...@@ -87,7 +94,7 @@ void thresh_callback(int, void* )
{ {
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 ) ); 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) ); 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 ); circle( drawing, mc[i], 4, color, -1, 8, 0 );
} }
} }
...@@ -35,10 +35,9 @@ int main( void ) ...@@ -35,10 +35,9 @@ int main( void )
{ line( src, vert[j], vert[(j+1)%6], Scalar( 255 ), 3, 8 ); } { line( src, vert[j], vert[(j+1)%6], Scalar( 255 ), 3, 8 ); }
/// Get the contours /// Get the contours
vector<vector<Point> > contours; vector<Vec4i> hierarchy; vector<vector<Point> > contours;
Mat src_copy = src.clone();
findContours( src_copy, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE); findContours( src, contours, RETR_TREE, CHAIN_APPROX_SIMPLE);
/// Calculate the distances to the contour /// Calculate the distances to the contour
Mat raw_dist( src.size(), CV_32FC1 ); Mat raw_dist( src.size(), CV_32FC1 );
...@@ -67,11 +66,8 @@ int main( void ) ...@@ -67,11 +66,8 @@ int main( void )
} }
} }
/// Create Window and show your results /// Show your results
const char* source_window = "Source"; imshow( "Source", src );
namedWindow( source_window, WINDOW_AUTOSIZE );
imshow( source_window, src );
namedWindow( "Distance", WINDOW_AUTOSIZE );
imshow( "Distance", drawing ); imshow( "Distance", drawing );
waitKey(0); waitKey(0);
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* @author OpenCV team * @author OpenCV team
*/ */
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include <iostream> #include <iostream>
...@@ -36,10 +35,17 @@ void myHarris_function( int, void* ); ...@@ -36,10 +35,17 @@ void myHarris_function( int, void* );
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
/// Load source image and convert it to gray /// 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 ); cvtColor( src, src_gray, COLOR_BGR2GRAY );
/// Set some parameters /// Set some parameters
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* @author OpenCV team * @author OpenCV team
*/ */
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include <iostream> #include <iostream>
...@@ -26,10 +25,17 @@ void cornerHarris_demo( int, void* ); ...@@ -26,10 +25,17 @@ void cornerHarris_demo( int, void* );
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
/// Load source image and convert it to gray /// 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 ); cvtColor( src, src_gray, COLOR_BGR2GRAY );
/// Create a window and a trackbar /// Create a window and a trackbar
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* @author OpenCV team * @author OpenCV team
*/ */
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include <iostream> #include <iostream>
...@@ -27,10 +26,17 @@ void goodFeaturesToTrack_Demo( int, void* ); ...@@ -27,10 +26,17 @@ void goodFeaturesToTrack_Demo( int, void* );
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
/// Load source image and convert it to gray /// 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 ); cvtColor( src, src_gray, COLOR_BGR2GRAY );
/// Create Window /// Create Window
......
...@@ -27,10 +27,17 @@ void goodFeaturesToTrack_Demo( int, void* ); ...@@ -27,10 +27,17 @@ void goodFeaturesToTrack_Demo( int, void* );
/** /**
* @function main * @function main
*/ */
int main( int, char** argv ) int main( int argc, char** argv )
{ {
/// Load source image and convert it to gray /// 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 ); cvtColor( src, src_gray, COLOR_BGR2GRAY );
/// Create Window /// Create Window
......
#include <opencv2/features2d.hpp> #include <opencv2/features2d.hpp>
#include <opencv2/imgcodecs.hpp> #include <opencv2/imgproc.hpp>
#include <opencv2/opencv.hpp> #include <opencv2/highgui.hpp>
#include <vector>
#include <iostream> #include <iostream>
using namespace std; using namespace std;
...@@ -10,13 +9,17 @@ using namespace cv; ...@@ -10,13 +9,17 @@ using namespace cv;
const float inlier_threshold = 2.5f; // Distance threshold to identify inliers const float inlier_threshold = 2.5f; // Distance threshold to identify inliers
const float nn_match_ratio = 0.8f; // Nearest neighbor matching ratio 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); CommandLineParser parser(argc, argv,
Mat img2 = imread("../data/graf3.png", IMREAD_GRAYSCALE); "{@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; Mat homography;
FileStorage fs("../data/H1to3p.xml", FileStorage::READ); FileStorage fs(parser.get<String>("@homography"), FileStorage::READ);
fs.getFirstTopLevelNode() >> homography; fs.getFirstTopLevelNode() >> homography;
vector<KeyPoint> kpts1, kpts2; vector<KeyPoint> kpts1, kpts2;
......
...@@ -153,16 +153,13 @@ void decomposeHomography(const string &img1Path, const string &img2Path, const S ...@@ -153,16 +153,13 @@ void decomposeHomography(const string &img1Path, const string &img2Path, const S
//! [decompose-homography-estimated-by-findHomography] //! [decompose-homography-estimated-by-findHomography]
} }
const char* about = "Code for homography tutorial.\n"
"Example 4: decompose the homography matrix.\n";
const char* params const char* params
= "{ h help | false | print usage }" = "{ help h | | print usage }"
"{ image1 | | path to the source chessboard image (left02.jpg) }" "{ image1 | ../data/left02.jpg | path to the source chessboard image }"
"{ image2 | | path to the desired chessboard image (left01.jpg) }" "{ image2 | ../data/left01.jpg | path to the desired chessboard image }"
"{ intrinsics | | path to camera intrinsics (left_intrinsics.yml) }" "{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }"
"{ width w | 9 | chessboard width }" "{ width bw | 9 | chessboard width }"
"{ height h | 6 | chessboard height }" "{ height bh | 6 | chessboard height }"
"{ square_size | 0.025 | chessboard square size }"; "{ square_size | 0.025 | chessboard square size }";
} }
...@@ -170,19 +167,20 @@ int main(int argc, char *argv[]) ...@@ -170,19 +167,20 @@ int main(int argc, char *argv[])
{ {
CommandLineParser parser(argc, argv, params); 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(); parser.printMessage();
return 0; return 0;
} }
Size patternSize(parser.get<int>("width"), parser.get<int>("height")); Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
float squareSize = (float) parser.get<double>("square_size"); float squareSize = (float) parser.get<double>("square_size");
decomposeHomography(parser.get<string>("image1"), decomposeHomography(parser.get<String>("image1"),
parser.get<string>("image2"), parser.get<String>("image2"),
patternSize, squareSize, patternSize, squareSize,
parser.get<string>("intrinsics")); parser.get<String>("intrinsics"));
return 0; return 0;
} }
......
...@@ -168,16 +168,13 @@ void homographyFromCameraDisplacement(const string &img1Path, const string &img2 ...@@ -168,16 +168,13 @@ void homographyFromCameraDisplacement(const string &img1Path, const string &img2
waitKey(); waitKey();
} }
const char* about = "Code for homography tutorial.\n"
"Example 3: homography from the camera displacement.\n";
const char* params const char* params
= "{ h help | false | print usage }" = "{ help h | | print usage }"
"{ image1 | | path to the source chessboard image (left02.jpg) }" "{ image1 | ../data/left02.jpg | path to the source chessboard image }"
"{ image2 | | path to the desired chessboard image (left01.jpg) }" "{ image2 | ../data/left01.jpg | path to the desired chessboard image }"
"{ intrinsics | | path to camera intrinsics (left_intrinsics.yml) }" "{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }"
"{ width w | 9 | chessboard width }" "{ width bw | 9 | chessboard width }"
"{ height h | 6 | chessboard height }" "{ height bh | 6 | chessboard height }"
"{ square_size | 0.025 | chessboard square size }"; "{ square_size | 0.025 | chessboard square size }";
} }
...@@ -185,19 +182,20 @@ int main(int argc, char *argv[]) ...@@ -185,19 +182,20 @@ int main(int argc, char *argv[])
{ {
CommandLineParser parser(argc, argv, params); 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(); parser.printMessage();
return 0; return 0;
} }
Size patternSize(parser.get<int>("width"), parser.get<int>("height")); Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
float squareSize = (float) parser.get<double>("square_size"); float squareSize = (float) parser.get<double>("square_size");
homographyFromCameraDisplacement(parser.get<string>("image1"), homographyFromCameraDisplacement(parser.get<String>("image1"),
parser.get<string>("image2"), parser.get<String>("image2"),
patternSize, squareSize, patternSize, squareSize,
parser.get<string>("intrinsics")); parser.get<String>("intrinsics"));
return 0; return 0;
} }
......
...@@ -92,15 +92,12 @@ void perspectiveCorrection(const string &img1Path, const string &img2Path, const ...@@ -92,15 +92,12 @@ void perspectiveCorrection(const string &img1Path, const string &img2Path, const
//! [compute-transformed-corners] //! [compute-transformed-corners]
} }
const char* about = "Code for homography tutorial.\n"
"Example 2: perspective correction.\n";
const char* params const char* params
= "{ h help | false | print usage }" = "{ help h | | print usage }"
"{ image1 | | path to the source chessboard image (left02.jpg) }" "{ image1 | ../data/left02.jpg | path to the source chessboard image }"
"{ image2 | | path to the desired chessboard image (left01.jpg) }" "{ image2 | ../data/left01.jpg | path to the desired chessboard image }"
"{ width w | 9 | chessboard width }" "{ width bw | 9 | chessboard width }"
"{ height h | 6 | chessboard height }"; "{ height bh | 6 | chessboard height }";
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
...@@ -108,16 +105,17 @@ int main(int argc, char *argv[]) ...@@ -108,16 +105,17 @@ int main(int argc, char *argv[])
cv::RNG rng( 0xFFFFFFFF ); cv::RNG rng( 0xFFFFFFFF );
CommandLineParser parser(argc, argv, params); 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(); parser.printMessage();
return 0; return 0;
} }
Size patternSize(parser.get<int>("width"), parser.get<int>("height")); Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
perspectiveCorrection(parser.get<string>("image1"), perspectiveCorrection(parser.get<String>("image1"),
parser.get<string>("image2"), parser.get<String>("image2"),
patternSize, rng); patternSize, rng);
return 0; return 0;
......
...@@ -116,15 +116,12 @@ void poseEstimationFromCoplanarPoints(const string &imgPath, const string &intri ...@@ -116,15 +116,12 @@ void poseEstimationFromCoplanarPoints(const string &imgPath, const string &intri
//! [display-pose] //! [display-pose]
} }
const char* about = "Code for homography tutorial.\n"
"Example 1: pose from homography with coplanar points.\n";
const char* params const char* params
= "{ h help | false | print usage }" = "{ help h | | print usage }"
"{ image | | path to a chessboard image (left04.jpg) }" "{ image | ../data/left04.jpg | path to a chessboard image }"
"{ intrinsics | | path to camera intrinsics (left_intrinsics.yml) }" "{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }"
"{ width w | 9 | chessboard width }" "{ width bw | 9 | chessboard width }"
"{ height h | 6 | chessboard height }" "{ height bh | 6 | chessboard height }"
"{ square_size | 0.025 | chessboard square size }"; "{ square_size | 0.025 | chessboard square size }";
} }
...@@ -132,17 +129,18 @@ int main(int argc, char *argv[]) ...@@ -132,17 +129,18 @@ int main(int argc, char *argv[])
{ {
CommandLineParser parser(argc, argv, params); 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(); parser.printMessage();
return 0; return 0;
} }
Size patternSize(parser.get<int>("width"), parser.get<int>("height")); Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
float squareSize = (float) parser.get<double>("square_size"); float squareSize = (float) parser.get<double>("square_size");
poseEstimationFromCoplanarPoints(parser.get<string>("image"), poseEstimationFromCoplanarPoints(parser.get<String>("image"),
parser.get<string>("intrinsics"), parser.get<String>("intrinsics"),
patternSize, squareSize); patternSize, squareSize);
return 0; return 0;
......
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
* @author OpenCV team * @author OpenCV team
*/ */
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <iostream> #include <iostream>
#include <opencv2/opencv.hpp>
using namespace std; using namespace std;
using namespace cv; using namespace cv;
...@@ -30,16 +32,16 @@ void drawAxis(Mat& img, Point p, Point q, Scalar colour, const float scale = 0.2 ...@@ -30,16 +32,16 @@ void drawAxis(Mat& img, Point p, Point q, Scalar colour, const float scale = 0.2
// Here we lengthen the arrow by a factor of scale // Here we lengthen the arrow by a factor of scale
q.x = (int) (p.x - scale * hypotenuse * cos(angle)); q.x = (int) (p.x - scale * hypotenuse * cos(angle));
q.y = (int) (p.y - scale * hypotenuse * sin(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 // create the arrow hooks
p.x = (int) (q.x + 9 * cos(angle + CV_PI / 4)); p.x = (int) (q.x + 9 * cos(angle + CV_PI / 4));
p.y = (int) (q.y + 9 * sin(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.x = (int) (q.x + 9 * cos(angle - CV_PI / 4));
p.y = (int) (q.y + 9 * sin(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] //! [visualization1]
} }
...@@ -59,7 +61,7 @@ double getOrientation(const vector<Point> &pts, Mat &img) ...@@ -59,7 +61,7 @@ double getOrientation(const vector<Point> &pts, Mat &img)
} }
//Perform PCA analysis //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 //Store the center of the object
Point cntr = Point(static_cast<int>(pca_analysis.mean.at<double>(0, 0)), Point cntr = Point(static_cast<int>(pca_analysis.mean.at<double>(0, 0)),
...@@ -98,15 +100,14 @@ int main(int argc, char** argv) ...@@ -98,15 +100,14 @@ int main(int argc, char** argv)
{ {
//! [pre-process] //! [pre-process]
// Load image // Load image
String imageName("../data/pca_test1.jpg"); // by default CommandLineParser parser(argc, argv, "{@input | ../data/pca_test1.jpg | input image}");
if (argc > 1) parser.about( "This program demonstrates how to use OpenCV PCA to extract the orienation of an object.\n" );
{ parser.printMessage();
imageName = argv[1];
} Mat src = imread(parser.get<String>("@input"));
Mat src = imread( imageName );
// Check if image is loaded successfully // Check if image is loaded successfully
if(!src.data || src.empty()) if(src.empty())
{ {
cout << "Problem loading image!!!" << endl; cout << "Problem loading image!!!" << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
...@@ -120,14 +121,13 @@ int main(int argc, char** argv) ...@@ -120,14 +121,13 @@ int main(int argc, char** argv)
// Convert image to binary // Convert image to binary
Mat bw; Mat bw;
threshold(gray, bw, 50, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); threshold(gray, bw, 50, 255, THRESH_BINARY | THRESH_OTSU);
//! [pre-process] //! [pre-process]
//! [contours] //! [contours]
// Find all the contours in the thresholded image // Find all the contours in the thresholded image
vector<Vec4i> hierarchy;
vector<vector<Point> > contours; 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) for (size_t i = 0; i < contours.size(); ++i)
{ {
...@@ -137,7 +137,7 @@ int main(int argc, char** argv) ...@@ -137,7 +137,7 @@ int main(int argc, char** argv)
if (area < 1e2 || 1e5 < area) continue; if (area < 1e2 || 1e5 < area) continue;
// Draw each contour only for visualisation purposes // 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 // Find the orientation of each shape
getOrientation(contours[i], src); getOrientation(contours[i], src);
} }
......
#include "opencv2/objdetect.hpp" #include "opencv2/objdetect.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include <iostream>
#include <stdio.h> #include <stdio.h>
using namespace std; using namespace std;
...@@ -26,12 +24,12 @@ int main( int argc, const char** argv ) ...@@ -26,12 +24,12 @@ int main( int argc, const char** argv )
"{face_cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|}" "{face_cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|}"
"{eyes_cascade|../../data/haarcascades/haarcascade_eye_tree_eyeglasses.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" 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"; "You can use Haar or LBP features.\n\n" );
parser.printMessage(); parser.printMessage();
face_cascade_name = parser.get<string>("face_cascade"); face_cascade_name = parser.get<String>("face_cascade");
eyes_cascade_name = parser.get<string>("eyes_cascade"); eyes_cascade_name = parser.get<String>("eyes_cascade");
VideoCapture capture; VideoCapture capture;
Mat frame; Mat frame;
...@@ -54,8 +52,7 @@ int main( int argc, const char** argv ) ...@@ -54,8 +52,7 @@ int main( int argc, const char** argv )
//-- 3. Apply the classifier to the frame //-- 3. Apply the classifier to the frame
detectAndDisplay( frame ); detectAndDisplay( frame );
char c = (char)waitKey(10); if( waitKey(10) == 27 ) { break; } // escape
if( c == 27 ) { break; } // escape
} }
return 0; return 0;
} }
...@@ -70,7 +67,7 @@ void detectAndDisplay( Mat frame ) ...@@ -70,7 +67,7 @@ void detectAndDisplay( Mat frame )
equalizeHist( frame_gray, frame_gray ); equalizeHist( frame_gray, frame_gray );
//-- Detect faces //-- 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++ ) for ( size_t i = 0; i < faces.size(); i++ )
{ {
......
...@@ -24,17 +24,21 @@ ...@@ -24,17 +24,21 @@
using namespace std; using namespace std;
using namespace cv; using namespace cv;
int main(int argc, char *argv[]) int main( int argc, char *argv[] )
{ {
CV_Assert(argc == 2); CommandLineParser parser( argc, argv, "{@input | ../data/HappyFish.jpg | input image}" );
Mat src; Mat src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
src = imread(argv[1], 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); decolor( src, gray, color_boost );
Mat color_boost = Mat(src.size(),CV_8UC3); imshow( "grayscale", gray );
imshow( "color_boost", color_boost );
decolor(src,gray,color_boost);
imshow("grayscale",gray);
imshow("color_boost",color_boost);
waitKey(0); waitKey(0);
} }
...@@ -14,32 +14,24 @@ ...@@ -14,32 +14,24 @@
* *
*/ */
#include <signal.h>
#include "opencv2/photo.hpp" #include "opencv2/photo.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include "opencv2/core.hpp"
#include <iostream> #include <iostream>
#include <stdlib.h>
using namespace std; using namespace std;
using namespace cv; using namespace cv;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if(argc < 2)
{
cout << "usage: " << argv[0] << " <Input image> " << endl;
exit(0);
}
int num,type; int num,type;
CommandLineParser parser(argc, argv, "{@input | ../data/lena.jpg | input image}");
Mat src = imread(argv[1], IMREAD_COLOR); Mat src = imread(parser.get<String>("@input"), IMREAD_COLOR);
if(src.empty()) 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); exit(0);
} }
......
...@@ -32,10 +32,10 @@ void KeyboardViz3d(const viz::KeyboardEvent &w, void *t); ...@@ -32,10 +32,10 @@ void KeyboardViz3d(const viz::KeyboardEvent &w, void *t);
void DrawHistogram3D(Histo3DData &h) void DrawHistogram3D(Histo3DData &h)
{ {
//! [get_cube_size] //! [get_cube_size]
int planSize = h.histogram.step1(0); int planSize = (int)h.histogram.step1(0);
int cols = h.histogram.step1(1); int cols = (int)h.histogram.step1(1);
int rows = planSize / cols; int rows = (int)planSize / cols;
int plans = h.histogram.total() / planSize; int plans = (int)h.histogram.total() / planSize;
h.fen3D->removeAllWidgets(); h.fen3D->removeAllWidgets();
h.nbWidget=0; h.nbWidget=0;
if (h.nbWidget==0) if (h.nbWidget==0)
......
...@@ -56,12 +56,12 @@ int main() ...@@ -56,12 +56,12 @@ int main()
{ {
/* Rotation using rodrigues */ /* Rotation using rodrigues */
/// Rotate around (1,1,1) /// Rotate around (1,1,1)
rot_vec.at<float>(0,0) += CV_PI * 0.01f; rot_vec.at<float>(0,0) += (float)CV_PI * 0.01f;
rot_vec.at<float>(0,1) += CV_PI * 0.01f; rot_vec.at<float>(0,1) += (float)CV_PI * 0.01f;
rot_vec.at<float>(0,2) += CV_PI * 0.01f; rot_vec.at<float>(0,2) += (float)CV_PI * 0.01f;
/// Shift on (1,1,1) /// Shift on (1,1,1)
translation_phase += CV_PI * 0.01f; translation_phase += (float)CV_PI * 0.01f;
translation = sin(translation_phase); translation = sin(translation_phase);
Mat rot_mat; Mat rot_mat;
......
...@@ -19,15 +19,17 @@ using namespace cv; ...@@ -19,15 +19,17 @@ using namespace cv;
const float inlier_threshold = 2.5f; // Distance threshold to identify inliers const float inlier_threshold = 2.5f; // Distance threshold to identify inliers
const float nn_match_ratio = 0.8f; // Nearest neighbor matching ratio 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); CommandLineParser parser(argc, argv,
Mat img2 = imread("../data/graf3.png", IMREAD_GRAYSCALE); "{@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; Mat homography;
FileStorage fs("../data/H1to3p.xml", FileStorage::READ); FileStorage fs(parser.get<String>("@homography"), FileStorage::READ);
fs.getFirstTopLevelNode() >> homography; fs.getFirstTopLevelNode() >> homography;
vector<KeyPoint> kpts1, kpts2; vector<KeyPoint> kpts1, kpts2;
......
...@@ -27,9 +27,6 @@ ...@@ -27,9 +27,6 @@
using namespace cv; using namespace cv;
using namespace dnn; 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 = const char* keys =
"{ help h | | print help message }" "{ help h | | print help message }"
"{ proto p | | path to .prototxt }" "{ proto p | | path to .prototxt }"
...@@ -53,9 +50,12 @@ int main(int argc, char** argv) ...@@ -53,9 +50,12 @@ int main(int argc, char** argv)
{ {
// Parse command line arguments. // Parse command line arguments.
CommandLineParser parser(argc, argv, keys); 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")) if (argc == 1 || parser.has("help"))
{ {
std::cout << about << std::endl; parser.printMessage();
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment