Update samples (#10333)
authorSuleyman TURKMEN <sturkmen@hotmail.com>
Mon, 18 Dec 2017 10:44:11 +0000 (12:44 +0200)
committerVadim Pisarevsky <vadim.pisarevsky@gmail.com>
Mon, 18 Dec 2017 10:44:11 +0000 (13:44 +0300)
* Update samples

* Update calib3d.hpp

* Update calib3d.hpp

* Update calib3d.hpp

* Update calib3d.hpp

36 files changed:
doc/js_tutorials/js_assets/js_houghlines_HoughLines.html
doc/js_tutorials/js_assets/js_houghlines_HoughLinesP.html
doc/tutorials/features2d/homography/homography.markdown
modules/calib3d/include/opencv2/calib3d.hpp
samples/cpp/dbt_face_detection.cpp
samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp
samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp
samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp
samples/cpp/tutorial_code/ImgProc/morph_lines_detection/Morphology_3.cpp
samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp
samples/cpp/tutorial_code/ImgTrans/houghlines.cpp
samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp
samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp
samples/cpp/tutorial_code/ShapeDescriptors/hull_demo.cpp
samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp
samples/cpp/tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp
samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp
samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp
samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp
samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp
samples/cpp/tutorial_code/features2D/AKAZE_match.cpp
samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp [moved from samples/cpp/tutorial_code/features2D/Homography/tutorial_homography_ex4_decompose_homography.cpp with 89% similarity, mode: 0644]
samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp [moved from samples/cpp/tutorial_code/features2D/Homography/tutorial_homography_ex3_homography_from_camera_displacement.cpp with 89% similarity, mode: 0644]
samples/cpp/tutorial_code/features2D/Homography/perspective_correction.cpp [moved from samples/cpp/tutorial_code/features2D/Homography/tutorial_homography_ex2_perspective_correction.cpp with 84% similarity, mode: 0644]
samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp [moved from samples/cpp/tutorial_code/features2D/Homography/tutorial_homography_ex1_pose_from_homography.cpp with 86% similarity, mode: 0644]
samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp
samples/cpp/tutorial_code/objectDetection/objectDetection.cpp
samples/cpp/tutorial_code/photo/decolorization/decolor.cpp
samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp
samples/cpp/tutorial_code/viz/histo3D.cpp
samples/cpp/tutorial_code/viz/widget_pose.cpp
samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp
samples/data/left_intrinsics.yml [moved from samples/cpp/tutorial_code/features2D/Homography/left_intrinsics.yml with 100% similarity]
samples/dnn/faster_rcnn.cpp

index 2edbe39..76aa6dc 100644 (file)
@@ -41,7 +41,7 @@
 <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);
index e69bf54..fdda01d 100644 (file)
@@ -41,7 +41,7 @@
 <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);
index 31aa402..8be683a 100644 (file)
@@ -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:
 
-@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*}
@@ -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:
 
-@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:
 
@@ -180,7 +180,7 @@ 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:
 
@@ -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:
 
-@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:
 
@@ -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:
 
-@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:
 
@@ -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}
 \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:
 
@@ -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}
 \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
 
@@ -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.
 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:
index 7145aa9..539fb50 100644 (file)
@@ -306,6 +306,12 @@ optimization procedures like calibrateCamera, stereoCalibrate, or solvePnP .
  */
 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
@@ -364,12 +370,6 @@ cannot be estimated, an empty one will be returned.
 @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,
@@ -525,6 +525,12 @@ CV_EXPORTS_W void projectPoints( InputArray objectPoints,
                                  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
index be61b87..a46ec12 100644 (file)
@@ -8,8 +8,6 @@
 #include <opencv2/objdetect.hpp>
 
 #include <stdio.h>
-#include <string>
-#include <vector>
 
 using namespace std;
 using namespace cv;
@@ -84,7 +82,7 @@ int main(int , char** )
     do
     {
         VideoStream >> ReferenceFrame;
-        cvtColor(ReferenceFrame, GrayFrame, COLOR_RGB2GRAY);
+        cvtColor(ReferenceFrame, GrayFrame, COLOR_BGR2GRAY);
         Detector.process(GrayFrame);
         Detector.getObjects(Faces);
 
index 80d4d46..7c7f4d4 100644 (file)
@@ -15,7 +15,7 @@ using namespace std;
 /**
  * @function main
  */
-int main( int, char** argv )
+int main( int argc, char** argv )
 {
   Mat src, dst;
 
@@ -23,12 +23,14 @@ int main( int, char** argv )
   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 );
index cfcd755..14526ae 100644 (file)
@@ -5,10 +5,11 @@
  */
 
 #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;
@@ -27,13 +28,17 @@ void Dilation( int, void* );
 /**
  * @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 );
index 6f843f6..ce71a3b 100644 (file)
@@ -7,6 +7,7 @@
 #include "opencv2/imgproc.hpp"
 #include "opencv2/imgcodecs.hpp"
 #include "opencv2/highgui.hpp"
+#include <iostream>
 
 using namespace cv;
 
@@ -32,15 +33,14 @@ void Morphology_Operations( int, void* );
 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]
index 1b0b4b7..31b3687 100644 (file)
@@ -11,16 +11,15 @@ void show_wait_destroy(const char* winname, cv::Mat img);
 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;
     }
 
index efdeca1..e77ef7b 100644 (file)
@@ -5,8 +5,8 @@
  */
 
 #include "opencv2/imgproc.hpp"
-#include "opencv2/imgcodecs.hpp"
 #include "opencv2/highgui.hpp"
+#include <iostream>
 
 using namespace cv;
 
@@ -56,13 +56,18 @@ static void CannyThreshold(int, void*)
 /**
  * @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]
index edbb1e7..93250a5 100644 (file)
@@ -20,7 +20,7 @@ const char* warp_rotate_window = "Warp + Rotate";
 /**
  * @function main
  */
-int main( int, char** argv )
+int main( int argc, char** argv )
 {
   Point2f srcTri[3];
   Point2f dstTri[3];
@@ -30,7 +30,14 @@ int main( int, char** argv )
   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() );
index bd07220..2a86941 100644 (file)
@@ -12,7 +12,7 @@ using namespace std;
 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 );
index 57f64c6..8180b9d 100644 (file)
@@ -16,7 +16,7 @@ int main(int argc, char** argv)
     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
index 1e5585a..ea0b2a4 100644 (file)
@@ -23,11 +23,18 @@ void thresh_callback(int, void* );
 /**
  * @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 );
@@ -84,8 +91,8 @@ void thresh_callback(int, void* )
   //![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]
index 742c6cf..169f8bf 100644 (file)
@@ -23,10 +23,17 @@ void thresh_callback(int, void* );
 /**
  * @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 );
@@ -63,9 +70,9 @@ void thresh_callback(int, void* )
   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
index e583791..c155908 100644 (file)
@@ -23,10 +23,17 @@ void thresh_callback(int, void* );
 /**
  * @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 );
@@ -62,7 +69,7 @@ void thresh_callback(int, void* )
   /// 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 );
index 4064048..6741cc6 100644 (file)
@@ -23,10 +23,18 @@ void thresh_callback(int, void* );
 /**
  * @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 );
@@ -51,12 +59,11 @@ void thresh_callback(int, void* )
 {
   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() );
@@ -73,7 +80,7 @@ void thresh_callback(int, void* )
   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 );
      }
 
@@ -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 ) );
        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 );
      }
 }
index 757b8dc..efc481a 100644 (file)
@@ -35,10 +35,9 @@ int main( void )
      { 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 );
@@ -67,11 +66,8 @@ int main( void )
           }
      }
 
-  /// 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);
index 52d7561..2b8471d 100644 (file)
@@ -4,7 +4,6 @@
  * @author OpenCV team
  */
 
-#include "opencv2/imgcodecs.hpp"
 #include "opencv2/highgui.hpp"
 #include "opencv2/imgproc.hpp"
 #include <iostream>
@@ -36,10 +35,17 @@ void myHarris_function( int, void* );
 /**
  * @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
index 4f1df4b..2d44eeb 100644 (file)
@@ -4,7 +4,6 @@
  * @author OpenCV team
  */
 
-#include "opencv2/imgcodecs.hpp"
 #include "opencv2/highgui.hpp"
 #include "opencv2/imgproc.hpp"
 #include <iostream>
@@ -26,10 +25,17 @@ void cornerHarris_demo( int, void* );
 /**
  * @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
index e58faea..daadf41 100644 (file)
@@ -4,7 +4,6 @@
  * @author OpenCV team
  */
 
-#include "opencv2/imgcodecs.hpp"
 #include "opencv2/highgui.hpp"
 #include "opencv2/imgproc.hpp"
 #include <iostream>
@@ -27,10 +26,17 @@ void goodFeaturesToTrack_Demo( int, void* );
 /**
  * @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
index 1626646..e72653f 100644 (file)
@@ -27,10 +27,17 @@ void goodFeaturesToTrack_Demo( int, void* );
 /**
  * @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
index f0e0ff1..1eb1df6 100755 (executable)
@@ -1,7 +1,6 @@
 #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;
@@ -10,13 +9,17 @@ using namespace cv;
 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;
@@ -153,16 +153,13 @@ void decomposeHomography(const string &img1Path, const string &img2Path, const S
     //! [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        | 9     | chessboard width }"
-      "{ height       | 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 }";
 }
 
@@ -170,19 +167,20 @@ int main(int argc, char *argv[])
 {
     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;
 }
@@ -168,16 +168,13 @@ void homographyFromCameraDisplacement(const string &img1Path, const string &img2
     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        | 9     | chessboard width }"
-      "{ height       | 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 }";
 }
 
@@ -185,19 +182,20 @@ int main(int argc, char *argv[])
 {
     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;
 }
@@ -92,15 +92,12 @@ void perspectiveCorrection(const string &img1Path, const string &img2Path, const
     //! [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        | 9     | chessboard width }"
-      "{ height       | 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[])
@@ -108,16 +105,17 @@ 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;
@@ -116,15 +116,12 @@ void poseEstimationFromCoplanarPoints(const string &imgPath, const string &intri
     //! [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        | 9     | chessboard width }"
-      "{ height       | 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 }";
 }
 
@@ -132,17 +129,18 @@ int main(int argc, char *argv[])
 {
     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;
index 851b32c..489bb88 100644 (file)
@@ -4,8 +4,10 @@
  * @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;
@@ -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
     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]
 }
 
@@ -59,7 +61,7 @@ double getOrientation(const vector<Point> &pts, Mat &img)
     }
 
     //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)),
@@ -98,15 +100,14 @@ int main(int argc, char** argv)
 {
 //! [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;
@@ -120,14 +121,13 @@ int main(int argc, char** argv)
 
     // 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)
     {
@@ -137,7 +137,7 @@ int main(int argc, char** argv)
         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);
     }
index 71097a8..6aa3f91 100644 (file)
@@ -1,9 +1,7 @@
 #include "opencv2/objdetect.hpp"
-#include "opencv2/videoio.hpp"
 #include "opencv2/highgui.hpp"
 #include "opencv2/imgproc.hpp"
 
-#include <iostream>
 #include <stdio.h>
 
 using namespace std;
@@ -26,12 +24,12 @@ int main( int argc, const char** argv )
         "{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;
 
@@ -54,8 +52,7 @@ int main( int argc, const char** argv )
         //-- 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;
 }
@@ -70,7 +67,7 @@ void detectAndDisplay( Mat frame )
     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++ )
     {
index 13c1b0c..c566dc7 100644 (file)
 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);
 }
index 8a24ddb..244e31a 100644 (file)
 *
 */
 
-#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);
     }
 
index 1b15737..0fb3735 100644 (file)
@@ -32,10 +32,10 @@ void  KeyboardViz3d(const viz::KeyboardEvent &w, void *t);
 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)
index 529a842..5de82bd 100644 (file)
@@ -56,12 +56,12 @@ int main()
     {
         /* 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;
index c118b76..04f2c3c 100644 (file)
@@ -19,15 +19,17 @@ using namespace cv;
 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;
index 67193d9..5c94afa 100644 (file)
@@ -27,9 +27,6 @@
 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   }"
@@ -53,9 +50,12 @@ int main(int argc, char** argv)
 {
     // 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;
     }