diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index b6cc6bc7c4..31d325cc70 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -273,6 +273,9 @@ of p and len. */ CV_EXPORTS_W int borderInterpolate(int p, int len, int borderType); +/** @example copyMakeBorder_demo.cpp +An example using copyMakeBorder function + */ /** @brief Forms a border around an image. The function copies the source image into the middle of the destination image. The areas to the @@ -471,6 +474,9 @@ The function can also be emulated with a matrix expression, for example: */ CV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst); +/** @example AddingImagesTrackbar.cpp + + */ /** @brief Calculates the weighted sum of two arrays. The function addWeighted calculates the weighted sum of two arrays as follows: diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 5e42232b65..1c86adb17c 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -2795,6 +2795,9 @@ CV_EXPORTS_W void adaptiveThreshold( InputArray src, OutputArray dst, //! @addtogroup imgproc_filter //! @{ +/** @example Pyramids.cpp +An example using pyrDown and pyrUp functions + */ /** @brief Blurs an image and downsamples it. By default, size of the output image is computed as `Size((src.cols+1)/2, (src.rows+1)/2)`, but in @@ -3669,6 +3672,9 @@ enum TemplateMatchModes { TM_CCOEFF_NORMED = 5 //!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{ \sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2} }\f] }; +/** @example MatchTemplate_Demo.cpp +An example using Template Matching algorithm + */ /** @brief Compares a template against overlapped image regions. The function slides through image , compares the overlapped patches of size \f$w \times h\f$ against @@ -4134,6 +4140,9 @@ enum ColormapTypes COLORMAP_PARULA = 12 //!< ![parula](pics/colormaps/colorscale_parula.jpg) }; +/** @example falsecolor.cpp +An example using applyColorMap function +*/ /** @brief Applies a GNU Octave/MATLAB equivalent colormap on a given image. @param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3. @@ -4216,6 +4225,9 @@ CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec, const Scalar& color, int thickness = 1, int lineType = LINE_8, int shift = 0); +/** @example Drawing_2.cpp +An example using drawing functions + */ /** @brief Draws a circle. The function circle draws a simple or filled circle with a given center and radius. @@ -4339,6 +4351,9 @@ CV_EXPORTS void fillPoly(Mat& img, const Point** pts, const Scalar& color, int lineType = LINE_8, int shift = 0, Point offset = Point() ); +/** @example Drawing_1.cpp +An example using drawing functions + */ /** @brief Fills the area bounded by one or more polygons. The function fillPoly fills an area bounded by several polygonal contours. The function can fill diff --git a/modules/objdetect/include/opencv2/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect.hpp index 432bee4d03..0747d67661 100644 --- a/modules/objdetect/include/opencv2/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect.hpp @@ -215,6 +215,8 @@ public: virtual Ptr getMaskGenerator() = 0; }; +/** @example facedetect.cpp +*/ /** @brief Cascade classifier class for object detection. */ class CV_EXPORTS_W CascadeClassifier @@ -348,6 +350,8 @@ struct DetectionROI std::vector confidences; }; +/**@example peopledetect.cpp + */ struct CV_EXPORTS_W HOGDescriptor { public: diff --git a/modules/photo/include/opencv2/photo.hpp b/modules/photo/include/opencv2/photo.hpp index 431a6324d6..6651ac80ac 100644 --- a/modules/photo/include/opencv2/photo.hpp +++ b/modules/photo/include/opencv2/photo.hpp @@ -730,6 +730,9 @@ CV_EXPORTS_W void decolor( InputArray src, OutputArray grayscale, OutputArray co //! @addtogroup photo_clone //! @{ +/** @example cloning_demo.cpp +An example using seamlessClone function +*/ /** @brief Image editing tasks concern either global changes (color/intensity corrections, filters, deformations) or local changes concerned to a selection. Here we are interested in achieving local changes, ones that are restricted to a region manually selected (ROI), in a seamless and effortless @@ -833,6 +836,9 @@ CV_EXPORTS_W void edgePreservingFilter(InputArray src, OutputArray dst, int flag CV_EXPORTS_W void detailEnhance(InputArray src, OutputArray dst, float sigma_s = 10, float sigma_r = 0.15f); +/** @example npr_demo.cpp +An example using non-photorealistic line drawing functions +*/ /** @brief Pencil-like non-photorealistic line drawing @param src Input 8-bit 3-channel image. diff --git a/modules/shape/include/opencv2/shape/shape_distance.hpp b/modules/shape/include/opencv2/shape/shape_distance.hpp index e4c3a87197..3a778f0525 100644 --- a/modules/shape/include/opencv2/shape/shape_distance.hpp +++ b/modules/shape/include/opencv2/shape/shape_distance.hpp @@ -53,6 +53,9 @@ namespace cv //! @addtogroup shape //! @{ +/** @example shape_example.cpp +An example using shape distance algorithm +*/ /** @brief Abstract base class for shape distance algorithms. */ class CV_EXPORTS_W ShapeDistanceExtractor : public Algorithm diff --git a/modules/video/include/opencv2/video/tracking.hpp b/modules/video/include/opencv2/video/tracking.hpp index 946596f36b..d397ac7aaf 100644 --- a/modules/video/include/opencv2/video/tracking.hpp +++ b/modules/video/include/opencv2/video/tracking.hpp @@ -78,7 +78,9 @@ See the OpenCV sample camshiftdemo.c that tracks colored objects. */ CV_EXPORTS_W RotatedRect CamShift( InputArray probImage, CV_IN_OUT Rect& window, TermCriteria criteria ); - +/** @example camshiftdemo.cpp +An example using the mean-shift tracking algorithm +*/ /** @brief Finds an object on a back projection image. @param probImage Back projection of the object histogram. See calcBackProject for details. @@ -97,8 +99,6 @@ projection and remove the noise. For example, you can do this by retrieving conn with findContours , throwing away contours with small area ( contourArea ), and rendering the remaining contours with drawContours. -@note -- A mean-shift tracking sample can be found at opencv_source_code/samples/cpp/camshiftdemo.cpp */ CV_EXPORTS_W int meanShift( InputArray probImage, CV_IN_OUT Rect& window, TermCriteria criteria ); @@ -123,6 +123,9 @@ CV_EXPORTS_W int buildOpticalFlowPyramid( InputArray img, OutputArrayOfArrays py int derivBorder = BORDER_CONSTANT, bool tryReuseInputImage = true ); +/** @example lkdemo.cpp +An example using the Lucas-Kanade optical flow algorithm + */ /** @brief Calculates an optical flow for a sparse feature set using the iterative Lucas-Kanade method with pyramids. @@ -258,6 +261,10 @@ enum MOTION_HOMOGRAPHY = 3 }; +/** @example image_alignment.cpp +An example using the image alignment ECC algorithm + */ + /** @brief Finds the geometric transform (warp) between two images in terms of the ECC criterion @cite EP08 . @param templateImage single-channel template image; CV_8U or CV_32F array. @@ -313,25 +320,20 @@ CV_EXPORTS_W double findTransformECC( InputArray templateImage, InputArray input TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001), InputArray inputMask = noArray()); +/** @example kalman.cpp +An example using the standard Kalman filter +*/ /** @brief Kalman filter class. The class implements a standard Kalman filter , @cite Welch95 . However, you can modify transitionMatrix, controlMatrix, and measurementMatrix to get -an extended Kalman filter functionality. See the OpenCV sample kalman.cpp. - -@note - -- An example using the standard Kalman filter can be found at - opencv_source_code/samples/cpp/kalman.cpp +an extended Kalman filter functionality. +@note In C API when CvKalman\* kalmanFilter structure is not needed anymore, it should be released +with cvReleaseKalman(&kalmanFilter) */ class CV_EXPORTS_W KalmanFilter { public: - /** @brief The constructors. - - @note In C API when CvKalman\* kalmanFilter structure is not needed anymore, it should be released - with cvReleaseKalman(&kalmanFilter) - */ CV_WRAP KalmanFilter(); /** @overload @param dynamParams Dimensionality of the state. diff --git a/modules/videoio/include/opencv2/videoio.hpp b/modules/videoio/include/opencv2/videoio.hpp index aa3f31a210..96d8df61e4 100644 --- a/modules/videoio/include/opencv2/videoio.hpp +++ b/modules/videoio/include/opencv2/videoio.hpp @@ -808,12 +808,12 @@ protected: class IVideoWriter; +/** @example videowriter_basic.cpp +An example using VideoCapture and VideoWriter class + */ /** @brief Video writer class. The class provides C++ API for writing video files or image sequences. - -Here is how the class can be used: -@include samples/cpp/videowriter_basic.cpp */ class CV_EXPORTS_W VideoWriter { diff --git a/samples/cpp/create_mask.cpp b/samples/cpp/create_mask.cpp index 7d6a61cfb4..c87d0fdaee 100644 --- a/samples/cpp/create_mask.cpp +++ b/samples/cpp/create_mask.cpp @@ -33,8 +33,6 @@ int flag1 = 0; int minx,miny,maxx,maxy,lenx,leny; -int channel; - void mouseHandler(int, int, int, int, void*); void mouseHandler(int event, int x, int y, int, void*) @@ -121,14 +119,22 @@ void mouseHandler(int event, int x, int y, int, void*) } } +static void help() +{ + cout << "\nThis program demonstrates using mouse events" + "\nCall:\n" + "./create_mask \n" + "\n" + "\tleft mouse button - set a point to create mask shape" + "\n" + "\tright mouse button - create mask from points\n" + "\tmiddle mouse button - reset\n" << endl; +} + int main(int argc, char **argv) { - cv::CommandLineParser parser(argc, argv, "{help h | | show help message}{@input | | input image}"); - if (parser.has("help")) - { - parser.printMessage(); - return 0; - } + cv::CommandLineParser parser(argc, argv, "{@input | ../data/lena.jpg | input image}"); + help(); string input_image = parser.get("@input"); if (input_image.empty()) { @@ -143,8 +149,6 @@ int main(int argc, char **argv) img0 = src; - channel = img0.channels(); - res1 = Mat::zeros(img0.size(),CV_8UC1); final = Mat::zeros(img0.size(),CV_8UC3); //////////// source image /////////////////// @@ -154,6 +158,5 @@ int main(int argc, char **argv) imshow("Source", img0); waitKey(0); - img0.release(); - img1.release(); + return 0; } diff --git a/samples/cpp/drawing.cpp b/samples/cpp/drawing.cpp index 236bcbcc62..93f09fe2e4 100644 --- a/samples/cpp/drawing.cpp +++ b/samples/cpp/drawing.cpp @@ -2,6 +2,7 @@ #include "opencv2/imgproc.hpp" #include "opencv2/highgui.hpp" #include + using namespace cv; static void help() @@ -16,14 +17,9 @@ static Scalar randomColor(RNG& rng) return Scalar(icolor&255, (icolor>>8)&255, (icolor>>16)&255); } -int main(int argc, char** argv) +int main() { - cv::CommandLineParser parser(argc, argv, "{help h||}"); - if (parser.has("help")) - { - help(); - return 0; - } + help(); char wndname[] = "Drawing Demo"; const int NUMBER = 100; const int DELAY = 5; @@ -36,7 +32,7 @@ int main(int argc, char** argv) imshow(wndname, image); waitKey(DELAY); - for (i = 0; i < NUMBER; i++) + for (i = 0; i < NUMBER * 2; i++) { Point pt1, pt2; pt1.x = rng.uniform(x1, x2); @@ -44,14 +40,19 @@ int main(int argc, char** argv) pt2.x = rng.uniform(x1, x2); pt2.y = rng.uniform(y1, y2); - line( image, pt1, pt2, randomColor(rng), rng.uniform(1,10), lineType ); + int arrowed = rng.uniform(0, 6); + + if( arrowed < 3 ) + line( image, pt1, pt2, randomColor(rng), rng.uniform(1,10), lineType ); + else + arrowedLine(image, pt1, pt2, randomColor(rng), rng.uniform(1, 10), lineType); imshow(wndname, image); if(waitKey(DELAY) >= 0) return 0; } - for (i = 0; i < NUMBER; i++) + for (i = 0; i < NUMBER * 2; i++) { Point pt1, pt2; pt1.x = rng.uniform(x1, x2); @@ -59,8 +60,13 @@ int main(int argc, char** argv) pt2.x = rng.uniform(x1, x2); pt2.y = rng.uniform(y1, y2); int thickness = rng.uniform(-3, 10); + int marker = rng.uniform(0, 10); + int marker_size = rng.uniform(30, 80); - rectangle( image, pt1, pt2, randomColor(rng), MAX(thickness, -1), lineType ); + if (marker > 5) + rectangle(image, pt1, pt2, randomColor(rng), MAX(thickness, -1), lineType); + else + drawMarker(image, pt1, randomColor(rng), marker, marker_size ); imshow(wndname, image); if(waitKey(DELAY) >= 0) @@ -181,7 +187,3 @@ int main(int argc, char** argv) waitKey(); return 0; } - -#ifdef _EiC -main(1,"drawing.c"); -#endif diff --git a/samples/cpp/edge.cpp b/samples/cpp/edge.cpp index 4fbef937a1..78bc4b6f7b 100644 --- a/samples/cpp/edge.cpp +++ b/samples/cpp/edge.cpp @@ -53,15 +53,11 @@ const char* keys = int main( int argc, const char** argv ) { + help(); CommandLineParser parser(argc, argv, keys); - if (parser.has("help")) - { - help(); - return 0; - } string filename = parser.get(0); - image = imread(filename, 1); + image = imread(filename, IMREAD_COLOR); if(image.empty()) { printf("Cannot read image file: %s\n", filename.c_str()); diff --git a/samples/cpp/falsecolor.cpp b/samples/cpp/falsecolor.cpp index a72711c1e4..3e62434cf0 100644 --- a/samples/cpp/falsecolor.cpp +++ b/samples/cpp/falsecolor.cpp @@ -125,11 +125,15 @@ static Mat DrawMyImage(int thickness,int nbShape) return img; } -int main(void) +int main(int argc, char** argv) { ParamColorMar p; - Mat img= DrawMyImage(2,256); + Mat img; + if (argc > 1) + img = imread(argv[1], 0); + else + img = DrawMyImage(2,256); p.img=img; p.iColormap=0; diff --git a/samples/cpp/grabcut.cpp b/samples/cpp/grabcut.cpp index 54edbf61ec..c5b68fca72 100644 --- a/samples/cpp/grabcut.cpp +++ b/samples/cpp/grabcut.cpp @@ -276,12 +276,9 @@ static void on_mouse( int event, int x, int y, int flags, void* param ) int main( int argc, char** argv ) { - cv::CommandLineParser parser(argc, argv, "{help h||}{@input||}"); - if (parser.has("help")) - { - help(); - return 0; - } + cv::CommandLineParser parser(argc, argv, "{@input| ../data/messi5.jpg |}"); + help(); + string filename = parser.get("@input"); if( filename.empty() ) { @@ -295,8 +292,6 @@ int main( int argc, char** argv ) return 1; } - help(); - const string winName = "image"; namedWindow( winName, WINDOW_AUTOSIZE ); setMouseCallback( winName, on_mouse, 0 ); diff --git a/samples/cpp/image_alignment.cpp b/samples/cpp/image_alignment.cpp index c62a1608da..2f0aa507f9 100644 --- a/samples/cpp/image_alignment.cpp +++ b/samples/cpp/image_alignment.cpp @@ -51,7 +51,7 @@ const std::string keys = "{e epsilon | 0.0001 | ECC's convergence epsilon }" "{o outputWarp | outWarp.ecc | output warp (matrix) filename }" "{m motionType | affine | type of motion (translation, euclidean, affine, homography) }" - "{v verbose | 0 | display initial and final images }" + "{v verbose | 1 | display initial and final images }" "{w warpedImfile | warpedECC.png | warped input image }" "{h help | | print help message }" ; @@ -165,10 +165,10 @@ static void draw_warped_roi(Mat& image, const int width, const int height, Mat& GET_HOMO_VALUES(U, bottom_right.x, bottom_right.y); // draw the warped perimeter - line(image, top_left, top_right, Scalar(255,0,255)); - line(image, top_right, bottom_right, Scalar(255,0,255)); - line(image, bottom_right, bottom_left, Scalar(255,0,255)); - line(image, bottom_left, top_left, Scalar(255,0,255)); + line(image, top_left, top_right, Scalar(255)); + line(image, top_right, bottom_right, Scalar(255)); + line(image, bottom_right, bottom_left, Scalar(255)); + line(image, bottom_left, top_left, Scalar(255)); } int main (const int argc, const char * argv[]) @@ -177,17 +177,9 @@ int main (const int argc, const char * argv[]) CommandLineParser parser(argc, argv, keys); parser.about("ECC demo"); - if (argc < 2) { - parser.printMessage(); - help(); - return 1; - } - if (parser.has("help")) - { - parser.printMessage(); - help(); - return 1; - } + parser.printMessage(); + help(); + string imgFile = parser.get(0); string tempImgFile = parser.get(1); string inWarpFile = parser.get(2); @@ -239,10 +231,10 @@ int main (const int argc, const char * argv[]) } } - else{ //apply random waro to input image + else{ //apply random warp to input image resize(inputImage, target_image, Size(216, 216)); Mat warpGround; - cv::RNG rng; + RNG rng(getTickCount()); double angle; switch (mode_temp) { case MOTION_TRANSLATION: @@ -299,7 +291,7 @@ int main (const int argc, const char * argv[]) } else { - printf("\n ->Perfomarnce Warning: Identity warp ideally assumes images of " + printf("\n ->Performance Warning: Identity warp ideally assumes images of " "similar size. If the deformation is strong, the identity warp may not " "be a good initialization. \n"); @@ -363,7 +355,8 @@ int main (const int argc, const char * argv[]) namedWindow ("warped image", WINDOW_AUTOSIZE); namedWindow ("error (black: no error)", WINDOW_AUTOSIZE); - moveWindow ("template", 350, 350); + moveWindow ("image", 20, 300); + moveWindow ("template", 300, 300); moveWindow ("warped image", 600, 300); moveWindow ("error (black: no error)", 900, 300); diff --git a/samples/cpp/image_sequence.cpp b/samples/cpp/image_sequence.cpp index 6a84fab4bd..ac99f785d9 100644 --- a/samples/cpp/image_sequence.cpp +++ b/samples/cpp/image_sequence.cpp @@ -18,17 +18,12 @@ static void help(char** argv) int main(int argc, char** argv) { - cv::CommandLineParser parser(argc, argv, "{help h||}{@image||}"); - if (parser.has("help")) - { - help(argv); - return 0; - } + help(argv); + cv::CommandLineParser parser(argc, argv, "{@image| ../data/left%02d.jpg |}"); string first_file = parser.get("@image"); if(first_file.empty()) { - help(argv); return 1; } diff --git a/samples/cpp/inpaint.cpp b/samples/cpp/inpaint.cpp index 86e6e37416..61c4c45cbd 100644 --- a/samples/cpp/inpaint.cpp +++ b/samples/cpp/inpaint.cpp @@ -47,12 +47,9 @@ static void onMouse( int event, int x, int y, int flags, void* ) int main( int argc, char** argv ) { - cv::CommandLineParser parser(argc, argv, "{help h||}{@image|../data/fruits.jpg|}"); - if (parser.has("help")) - { - help(); - return 0; - } + cv::CommandLineParser parser(argc, argv, "{@image|../data/fruits.jpg|}"); + help(); + string filename = parser.get("@image"); Mat img0 = imread(filename, -1); if(img0.empty()) diff --git a/samples/cpp/laplace.cpp b/samples/cpp/laplace.cpp index 958fccb608..d50029cb31 100644 --- a/samples/cpp/laplace.cpp +++ b/samples/cpp/laplace.cpp @@ -26,12 +26,9 @@ int smoothType = GAUSSIAN; int main( int argc, char** argv ) { VideoCapture cap; - cv::CommandLineParser parser(argc, argv, "{help h | | }{ c | 0 | }{ p | | }"); - if ( parser.has("help") ) - { - help(); - return 0; - } + cv::CommandLineParser parser(argc, argv, "{ c | 0 | }{ p | | }"); + help(); + if( parser.get("c").size() == 1 && isdigit(parser.get("c")[0]) ) cap.open(parser.get("c")); else diff --git a/samples/cpp/letter_recog.cpp b/samples/cpp/letter_recog.cpp index 0eb67d1e42..32ccf6b09b 100644 --- a/samples/cpp/letter_recog.cpp +++ b/samples/cpp/letter_recog.cpp @@ -521,7 +521,7 @@ int main( int argc, char *argv[] ) int method = 0; cv::CommandLineParser parser(argc, argv, "{data|../data/letter-recognition.data|}{save||}{load||}{boost||}" - "{mlp||}{knn knearest||}{nbayes||}{svm||}{help h||}"); + "{mlp||}{knn knearest||}{nbayes||}{svm||}"); data_filename = parser.get("data"); if (parser.has("save")) filename_to_save = parser.get("save"); @@ -537,11 +537,9 @@ int main( int argc, char *argv[] ) method = 4; else if (parser.has("svm")) method = 5; - if (parser.has("help")) - { - help(); - return 0; - } + + help(); + if( (method == 0 ? build_rtrees_classifier( data_filename, filename_to_save, filename_to_load ) : method == 1 ? @@ -555,8 +553,6 @@ int main( int argc, char *argv[] ) method == 5 ? build_svm_classifier( data_filename, filename_to_save, filename_to_load ): -1) < 0) - { - help(); - } + return 0; } diff --git a/samples/cpp/lkdemo.cpp b/samples/cpp/lkdemo.cpp index 5e57aa84a4..f8ba732931 100644 --- a/samples/cpp/lkdemo.cpp +++ b/samples/cpp/lkdemo.cpp @@ -45,16 +45,11 @@ int main( int argc, char** argv ) bool needToInit = false; bool nightMode = false; - cv::CommandLineParser parser(argc, argv, "{@input||}{help h||}"); + help(); + cv::CommandLineParser parser(argc, argv, "{@input|0|}"); string input = parser.get("@input"); - if (parser.has("help")) - { - help(); - return 0; - } - if( input.empty() ) - cap.open(0); - else if( input.size() == 1 && isdigit(input[0]) ) + + if( input.size() == 1 && isdigit(input[0]) ) cap.open(input[0] - '0'); else cap.open(input); diff --git a/samples/cpp/mask_tmpl.cpp b/samples/cpp/mask_tmpl.cpp index 6617783266..b20c3eefd4 100644 --- a/samples/cpp/mask_tmpl.cpp +++ b/samples/cpp/mask_tmpl.cpp @@ -19,16 +19,12 @@ static void help() int main( int argc, const char** argv ) { + help(); cv::CommandLineParser parser(argc, argv, - "{help h||}" "{ i | ../data/lena_tmpl.jpg | }" "{ t | ../data/tmpl.png | }" "{ m | ../data/mask.png | }"); - if (parser.has("help")) - { - help(); - return 0; - } + string filename = parser.get("i"); string tmplname = parser.get("t"); string maskname = parser.get("m"); diff --git a/samples/cpp/npr_demo.cpp b/samples/cpp/npr_demo.cpp index 64a3e05389..c343969ff6 100644 --- a/samples/cpp/npr_demo.cpp +++ b/samples/cpp/npr_demo.cpp @@ -28,7 +28,7 @@ using namespace cv; int main(int argc, char* argv[]) { - cv::CommandLineParser parser(argc, argv, "{help h||show help message}{@image||input image}"); + cv::CommandLineParser parser(argc, argv, "{help h||show help message}{@image|../data/lena.jpg|input image}"); if (parser.has("help")) { parser.printMessage(); diff --git a/samples/cpp/polar_transforms.cpp b/samples/cpp/polar_transforms.cpp index adbc955b17..d860e27981 100644 --- a/samples/cpp/polar_transforms.cpp +++ b/samples/cpp/polar_transforms.cpp @@ -53,14 +53,13 @@ int main( int argc, char** argv ) break; Point2f center( (float)frame.cols / 2, (float)frame.rows / 2 ); - double radius = (double)frame.cols / 4; - double M = (double)frame.cols / log(radius); + double M = 70; logPolar(frame,log_polar_img, center, M, INTER_LINEAR + WARP_FILL_OUTLIERS); - linearPolar(frame,lin_polar_img, center, radius, INTER_LINEAR + WARP_FILL_OUTLIERS); + linearPolar(frame,lin_polar_img, center, M, INTER_LINEAR + WARP_FILL_OUTLIERS); logPolar(log_polar_img, recovered_log_polar, center, M, WARP_INVERSE_MAP + INTER_LINEAR); - linearPolar(lin_polar_img, recovered_lin_polar_img, center, radius, WARP_INVERSE_MAP + INTER_LINEAR + WARP_FILL_OUTLIERS); + linearPolar(lin_polar_img, recovered_lin_polar_img, center, M, WARP_INVERSE_MAP + INTER_LINEAR + WARP_FILL_OUTLIERS); imshow("Log-Polar", log_polar_img ); imshow("Linear-Polar", lin_polar_img ); diff --git a/samples/cpp/shape_example.cpp b/samples/cpp/shape_example.cpp index cb6cfbeef4..120d94798b 100644 --- a/samples/cpp/shape_example.cpp +++ b/samples/cpp/shape_example.cpp @@ -115,6 +115,7 @@ int main(int argc, char** argv) resize(iiIm, bestToShow, sz2Sh); imshow("BEST MATCH", bestToShow); moveWindow("BEST MATCH", sz2Sh.width+50,0); + waitKey(); return 0; } diff --git a/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp b/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp index 1834e35e22..563e35dc2b 100644 --- a/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp +++ b/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp @@ -40,10 +40,15 @@ static void on_trackbar( int, void* ) * @function main * @brief Main function */ -int main( int, char** argv ) +int main( int argc, char** argv ) { /// Read image given by user - image = imread( argv[1] ); + String imageName("../data/lena.jpg"); // by default + if (argc > 1) + { + imageName = argv[1]; + } + image = imread( imageName ); /// Initialize values alpha = 1; @@ -54,8 +59,8 @@ int main( int, char** argv ) namedWindow("New Image", 1); /// Create Trackbars - createTrackbar( "Contrast Trackbar", "New Image", &alpha, alpha_max, on_trackbar ); - createTrackbar( "Brightness Trackbar", "New Image", &beta, beta_max, on_trackbar ); + createTrackbar( "Contrast", "New Image", &alpha, alpha_max, on_trackbar ); + createTrackbar( "Brightness", "New Image", &beta, beta_max, on_trackbar ); /// Show some stuff imshow("Original Image", image); diff --git a/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp b/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp index 2535782087..0f325545c8 100644 --- a/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp +++ b/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp @@ -15,7 +15,7 @@ using namespace cv; * @function main * @brief Main function */ -int main( int, char** argv ) +int main( int argc, char** argv ) { //! [basic-linear-transform-parameters] double alpha = 1.0; /*< Simple contrast control */ @@ -24,7 +24,12 @@ int main( int, char** argv ) /// Read image given by user //! [basic-linear-transform-load] - Mat image = imread( argv[1] ); + String imageName("../data/lena.jpg"); // by default + if (argc > 1) + { + imageName = argv[1]; + } + Mat image = imread( imageName ); //! [basic-linear-transform-load] //! [basic-linear-transform-output] Mat new_image = Mat::zeros( image.size(), image.type() ); diff --git a/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp b/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp index 7a8fb57284..6f843f6880 100644 --- a/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp @@ -29,10 +29,15 @@ void Morphology_Operations( 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 + String imageName("../data/baboon.jpg"); // by default + if (argc > 1) + { + imageName = argv[1]; + } + src = imread(imageName, IMREAD_COLOR); // Load an image if( src.empty() ) { return -1; } diff --git a/samples/cpp/tutorial_code/ImgProc/Threshold.cpp b/samples/cpp/tutorial_code/ImgProc/Threshold.cpp index d057ebcdcf..c127b7d33d 100644 --- a/samples/cpp/tutorial_code/ImgProc/Threshold.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Threshold.cpp @@ -30,10 +30,15 @@ void Threshold_Demo( 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 + String imageName("../data/stuff.jpg"); // by default + if (argc > 1) + { + imageName = argv[1]; + } + src = imread( imageName, IMREAD_COLOR ); // Load an image if( src.empty() ) { return -1; } diff --git a/samples/cpp/tutorial_code/ImgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.cpp b/samples/cpp/tutorial_code/ImgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.cpp index 7fc28f03d1..7ee22a2258 100644 --- a/samples/cpp/tutorial_code/ImgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.cpp +++ b/samples/cpp/tutorial_code/ImgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.cpp @@ -58,9 +58,16 @@ void on_gamma_correction_trackbar(int, void *) } } -int main( int, char** argv ) +int main( int argc, char** argv ) { - img_original = imread( argv[1] ); + + String imageName("../data/lena.jpg"); // by default + if (argc > 1) + { + imageName = argv[1]; + } + + img_original = imread( imageName ); img_corrected = Mat(img_original.rows, img_original.cols*2, img_original.type()); img_gamma_corrected = Mat(img_original.rows, img_original.cols*2, img_original.type()); diff --git a/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp index 2911b9d1c0..604b57f41e 100644 --- a/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp @@ -21,7 +21,7 @@ namespace const std::string usage = "Usage : tutorial_HoughCircle_Demo \n"; // initial and max values of the parameters of interests. - const int cannyThresholdInitialValue = 200; + const int cannyThresholdInitialValue = 100; const int accumulatorThresholdInitialValue = 50; const int maxAccumulatorThreshold = 200; const int maxCannyThreshold = 255; @@ -55,15 +55,13 @@ int main(int argc, char** argv) { Mat src, src_gray; - if (argc < 2) + // Read the image + String imageName("../data/stuff.jpg"); // by default + if (argc > 1) { - std::cerr<<"No input image specified\n"; - std::cout< 1) + { + imageName = argv[1]; + } + src = imread( imageName, IMREAD_COLOR ); if( src.empty() ) { help(); diff --git a/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp index 6a41c3a1c3..0f56c49df7 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp @@ -13,7 +13,7 @@ using namespace cv; /** * @function main */ -int main( int, char** argv ) +int main( int argc, char** argv ) { //![variables] Mat src, src_gray, dst; @@ -25,7 +25,12 @@ int main( int, char** argv ) //![variables] //![load] - src = imread( argv[1], IMREAD_COLOR ); // Load an image + String imageName("../data/lena.jpg"); // by default + if (argc > 1) + { + imageName = argv[1]; + } + src = imread( imageName, IMREAD_COLOR ); // Load an image if( src.empty() ) { return -1; } diff --git a/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp index afe7024e75..4cc3bb84c3 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp @@ -23,10 +23,12 @@ void update_map( void ); /** * @function main */ -int main( int, char** argv ) +int main(int argc, const char** argv) { /// Load the image - src = imread( argv[1], IMREAD_COLOR ); + CommandLineParser parser(argc, argv, "{@image |../data/chicky_512.png|input image name}"); + std::string filename = parser.get(0); + src = imread( filename, IMREAD_COLOR ); /// Create dst, map_x and map_y with the same size as src: dst.create( src.size(), src.type() ); diff --git a/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp index ad45452021..d5a3776aa7 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp @@ -13,7 +13,7 @@ using namespace cv; /** * @function main */ -int main( int, char** argv ) +int main( int argc, char** argv ) { //![variables] Mat src, src_gray; @@ -25,7 +25,12 @@ int main( int, char** argv ) //![variables] //![load] - src = imread( argv[1], IMREAD_COLOR ); // Load an image + String imageName("../data/lena.jpg"); // by default + if (argc > 1) + { + imageName = argv[1]; + } + src = imread( imageName, IMREAD_COLOR ); // Load an image if( src.empty() ) { return -1; } diff --git a/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp b/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp index 3b9ad0d5ce..ca78078eea 100644 --- a/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp @@ -21,10 +21,15 @@ RNG rng(12345); /** * @function main */ -int main( int, char** argv ) +int main( int argc, char** argv ) { //![load] - src = imread( argv[1], IMREAD_COLOR ); // Load an image + String imageName("../data/lena.jpg"); // by default + if (argc > 1) + { + imageName = argv[1]; + } + src = imread( imageName, IMREAD_COLOR ); // Load an image if( src.empty() ) { diff --git a/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp b/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp index 81a6fc002f..24aef46b97 100644 --- a/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp @@ -13,7 +13,7 @@ using namespace cv; /** * @function main */ -int main ( int, char** argv ) +int main ( int argc, char** argv ) { /// Declare variables Mat src, dst; @@ -26,7 +26,12 @@ int main ( int, char** argv ) const char* window_name = "filter2D Demo"; //![load] - src = imread( argv[1], IMREAD_COLOR ); // Load an image + String imageName("../data/lena.jpg"); // by default + if (argc > 1) + { + imageName = argv[1]; + } + src = imread( imageName, IMREAD_COLOR ); // Load an image if( src.empty() ) { return -1; } diff --git a/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp b/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp index 424a4901ec..01783cc62d 100644 --- a/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp @@ -10,11 +10,11 @@ using namespace std; using namespace cv; -int main(int, char** argv) +int main() { //! [load_image] // Load the image - Mat src = imread(argv[1]); + Mat src = imread("../data/cards.png"); // Check if everything was fine if (!src.data) diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp index b831441b33..233800e901 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp @@ -23,10 +23,16 @@ void thresh_callback(int, void* ); /** * @function main */ -int main( int, char** argv ) +int main( int argc, char** argv ) { /// Load source image - src = imread(argv[1], IMREAD_COLOR); + String imageName("../data/happyfish.jpg"); // by default + if (argc > 1) + { + imageName = argv[1]; + } + src = imread(imageName, IMREAD_COLOR); + if (src.empty()) { cerr << "No image supplied ..." << endl; diff --git a/samples/cpp/tutorial_code/calib3d/stereoBM/SBM_Sample.cpp b/samples/cpp/tutorial_code/calib3d/stereoBM/SBM_Sample.cpp index d114a9582f..e024b215f1 100644 --- a/samples/cpp/tutorial_code/calib3d/stereoBM/SBM_Sample.cpp +++ b/samples/cpp/tutorial_code/calib3d/stereoBM/SBM_Sample.cpp @@ -19,14 +19,13 @@ void readme(); * @function main * @brief Main function */ -int main( int argc, char** argv ) +int main() { - if( argc != 3 ) - { readme(); return -1; } + readme(); //-- 1. Read the images - Mat imgLeft = imread( argv[1], IMREAD_GRAYSCALE ); - Mat imgRight = imread( argv[2], IMREAD_GRAYSCALE ); + Mat imgLeft = imread( "../data/rubberwhale1.png", IMREAD_GRAYSCALE ); + Mat imgRight = imread( "../data/rubberwhale2.png", IMREAD_GRAYSCALE ); //-- And create the image in which we will save our disparities Mat imgDisparity16S = Mat( imgLeft.rows, imgLeft.cols, CV_16S ); Mat imgDisparity8U = Mat( imgLeft.rows, imgLeft.cols, CV_8UC1 ); diff --git a/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp b/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp index 7018b703fb..f0e0ff1f10 100755 --- a/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp +++ b/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp @@ -63,7 +63,7 @@ int main(void) Mat res; drawMatches(img1, inliers1, img2, inliers2, good_matches, res); - imwrite("res.png", res); + imwrite("akaze_result.png", res); double inlier_ratio = inliers1.size() * 1.0 / matched1.size(); cout << "A-KAZE Matching Results" << endl; @@ -75,5 +75,8 @@ int main(void) cout << "# Inliers Ratio: \t" << inlier_ratio << endl; cout << endl; + imshow("result", res); + waitKey(); + return 0; } diff --git a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp index 6ccb83119a..e4673f82f5 100755 --- a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp +++ b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp @@ -120,27 +120,27 @@ Mat Tracker::process(const Mat frame, Stats& stats) int main(int argc, char **argv) { - if(argc < 2) { - cerr << "Usage: " << endl - << "akaze_track input_path" << endl - << " (input_path can be a camera id, like 0,1,2 or a video filename)" << endl; - return 1; - } + cerr << "Usage: " << endl + << "akaze_track input_path" << endl + << " (input_path can be a camera id, like 0,1,2 or a video filename)" << endl; - std::string video_name = argv[1]; - std::stringstream ssFormat; - ssFormat << atoi(argv[1]); + CommandLineParser parser(argc, argv, "{@input_path |0|input path can be a camera id, like 0,1,2 or a video filename}"); + string input_path = parser.get(0); + string video_name = input_path; VideoCapture video_in; - if (video_name.compare(ssFormat.str())==0) { //test str==str(num) - video_in.open(atoi(argv[1])); + + if ( ( isdigit(input_path[0]) && input_path.size() == 1 ) ) + { + int camera_no = input_path[0] - '0'; + video_in.open( camera_no ); } else { video_in.open(video_name); } if(!video_in.isOpened()) { - cerr << "Couldn't open " << argv[1] << endl; + cerr << "Couldn't open " << video_name << endl; return 1; } diff --git a/samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp b/samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp index 97ac8e8047..851b32ce77 100644 --- a/samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp +++ b/samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp @@ -94,12 +94,16 @@ double getOrientation(const vector &pts, Mat &img) /** * @function main */ -int main(int, char** argv) +int main(int argc, char** argv) { //! [pre-process] // Load image -// Mat src = imread("pca_test1.jpg"); - Mat src = imread(argv[1]); + String imageName("../data/pca_test1.jpg"); // by default + if (argc > 1) + { + imageName = argv[1]; + } + Mat src = imread( imageName ); // Check if image is loaded successfully if(!src.data || src.empty()) diff --git a/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp b/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp index 2fd0bb9b3a..c118b7661c 100644 --- a/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp +++ b/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp @@ -81,7 +81,7 @@ int main(void) Mat res; drawMatches(img1, inliers1, img2, inliers2, good_matches, res); - imwrite("../../samples/data/latch_res.png", res); + imwrite("latch_result.png", res); double inlier_ratio = inliers1.size() * 1.0 / matched1.size(); @@ -93,6 +93,10 @@ int main(void) cout << "# Inliers: \t" << inliers1.size() << endl; cout << "# Inliers Ratio: \t" << inlier_ratio << endl; cout << endl; + + imshow("result", res); + waitKey(); + return 0; }