From c4c31f5bba19fb701c30066c6039ee6eb187edd1 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 31 Oct 2018 15:48:56 +0300 Subject: [PATCH] samples: use findFile() in "cpp" --- samples/cpp/application_trace.cpp | 2 +- samples/cpp/bgfg_segm.cpp | 3 + samples/cpp/calibration.cpp | 25 ++++- samples/cpp/cloning_demo.cpp | 54 ++++++----- samples/cpp/cloning_gui.cpp | 12 +-- samples/cpp/connected_components.cpp | 4 +- samples/cpp/create_mask.cpp | 8 +- samples/cpp/dbt_face_detection.cpp | 2 +- samples/cpp/demhist.cpp | 6 +- samples/cpp/detect_blob.cpp | 26 +++--- samples/cpp/detect_mser.cpp | 2 +- samples/cpp/dft.cpp | 6 +- samples/cpp/distrans.cpp | 6 +- samples/cpp/edge.cpp | 6 +- samples/cpp/facedetect.cpp | 32 ++++--- samples/cpp/facial_features.cpp | 30 +++--- samples/cpp/falsecolor.cpp | 2 +- samples/cpp/ffilldemo.cpp | 6 +- samples/cpp/filestorage.cpp | 4 +- samples/cpp/fitellipse.cpp | 6 +- samples/cpp/grabcut.cpp | 4 +- samples/cpp/gstreamer_pipeline.cpp | 1 + samples/cpp/image.cpp | 6 +- samples/cpp/image_alignment.cpp | 12 +-- samples/cpp/inpaint.cpp | 12 +-- samples/cpp/laplace.cpp | 51 +++++----- samples/cpp/letter_recog.cpp | 6 +- samples/cpp/live_detect_qrcode.cpp | 104 ++++++++++----------- samples/cpp/logistic_regression.cpp | 2 +- samples/cpp/lsd_lines.cpp | 4 +- samples/cpp/mask_tmpl.cpp | 24 +++-- samples/cpp/matchmethod_orb_akaze_brisk.cpp | 38 ++++---- samples/cpp/minarea.cpp | 2 +- samples/cpp/morphology2.cpp | 19 ++-- samples/cpp/npr_demo.cpp | 14 +-- samples/cpp/peopledetect.cpp | 5 +- samples/cpp/points_classifier.cpp | 5 - samples/cpp/polar_transforms.cpp | 2 +- samples/cpp/segment_objects.cpp | 2 +- samples/cpp/select3dobj.cpp | 2 +- samples/cpp/smiledetect.cpp | 11 ++- samples/cpp/squares.cpp | 9 +- samples/cpp/stereo_calib.cpp | 9 +- samples/cpp/stereo_match.cpp | 4 +- samples/cpp/stitching.cpp | 2 +- samples/cpp/stitching_detailed.cpp | 4 +- .../src/main_detection.cpp | 2 +- samples/cpp/tvl1_optical_flow.cpp | 4 +- samples/cpp/warpPerspective_demo.cpp | 6 +- samples/cpp/watershed.cpp | 8 +- samples/data/calibration.yml | 15 +++ samples/python/facedetect.py | 6 +- 52 files changed, 355 insertions(+), 282 deletions(-) create mode 100644 samples/data/calibration.yml diff --git a/samples/cpp/application_trace.cpp b/samples/cpp/application_trace.cpp index fa77542..4c03e48 100644 --- a/samples/cpp/application_trace.cpp +++ b/samples/cpp/application_trace.cpp @@ -41,7 +41,7 @@ int main(int argc, char** argv) if (video.size() == 1 && isdigit(video[0])) capture.open(parser.get("@video")); else - capture.open(video); + capture.open(samples::findFileOrKeep(video)); // keep GStreamer pipelines int nframes = 0; if (capture.isOpened()) { diff --git a/samples/cpp/bgfg_segm.cpp b/samples/cpp/bgfg_segm.cpp index 9fc2780..0537775 100644 --- a/samples/cpp/bgfg_segm.cpp +++ b/samples/cpp/bgfg_segm.cpp @@ -38,7 +38,10 @@ int main(int argc, const char** argv) if (file.empty()) cap.open(camera); else + { + file = samples::findFileOrKeep(file); // ignore gstreamer pipelines cap.open(file.c_str()); + } if (!cap.isOpened()) { cout << "Can not open video stream: '" << (file.empty() ? "" : file) << "'" << endl; diff --git a/samples/cpp/calibration.cpp b/samples/cpp/calibration.cpp index 251ab83..53cade6 100644 --- a/samples/cpp/calibration.cpp +++ b/samples/cpp/calibration.cpp @@ -254,12 +254,31 @@ static bool readStringList( const string& filename, vector& l ) FileStorage fs(filename, FileStorage::READ); if( !fs.isOpened() ) return false; + size_t dir_pos = filename.rfind('/'); + if (dir_pos == string::npos) + dir_pos = filename.rfind('\\'); FileNode n = fs.getFirstTopLevelNode(); if( n.type() != FileNode::SEQ ) return false; FileNodeIterator it = n.begin(), it_end = n.end(); for( ; it != it_end; ++it ) - l.push_back((string)*it); + { + string fname = (string)*it; + if (dir_pos != string::npos) + { + string fpath = samples::findFile(filename.substr(0, dir_pos + 1) + fname, false); + if (fpath.empty()) + { + fpath = samples::findFile(fname); + } + fname = fpath; + } + else + { + fname = samples::findFile(fname); + } + l.push_back(fname); + } return true; } @@ -383,10 +402,10 @@ int main( int argc, char** argv ) if( !inputFilename.empty() ) { - if( !videofile && readStringList(inputFilename, imageList) ) + if( !videofile && readStringList(samples::findFile(inputFilename), imageList) ) mode = CAPTURING; else - capture.open(inputFilename); + capture.open(samples::findFileOrKeep(inputFilename)); } else capture.open(cameraId); diff --git a/samples/cpp/cloning_demo.cpp b/samples/cpp/cloning_demo.cpp index 25729db..43f6e20 100644 --- a/samples/cpp/cloning_demo.cpp +++ b/samples/cpp/cloning_demo.cpp @@ -17,8 +17,7 @@ * The program takes as input a source and a destination image (for 1-3 methods) * and outputs the cloned image. * -* Download test images from opencv_extra folder @github. -* +* Download test images from opencv_extra repository. */ #include "opencv2/photo.hpp" @@ -27,7 +26,6 @@ #include "opencv2/highgui.hpp" #include "opencv2/core.hpp" #include -#include using namespace std; using namespace cv; @@ -35,6 +33,7 @@ using namespace cv; int main() { cout << endl; + cout << "Note: specify OPENCV_SAMPLES_DATA_PATH_HINT=/testdata/cv" << endl << endl; cout << "Cloning Module" << endl; cout << "---------------" << endl; cout << "Options: " << endl; @@ -54,9 +53,9 @@ int main() if(num == 1) { string folder = "cloning/Normal_Cloning/"; - string original_path1 = folder + "source1.png"; - string original_path2 = folder + "destination1.png"; - string original_path3 = folder + "mask.png"; + string original_path1 = samples::findFile(folder + "source1.png"); + string original_path2 = samples::findFile(folder + "destination1.png"); + string original_path3 = samples::findFile(folder + "mask.png"); Mat source = imread(original_path1, IMREAD_COLOR); Mat destination = imread(original_path2, IMREAD_COLOR); @@ -86,14 +85,14 @@ int main() seamlessClone(source, destination, mask, p, result, 1); imshow("Output",result); - imwrite(folder + "cloned.png", result); + imwrite("cloned.png", result); } else if(num == 2) { string folder = "cloning/Mixed_Cloning/"; - string original_path1 = folder + "source1.png"; - string original_path2 = folder + "destination1.png"; - string original_path3 = folder + "mask.png"; + string original_path1 = samples::findFile(folder + "source1.png"); + string original_path2 = samples::findFile(folder + "destination1.png"); + string original_path3 = samples::findFile(folder + "mask.png"); Mat source = imread(original_path1, IMREAD_COLOR); Mat destination = imread(original_path2, IMREAD_COLOR); @@ -123,14 +122,14 @@ int main() seamlessClone(source, destination, mask, p, result, 2); imshow("Output",result); - imwrite(folder + "cloned.png", result); + imwrite("cloned.png", result); } else if(num == 3) { string folder = "cloning/Monochrome_Transfer/"; - string original_path1 = folder + "source1.png"; - string original_path2 = folder + "destination1.png"; - string original_path3 = folder + "mask.png"; + string original_path1 = samples::findFile(folder + "source1.png"); + string original_path2 = samples::findFile(folder + "destination1.png"); + string original_path3 = samples::findFile(folder + "mask.png"); Mat source = imread(original_path1, IMREAD_COLOR); Mat destination = imread(original_path2, IMREAD_COLOR); @@ -160,13 +159,13 @@ int main() seamlessClone(source, destination, mask, p, result, 3); imshow("Output",result); - imwrite(folder + "cloned.png", result); + imwrite("cloned.png", result); } else if(num == 4) { - string folder = "cloning/Color_Change/"; - string original_path1 = folder + "source1.png"; - string original_path2 = folder + "mask.png"; + string folder = "cloning/color_change/"; + string original_path1 = samples::findFile(folder + "source1.png"); + string original_path2 = samples::findFile(folder + "mask.png"); Mat source = imread(original_path1, IMREAD_COLOR); Mat mask = imread(original_path2, IMREAD_COLOR); @@ -187,13 +186,13 @@ int main() colorChange(source, mask, result, 1.5, .5, .5); imshow("Output",result); - imwrite(folder + "cloned.png", result); + imwrite("cloned.png", result); } else if(num == 5) { string folder = "cloning/Illumination_Change/"; - string original_path1 = folder + "source1.png"; - string original_path2 = folder + "mask.png"; + string original_path1 = samples::findFile(folder + "source1.png"); + string original_path2 = samples::findFile(folder + "mask.png"); Mat source = imread(original_path1, IMREAD_COLOR); Mat mask = imread(original_path2, IMREAD_COLOR); @@ -214,13 +213,13 @@ int main() illuminationChange(source, mask, result, 0.2f, 0.4f); imshow("Output",result); - imwrite(folder + "cloned.png", result); + imwrite("cloned.png", result); } else if(num == 6) { string folder = "cloning/Texture_Flattening/"; - string original_path1 = folder + "source1.png"; - string original_path2 = folder + "mask.png"; + string original_path1 = samples::findFile(folder + "source1.png"); + string original_path2 = samples::findFile(folder + "mask.png"); Mat source = imread(original_path1, IMREAD_COLOR); Mat mask = imread(original_path2, IMREAD_COLOR); @@ -241,7 +240,12 @@ int main() textureFlattening(source, mask, result, 30, 45, 3); imshow("Output",result); - imwrite(folder + "cloned.png", result); + imwrite("cloned.png", result); + } + else + { + cerr << "Invalid selection: " << num << endl; + exit(1); } waitKey(0); } diff --git a/samples/cpp/cloning_gui.cpp b/samples/cpp/cloning_gui.cpp index 14a5079..c4e4de7 100644 --- a/samples/cpp/cloning_gui.cpp +++ b/samples/cpp/cloning_gui.cpp @@ -30,14 +30,12 @@ * Result: The cloned image will be displayed. */ -#include #include "opencv2/photo.hpp" #include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/highgui.hpp" #include "opencv2/core.hpp" #include -#include // we're NOT "using namespace std;" here, to avoid collisions between the beta variable and std::beta in c++17 using std::cin; @@ -320,9 +318,9 @@ int main() cout << "Enter Destination Image: "; cin >> dest; - img0 = imread(src); + img0 = imread(samples::findFile(src)); - img2 = imread(dest); + img2 = imread(samples::findFile(dest)); if(img0.empty()) { @@ -370,7 +368,7 @@ int main() cout << "Blue: "; cin >> blue; - img0 = imread(src); + img0 = imread(samples::findFile(src)); if(img0.empty()) { @@ -400,7 +398,7 @@ int main() cout << "beta: "; cin >> beta; - img0 = imread(src); + img0 = imread(samples::findFile(src)); if(img0.empty()) { @@ -433,7 +431,7 @@ int main() cout << "kernel_size: "; cin >> kernel_size; - img0 = imread(src); + img0 = imread(samples::findFile(src)); if(img0.empty()) { diff --git a/samples/cpp/connected_components.cpp b/samples/cpp/connected_components.cpp index 711b0a9..74afb29 100644 --- a/samples/cpp/connected_components.cpp +++ b/samples/cpp/connected_components.cpp @@ -35,14 +35,14 @@ static void on_trackbar(int, void*) int main( int argc, const char** argv ) { - CommandLineParser parser(argc, argv, "{@image|../data/stuff.jpg|image for converting to a grayscale}"); + CommandLineParser parser(argc, argv, "{@image|stuff.jpg|image for converting to a grayscale}"); parser.about("\nThis program demonstrates connected components and use of the trackbar\n"); parser.printMessage(); cout << "\nThe image is converted to grayscale and displayed, another image has a trackbar\n" "that controls thresholding and thereby the extracted contours which are drawn in color\n"; String inputImage = parser.get(0); - img = imread(inputImage, IMREAD_GRAYSCALE); + img = imread(samples::findFile(inputImage), IMREAD_GRAYSCALE); if(img.empty()) { diff --git a/samples/cpp/create_mask.cpp b/samples/cpp/create_mask.cpp index b90a7b7..dc54953 100644 --- a/samples/cpp/create_mask.cpp +++ b/samples/cpp/create_mask.cpp @@ -95,7 +95,7 @@ void mouseHandler(int event, int x, int y, int, void*) int main(int argc, char **argv) { - CommandLineParser parser(argc, argv, "{@input | ../data/lena.jpg | input image}"); + CommandLineParser parser(argc, argv, "{@input | lena.jpg | input image}"); parser.about("This program demonstrates using mouse events\n"); parser.printMessage(); cout << "\n\tleft mouse button - set a point to create mask shape\n" @@ -103,13 +103,13 @@ int main(int argc, char **argv) "\tmiddle mouse button - reset\n"; String input_image = parser.get("@input"); - src = imread(input_image); + src = imread(samples::findFile(input_image)); if (src.empty()) - { + { printf("Error opening image: %s\n", input_image.c_str()); return 0; - } + } namedWindow("Source", WINDOW_AUTOSIZE); setMouseCallback("Source", mouseHandler, NULL); diff --git a/samples/cpp/dbt_face_detection.cpp b/samples/cpp/dbt_face_detection.cpp index 8e5112f..d5707d4 100644 --- a/samples/cpp/dbt_face_detection.cpp +++ b/samples/cpp/dbt_face_detection.cpp @@ -49,7 +49,7 @@ int main(int , char** ) return 1; } - std::string cascadeFrontalfilename = "../../data/lbpcascades/lbpcascade_frontalface.xml"; + std::string cascadeFrontalfilename = samples::findFile("data/lbpcascades/lbpcascade_frontalface.xml"); cv::Ptr cascade = makePtr(cascadeFrontalfilename); cv::Ptr MainDetector = makePtr(cascade); if ( cascade->empty() ) diff --git a/samples/cpp/demhist.cpp b/samples/cpp/demhist.cpp index d4a4c92..3e416b3 100644 --- a/samples/cpp/demhist.cpp +++ b/samples/cpp/demhist.cpp @@ -59,12 +59,12 @@ static void updateBrightnessContrast( int /*arg*/, void* ) static void help() { std::cout << "\nThis program demonstrates the use of calcHist() -- histogram creation.\n" - << "Usage: \n" << "demhist [image_name -- Defaults to ../data/baboon.jpg]" << std::endl; + << "Usage: \n" << "demhist [image_name -- Defaults to baboon.jpg]" << std::endl; } const char* keys = { - "{help h||}{@image|../data/baboon.jpg|input image file}" + "{help h||}{@image|baboon.jpg|input image file}" }; int main( int argc, const char** argv ) @@ -78,7 +78,7 @@ int main( int argc, const char** argv ) string inputImage = parser.get(0); // Load the source image. HighGUI use. - image = imread( inputImage, 0 ); + image = imread(samples::findFile(inputImage), IMREAD_GRAYSCALE); if(image.empty()) { std::cerr << "Cannot read image file: " << inputImage << std::endl; diff --git a/samples/cpp/detect_blob.cpp b/samples/cpp/detect_blob.cpp index 25fbe56..04481cc 100644 --- a/samples/cpp/detect_blob.cpp +++ b/samples/cpp/detect_blob.cpp @@ -14,7 +14,7 @@ static void help() { cout << "\n This program demonstrates how to use BLOB to detect and filter region \n" "Usage: \n" - " ./detect_blob \n" + " ./detect_blob \n" "Press a key when image window is active to change descriptor"; } @@ -70,20 +70,19 @@ static String Legende(SimpleBlobDetector::Params &pAct) int main(int argc, char *argv[]) { - vector fileName; - Mat img(600, 800, CV_8UC1); - cv::CommandLineParser parser(argc, argv, "{@input |../data/detect_blob.png| }{h help | | }"); + String fileName; + cv::CommandLineParser parser(argc, argv, "{@input |detect_blob.png| }{h help | | }"); if (parser.has("h")) { help(); return 0; } - fileName.push_back(parser.get("@input")); - img = imread(fileName[0], IMREAD_COLOR); - if (img.rows*img.cols <= 0) + fileName = parser.get("@input"); + Mat img = imread(samples::findFile(fileName), IMREAD_COLOR); + if (img.empty()) { - cout << "Image " << fileName[0] << " is empty or cannot be found\n"; - return(0); + cout << "Image " << fileName << " is empty or cannot be found\n"; + return 1; } SimpleBlobDetector::Params pDefaultBLOB; @@ -116,14 +115,17 @@ int main(int argc, char *argv[]) vector< Vec3b > palette; for (int i = 0; i<65536; i++) { - palette.push_back(Vec3b((uchar)rand(), (uchar)rand(), (uchar)rand())); + uchar c1 = (uchar)rand(); + uchar c2 = (uchar)rand(); + uchar c3 = (uchar)rand(); + palette.push_back(Vec3b(c1, c2, c3)); } help(); // These descriptors are going to be detecting and computing BLOBS with 6 different params // Param for first BLOB detector we want all - typeDesc.push_back("BLOB"); // see http://docs.opencv.org/trunk/d0/d7a/classcv_1_1SimpleBlobDetector.html + typeDesc.push_back("BLOB"); // see http://docs.opencv.org/3.4/d0/d7a/classcv_1_1SimpleBlobDetector.html pBLOB.push_back(pDefaultBLOB); pBLOB.back().filterByArea = true; pBLOB.back().minArea = 1; @@ -150,7 +152,7 @@ int main(int argc, char *argv[]) pBLOB.back().filterByConvexity = true; pBLOB.back().minConvexity = 0.; pBLOB.back().maxConvexity = (float)0.9; - // Param for six BLOB detector we want blob with gravity center color equal to 0 bug #4321 must be fixed + // Param for six BLOB detector we want blob with gravity center color equal to 0 typeDesc.push_back("BLOB"); pBLOB.push_back(pDefaultBLOB); pBLOB.back().filterByColor = true; diff --git a/samples/cpp/detect_mser.cpp b/samples/cpp/detect_mser.cpp index 9006efe..8749789 100644 --- a/samples/cpp/detect_mser.cpp +++ b/samples/cpp/detect_mser.cpp @@ -412,7 +412,7 @@ int main(int argc, char *argv[]) string input = parser.get("@input"); if (!input.empty()) { - imgOrig = imread(input, IMREAD_GRAYSCALE); + imgOrig = imread(samples::findFile(input), IMREAD_GRAYSCALE); blur(imgOrig, img, blurSize); } else diff --git a/samples/cpp/dft.cpp b/samples/cpp/dft.cpp index ddb56ac..652ffb3 100644 --- a/samples/cpp/dft.cpp +++ b/samples/cpp/dft.cpp @@ -14,12 +14,12 @@ static void help() printf("\nThis program demonstrated the use of the discrete Fourier transform (dft)\n" "The dft of an image is taken and it's power spectrum is displayed.\n" "Usage:\n" - "./dft [image_name -- default ../data/lena.jpg]\n"); + "./dft [image_name -- default lena.jpg]\n"); } const char* keys = { - "{help h||}{@image|../data/lena.jpg|input image file}" + "{help h||}{@image|lena.jpg|input image file}" }; int main(int argc, const char ** argv) @@ -32,7 +32,7 @@ int main(int argc, const char ** argv) return 0; } string filename = parser.get(0); - Mat img = imread(filename, IMREAD_GRAYSCALE); + Mat img = imread(samples::findFile(filename), IMREAD_GRAYSCALE); if( img.empty() ) { help(); diff --git a/samples/cpp/distrans.cpp b/samples/cpp/distrans.cpp index 2143264..67547f2 100644 --- a/samples/cpp/distrans.cpp +++ b/samples/cpp/distrans.cpp @@ -91,7 +91,7 @@ static void help() { printf("\nProgram to demonstrate the use of the distance transform function between edge images.\n" "Usage:\n" - "./distrans [image_name -- default image is ../data/stuff.jpg]\n" + "./distrans [image_name -- default image is stuff.jpg]\n" "\nHot keys: \n" "\tESC - quit the program\n" "\tC - use C/Inf metric\n" @@ -107,7 +107,7 @@ static void help() const char* keys = { - "{help h||}{@image |../data/stuff.jpg|input image file}" + "{help h||}{@image |stuff.jpg|input image file}" }; int main( int argc, const char** argv ) @@ -117,7 +117,7 @@ int main( int argc, const char** argv ) if (parser.has("help")) return 0; string filename = parser.get(0); - gray = imread(filename, 0); + gray = imread(samples::findFile(filename), 0); if(gray.empty()) { printf("Cannot read image file: %s\n", filename.c_str()); diff --git a/samples/cpp/edge.cpp b/samples/cpp/edge.cpp index 78bc4b6..ba21cb5 100644 --- a/samples/cpp/edge.cpp +++ b/samples/cpp/edge.cpp @@ -43,12 +43,12 @@ static void help() { printf("\nThis sample demonstrates Canny edge detection\n" "Call:\n" - " /.edge [image_name -- Default is ../data/fruits.jpg]\n\n"); + " /.edge [image_name -- Default is fruits.jpg]\n\n"); } const char* keys = { - "{help h||}{@image |../data/fruits.jpg|input image name}" + "{help h||}{@image |fruits.jpg|input image name}" }; int main( int argc, const char** argv ) @@ -57,7 +57,7 @@ int main( int argc, const char** argv ) CommandLineParser parser(argc, argv, keys); string filename = parser.get(0); - image = imread(filename, IMREAD_COLOR); + image = imread(samples::findFile(filename), IMREAD_COLOR); if(image.empty()) { printf("Cannot read image file: %s\n", filename.c_str()); diff --git a/samples/cpp/facedetect.cpp b/samples/cpp/facedetect.cpp index f6de738..88d632b 100644 --- a/samples/cpp/facedetect.cpp +++ b/samples/cpp/facedetect.cpp @@ -18,7 +18,7 @@ static void help() " [--try-flip]\n" " [filename|camera_index]\n\n" "see facedetect.cmd for one call:\n" - "./facedetect --cascade=\"../../data/haarcascades/haarcascade_frontalface_alt.xml\" --nested-cascade=\"../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml\" --scale=1.3\n\n" + "./facedetect --cascade=\"data/haarcascades/haarcascade_frontalface_alt.xml\" --nested-cascade=\"data/haarcascades/haarcascade_eye_tree_eyeglasses.xml\" --scale=1.3\n\n" "During execution:\n\tHit any key to quit.\n" "\tUsing OpenCV version " << CV_VERSION << "\n" << endl; } @@ -41,8 +41,8 @@ int main( int argc, const char** argv ) cv::CommandLineParser parser(argc, argv, "{help h||}" - "{cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|}" - "{nested-cascade|../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|}" + "{cascade|data/haarcascades/haarcascade_frontalface_alt.xml|}" + "{nested-cascade|data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|}" "{scale|1|}{try-flip||}{@filename||}" ); if (parser.has("help")) @@ -62,9 +62,9 @@ int main( int argc, const char** argv ) parser.printErrors(); return 0; } - if ( !nestedCascade.load( nestedCascadeName ) ) + if (!nestedCascade.load(samples::findFileOrKeep(nestedCascadeName))) cerr << "WARNING: Could not load classifier cascade for nested objects" << endl; - if( !cascade.load( cascadeName ) ) + if (!cascade.load(samples::findFile(cascadeName))) { cerr << "ERROR: Could not load classifier cascade" << endl; help(); @@ -74,21 +74,31 @@ int main( int argc, const char** argv ) { int camera = inputName.empty() ? 0 : inputName[0] - '0'; if(!capture.open(camera)) + { cout << "Capture from camera #" << camera << " didn't work" << endl; + return 1; + } } - else if( inputName.size() ) + else if (!inputName.empty()) { - image = imread( inputName, 1 ); - if( image.empty() ) + image = imread(samples::findFileOrKeep(inputName), IMREAD_COLOR); + if (image.empty()) { - if(!capture.open( inputName )) + if (!capture.open(samples::findFileOrKeep(inputName))) + { cout << "Could not read " << inputName << endl; + return 1; + } } } else { - image = imread( "../data/lena.jpg", 1 ); - if(image.empty()) cout << "Couldn't read ../data/lena.jpg" << endl; + image = imread(samples::findFile("lena.jpg"), IMREAD_COLOR); + if (image.empty()) + { + cout << "Couldn't read lena.jpg" << endl; + return 1; + } } if( capture.isOpened() ) diff --git a/samples/cpp/facial_features.cpp b/samples/cpp/facial_features.cpp index 4fdfcb7..5c2ae25 100644 --- a/samples/cpp/facial_features.cpp +++ b/samples/cpp/facial_features.cpp @@ -32,14 +32,14 @@ string face_cascade_path, eye_cascade_path, nose_cascade_path, mouth_cascade_pat int main(int argc, char** argv) { cv::CommandLineParser parser(argc, argv, - "{eyes||}{nose||}{mouth||}{help h||}"); + "{eyes||}{nose||}{mouth||}{help h||}{@image||}{@facexml||}"); if (parser.has("help")) { help(); return 0; } - input_image_path = parser.get(0); - face_cascade_path = parser.get(1); + input_image_path = parser.get("@image"); + face_cascade_path = parser.get("@facexml"); eye_cascade_path = parser.has("eyes") ? parser.get("eyes") : ""; nose_cascade_path = parser.has("nose") ? parser.get("nose") : ""; mouth_cascade_path = parser.has("mouth") ? parser.get("mouth") : ""; @@ -50,7 +50,7 @@ int main(int argc, char** argv) } // Load image and cascade classifier files Mat image; - image = imread(input_image_path); + image = imread(samples::findFile(input_image_path)); // Detect faces and facial features vector > faces; @@ -92,15 +92,16 @@ static void help() " \nhttps://github.com/opencv/opencv/tree/3.4/data/haarcascades"; cout << "\n\nThe classifiers for nose and mouth can be downloaded from : " - " \nhttps://github.com/opencv/opencv_contrib/tree/master/modules/face/data/cascades\n"; + " \nhttps://github.com/opencv/opencv_contrib/tree/3.4/modules/face/data/cascades\n"; } static void detectFaces(Mat& img, vector >& faces, string cascade_path) { CascadeClassifier face_cascade; - face_cascade.load(cascade_path); + face_cascade.load(samples::findFile(cascade_path)); - face_cascade.detectMultiScale(img, faces, 1.15, 3, 0|CASCADE_SCALE_IMAGE, Size(30, 30)); + if (!face_cascade.empty()) + face_cascade.detectMultiScale(img, faces, 1.15, 3, 0|CASCADE_SCALE_IMAGE, Size(30, 30)); return; } @@ -186,26 +187,29 @@ static void detectFacialFeaures(Mat& img, const vector > faces, strin static void detectEyes(Mat& img, vector >& eyes, string cascade_path) { CascadeClassifier eyes_cascade; - eyes_cascade.load(cascade_path); + eyes_cascade.load(samples::findFile(cascade_path, !cascade_path.empty())); - eyes_cascade.detectMultiScale(img, eyes, 1.20, 5, 0|CASCADE_SCALE_IMAGE, Size(30, 30)); + if (!eyes_cascade.empty()) + eyes_cascade.detectMultiScale(img, eyes, 1.20, 5, 0|CASCADE_SCALE_IMAGE, Size(30, 30)); return; } static void detectNose(Mat& img, vector >& nose, string cascade_path) { CascadeClassifier nose_cascade; - nose_cascade.load(cascade_path); + nose_cascade.load(samples::findFile(cascade_path, !cascade_path.empty())); - nose_cascade.detectMultiScale(img, nose, 1.20, 5, 0|CASCADE_SCALE_IMAGE, Size(30, 30)); + if (!nose_cascade.empty()) + nose_cascade.detectMultiScale(img, nose, 1.20, 5, 0|CASCADE_SCALE_IMAGE, Size(30, 30)); return; } static void detectMouth(Mat& img, vector >& mouth, string cascade_path) { CascadeClassifier mouth_cascade; - mouth_cascade.load(cascade_path); + mouth_cascade.load(samples::findFile(cascade_path, !cascade_path.empty())); - mouth_cascade.detectMultiScale(img, mouth, 1.20, 5, 0|CASCADE_SCALE_IMAGE, Size(30, 30)); + if (!mouth_cascade.empty()) + mouth_cascade.detectMultiScale(img, mouth, 1.20, 5, 0|CASCADE_SCALE_IMAGE, Size(30, 30)); return; } diff --git a/samples/cpp/falsecolor.cpp b/samples/cpp/falsecolor.cpp index 1a2c072..cb074bd 100644 --- a/samples/cpp/falsecolor.cpp +++ b/samples/cpp/falsecolor.cpp @@ -87,7 +87,7 @@ int main(int argc, char** argv) Mat img; if (argc > 1) - img = imread(argv[1], IMREAD_GRAYSCALE); + img = imread(samples::findFile(argv[1]), IMREAD_GRAYSCALE); else img = DrawMyImage(2,256); diff --git a/samples/cpp/ffilldemo.cpp b/samples/cpp/ffilldemo.cpp index 0cf3155..074a9ae 100644 --- a/samples/cpp/ffilldemo.cpp +++ b/samples/cpp/ffilldemo.cpp @@ -12,7 +12,7 @@ static void help() { cout << "\nThis program demonstrated the floodFill() function\n" "Call:\n" - "./ffilldemo [image_name -- Default: ../data/fruits.jpg]\n" << endl; + "./ffilldemo [image_name -- Default: fruits.jpg]\n" << endl; cout << "Hot keys: \n" "\tESC - quit the program\n" @@ -74,7 +74,7 @@ static void onMouse( int event, int x, int y, int, void* ) int main( int argc, char** argv ) { cv::CommandLineParser parser (argc, argv, - "{help h | | show help message}{@image|../data/fruits.jpg| input image}" + "{help h | | show help message}{@image|fruits.jpg| input image}" ); if (parser.has("help")) { @@ -82,7 +82,7 @@ int main( int argc, char** argv ) return 0; } string filename = parser.get("@image"); - image0 = imread(filename, 1); + image0 = imread(samples::findFile(filename), 1); if( image0.empty() ) { diff --git a/samples/cpp/filestorage.cpp b/samples/cpp/filestorage.cpp index 3315455..e0b462b 100644 --- a/samples/cpp/filestorage.cpp +++ b/samples/cpp/filestorage.cpp @@ -92,8 +92,8 @@ int main(int ac, char** av) cout << "writing images\n"; fs << "images" << "["; - fs << "image1.jpg" << "myfi.png" << "../data/baboon.jpg"; - cout << "image1.jpg" << " myfi.png" << " ../data/baboon.jpg" << endl; + fs << "image1.jpg" << "myfi.png" << "baboon.jpg"; + cout << "image1.jpg" << " myfi.png" << " baboon.jpg" << endl; fs << "]"; diff --git a/samples/cpp/fitellipse.cpp b/samples/cpp/fitellipse.cpp index 8aaf0ba..6d3346b 100644 --- a/samples/cpp/fitellipse.cpp +++ b/samples/cpp/fitellipse.cpp @@ -171,7 +171,7 @@ static void help() "contours and approximate it by ellipses. Three methods are used to find the \n" "elliptical fits: fitEllipse, fitEllipseAMS and fitEllipseDirect.\n" "Call:\n" - "./fitellipse [image_name -- Default ../data/stuff.jpg]\n" << endl; + "./fitellipse [image_name -- Default ellipses.jpg]\n" << endl; } int sliderPos = 70; @@ -192,14 +192,14 @@ int main( int argc, char** argv ) fitEllipseAMSQ = true; fitEllipseDirectQ = true; - cv::CommandLineParser parser(argc, argv,"{help h||}{@image|../data/ellipses.jpg|}"); + cv::CommandLineParser parser(argc, argv,"{help h||}{@image|ellipses.jpg|}"); if (parser.has("help")) { help(); return 0; } string filename = parser.get("@image"); - image = imread(filename, 0); + image = imread(samples::findFile(filename), 0); if( image.empty() ) { cout << "Couldn't open image " << filename << "\n"; diff --git a/samples/cpp/grabcut.cpp b/samples/cpp/grabcut.cpp index c5b68fc..03ca7be 100644 --- a/samples/cpp/grabcut.cpp +++ b/samples/cpp/grabcut.cpp @@ -276,7 +276,7 @@ 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, "{@input| ../data/messi5.jpg |}"); + cv::CommandLineParser parser(argc, argv, "{@input| messi5.jpg |}"); help(); string filename = parser.get("@input"); @@ -285,7 +285,7 @@ int main( int argc, char** argv ) cout << "\nDurn, empty filename" << endl; return 1; } - Mat image = imread( filename, 1 ); + Mat image = imread(samples::findFile(filename), IMREAD_COLOR); if( image.empty() ) { cout << "\n Durn, couldn't read image filename " << filename << endl; diff --git a/samples/cpp/gstreamer_pipeline.cpp b/samples/cpp/gstreamer_pipeline.cpp index 4ad1daa..bc6b659 100644 --- a/samples/cpp/gstreamer_pipeline.cpp +++ b/samples/cpp/gstreamer_pipeline.cpp @@ -266,6 +266,7 @@ int main(int argc, char *argv[]) cout << "Unsupported mode: " << mode << endl; return -1; } + file_name = samples::findFile(file_name); cout << "Mode: " << mode << ", Backend: " << backend << ", File: " << file_name << ", Codec: " << codec << endl; TickMeter total; diff --git a/samples/cpp/image.cpp b/samples/cpp/image.cpp index fc57738..794d439 100644 --- a/samples/cpp/image.cpp +++ b/samples/cpp/image.cpp @@ -14,7 +14,7 @@ static void help() "It shows reading of images, converting to planes and merging back, color conversion\n" "and also iterating through pixels.\n" "Call:\n" - "./image [image-name Default: ../data/lena.jpg]\n" << endl; + "./image [image-name Default: lena.jpg]\n" << endl; } // enable/disable use of mixed API in the code below. @@ -27,7 +27,7 @@ static void help() int main( int argc, char** argv ) { - cv::CommandLineParser parser(argc, argv, "{help h | |}{@image|../data/lena.jpg|}"); + cv::CommandLineParser parser(argc, argv, "{help h | |}{@image|lena.jpg|}"); if (parser.has("help")) { help(); @@ -47,7 +47,7 @@ int main( int argc, char** argv ) // is converted, while the data is shared) //! [iplimage] #else - Mat img = imread(imagename); // the newer cvLoadImage alternative, MATLAB-style function + Mat img = imread(samples::findFile(imagename)); // the newer cvLoadImage alternative, MATLAB-style function if(img.empty()) { fprintf(stderr, "Can not load image %s\n", imagename.c_str()); diff --git a/samples/cpp/image_alignment.cpp b/samples/cpp/image_alignment.cpp index c55d1d6..ab0c129 100644 --- a/samples/cpp/image_alignment.cpp +++ b/samples/cpp/image_alignment.cpp @@ -3,7 +3,7 @@ * findTransformECC that implements the image alignment ECC algorithm * * -* The demo loads an image (defaults to ../data/fruits.jpg) and it artificially creates +* The demo loads an image (defaults to fruits.jpg) and it artificially creates * a template image based on the given motion type. When two images are given, * the first image is the input image and the second one defines the template image. * In the latter case, you can also parse the warp's initialization. @@ -44,7 +44,7 @@ static void draw_warped_roi(Mat& image, const int width, const int height, Mat& const std::string keys = - "{@inputImage | ../data/fruits.jpg | input image filename }" + "{@inputImage | fruits.jpg | input image filename }" "{@templateImage | | template image filename (optional)}" "{@inputWarp | | input warp (matrix) filename (optional)}" "{n numOfIter | 50 | ECC's iterations }" @@ -65,10 +65,10 @@ static void help(void) " are given, the initialization of the warp by command line parsing is possible. " "If inputWarp is missing, the identity transformation initializes the algorithm. \n" << endl; - cout << "\nUsage example (one image): \n./ecc ../data/fruits.jpg -o=outWarp.ecc " + cout << "\nUsage example (one image): \n./image_alignment fruits.jpg -o=outWarp.ecc " "-m=euclidean -e=1e-6 -N=70 -v=1 \n" << endl; - cout << "\nUsage example (two images with initialization): \n./ecc yourInput.png yourTemplate.png " + cout << "\nUsage example (two images with initialization): \n./image_alignment yourInput.png yourTemplate.png " "yourInitialWarp.ecc -o=outWarp.ecc -m=homography -e=1e-6 -N=70 -v=1 -w=yourFinalImage.png \n" << endl; } @@ -212,7 +212,7 @@ int main (const int argc, const char * argv[]) else mode_temp = MOTION_HOMOGRAPHY; - Mat inputImage = imread(imgFile,0); + Mat inputImage = imread(samples::findFile(imgFile), IMREAD_GRAYSCALE); if (inputImage.empty()) { cerr << "Unable to load the inputImage" << endl; @@ -224,7 +224,7 @@ int main (const int argc, const char * argv[]) if (tempImgFile!="") { inputImage.copyTo(target_image); - template_image = imread(tempImgFile,0); + template_image = imread(samples::findFile(tempImgFile), IMREAD_GRAYSCALE); if (template_image.empty()){ cerr << "Unable to load the template image" << endl; return -1; diff --git a/samples/cpp/inpaint.cpp b/samples/cpp/inpaint.cpp index 61c4c45..175bff8 100644 --- a/samples/cpp/inpaint.cpp +++ b/samples/cpp/inpaint.cpp @@ -14,7 +14,7 @@ static void help() << "with surrounding image areas.\n" "Using OpenCV version %s\n" << CV_VERSION << "\n" "Usage:\n" - "./inpaint [image_name -- Default ../data/fruits.jpg]\n" << endl; + "./inpaint [image_name -- Default fruits.jpg]\n" << endl; cout << "Hot keys: \n" "\tESC - quit the program\n" @@ -47,24 +47,24 @@ static void onMouse( int event, int x, int y, int flags, void* ) int main( int argc, char** argv ) { - cv::CommandLineParser parser(argc, argv, "{@image|../data/fruits.jpg|}"); + cv::CommandLineParser parser(argc, argv, "{@image|fruits.jpg|}"); help(); - string filename = parser.get("@image"); - Mat img0 = imread(filename, -1); + string filename = samples::findFile(parser.get("@image")); + Mat img0 = imread(filename, IMREAD_COLOR); if(img0.empty()) { cout << "Couldn't open the image " << filename << ". Usage: inpaint \n" << endl; return 0; } - namedWindow( "image", 1 ); + namedWindow("image", WINDOW_AUTOSIZE); img = img0.clone(); inpaintMask = Mat::zeros(img.size(), CV_8U); imshow("image", img); - setMouseCallback( "image", onMouse, 0 ); + setMouseCallback( "image", onMouse, NULL); for(;;) { diff --git a/samples/cpp/laplace.cpp b/samples/cpp/laplace.cpp index d50029c..1bf3e51 100644 --- a/samples/cpp/laplace.cpp +++ b/samples/cpp/laplace.cpp @@ -25,39 +25,46 @@ int smoothType = GAUSSIAN; int main( int argc, char** argv ) { - VideoCapture cap; cv::CommandLineParser parser(argc, argv, "{ c | 0 | }{ p | | }"); help(); - if( parser.get("c").size() == 1 && isdigit(parser.get("c")[0]) ) + VideoCapture cap; + string camera = parser.get("c"); + if (camera.size() == 1 && isdigit(camera[0])) cap.open(parser.get("c")); else - cap.open(parser.get("c")); - if( cap.isOpened() ) - cout << "Video " << parser.get("c") << - ": width=" << cap.get(CAP_PROP_FRAME_WIDTH) << - ", height=" << cap.get(CAP_PROP_FRAME_HEIGHT) << - ", nframes=" << cap.get(CAP_PROP_FRAME_COUNT) << endl; - if( parser.has("p") ) + cap.open(samples::findFileOrKeep(camera)); + if (!cap.isOpened()) { - int pos = parser.get("p"); - if (!parser.check()) - { - parser.printErrors(); - return -1; - } - cout << "seeking to frame #" << pos << endl; - cap.set(CAP_PROP_POS_FRAMES, pos); + cerr << "Can't open camera/video stream: " << camera << endl; + return 1; } - - if( !cap.isOpened() ) + cout << "Video " << parser.get("c") << + ": width=" << cap.get(CAP_PROP_FRAME_WIDTH) << + ", height=" << cap.get(CAP_PROP_FRAME_HEIGHT) << + ", nframes=" << cap.get(CAP_PROP_FRAME_COUNT) << endl; + int pos = 0; + if (parser.has("p")) + { + pos = parser.get("p"); + } + if (!parser.check()) { - cout << "Could not initialize capturing...\n"; + parser.printErrors(); return -1; } - namedWindow( "Laplacian", 0 ); - createTrackbar( "Sigma", "Laplacian", &sigma, 15, 0 ); + if (pos != 0) + { + cout << "seeking to frame #" << pos << endl; + if (!cap.set(CAP_PROP_POS_FRAMES, pos)) + { + cerr << "ERROR: seekeing is not supported" << endl; + } + } + + namedWindow("Laplacian", WINDOW_AUTOSIZE); + createTrackbar("Sigma", "Laplacian", &sigma, 15, 0); Mat smoothed, laplace, result; diff --git a/samples/cpp/letter_recog.cpp b/samples/cpp/letter_recog.cpp index 32ccf6b..66756b6 100644 --- a/samples/cpp/letter_recog.cpp +++ b/samples/cpp/letter_recog.cpp @@ -520,13 +520,13 @@ int main( int argc, char *argv[] ) string data_filename; int method = 0; - cv::CommandLineParser parser(argc, argv, "{data|../data/letter-recognition.data|}{save||}{load||}{boost||}" + cv::CommandLineParser parser(argc, argv, "{data|letter-recognition.data|}{save||}{load||}{boost||}" "{mlp||}{knn knearest||}{nbayes||}{svm||}"); - data_filename = parser.get("data"); + data_filename = samples::findFile(parser.get("data")); if (parser.has("save")) filename_to_save = parser.get("save"); if (parser.has("load")) - filename_to_load = parser.get("load"); + filename_to_load = samples::findFile(parser.get("load")); if (parser.has("boost")) method = 1; else if (parser.has("mlp")) diff --git a/samples/cpp/live_detect_qrcode.cpp b/samples/cpp/live_detect_qrcode.cpp index 07101da..41c19f1 100644 --- a/samples/cpp/live_detect_qrcode.cpp +++ b/samples/cpp/live_detect_qrcode.cpp @@ -7,10 +7,10 @@ using namespace std; using namespace cv; -void getMatWithQRCodeContour(Mat &color_image, vector transform); -void getMatWithFPS(Mat &color_image, double fps); -int liveQRCodeDetect(); -int showImageQRCodeDetect(string in, string out); +static void drawQRCodeContour(Mat &color_image, vector transform); +static void drawFPS(Mat &color_image, double fps); +static int liveQRCodeDetect(const string& out_file); +static int imageQRCodeDetect(const string& in_file, const string& out_file); int main(int argc, char *argv[]) { @@ -28,7 +28,9 @@ int main(int argc, char *argv[]) } string in_file_name = cmd_parser.get("in"); // input path to image - string out_file_name = cmd_parser.get("out"); // output path to image + string out_file_name; + if (cmd_parser.has("out")) + out_file_name = cmd_parser.get("out"); // output path to image if (!cmd_parser.check()) { @@ -39,16 +41,16 @@ int main(int argc, char *argv[]) int return_code = 0; if (in_file_name.empty()) { - return_code = liveQRCodeDetect(); + return_code = liveQRCodeDetect(out_file_name); } else { - return_code = showImageQRCodeDetect(in_file_name, out_file_name); + return_code = imageQRCodeDetect(samples::findFile(in_file_name), out_file_name); } return return_code; } -void getMatWithQRCodeContour(Mat &color_image, vector transform) +void drawQRCodeContour(Mat &color_image, vector transform) { if (!transform.empty()) { @@ -70,19 +72,19 @@ void getMatWithQRCodeContour(Mat &color_image, vector transform) } } -void getMatWithFPS(Mat &color_image, double fps) +void drawFPS(Mat &color_image, double fps) { ostringstream convert; - convert << cvRound(fps) << " FPS."; + convert << cvRound(fps) << " FPS (QR detection)"; putText(color_image, convert.str(), Point(25, 25), FONT_HERSHEY_DUPLEX, 1, Scalar(0, 0, 255), 2); } -int liveQRCodeDetect() +int liveQRCodeDetect(const string& out_file) { VideoCapture cap(0); if(!cap.isOpened()) { - cout << "Cannot open a camera" << '\n'; + cout << "Cannot open a camera" << endl; return -4; } @@ -94,7 +96,11 @@ int liveQRCodeDetect() string decode_info; vector transform; cap >> frame; - if(frame.empty()) { break; } + if (frame.empty()) + { + cout << "End of video stream" << endl; + break; + } cvtColor(frame, src, COLOR_BGR2GRAY); total.start(); @@ -102,24 +108,30 @@ int liveQRCodeDetect() if (result_detection) { decode_info = qrcode.decode(src, transform, straight_barcode); - if (!decode_info.empty()) { cout << decode_info << '\n'; } + if (!decode_info.empty()) { cout << decode_info << endl; } } total.stop(); double fps = 1 / total.getTimeSec(); total.reset(); - if (result_detection) { getMatWithQRCodeContour(frame, transform); } - getMatWithFPS(frame, fps); + if (result_detection) { drawQRCodeContour(frame, transform); } + drawFPS(frame, fps); imshow("Live QR code detector", frame); - if( waitKey(30) > 0 ) { break; } + char c = (char)waitKey(30); + if (c == 27) + break; + if (c == ' ' && !out_file.empty()) + imwrite(out_file, frame); // TODO write original frame too } return 0; } -int showImageQRCodeDetect(string in, string out) +int imageQRCodeDetect(const string& in_file, const string& out_file) { - Mat src = imread(in, IMREAD_GRAYSCALE), straight_barcode; + Mat color_src = imread(in_file, IMREAD_COLOR), src; + cvtColor(color_src, src, COLOR_BGR2GRAY); + Mat straight_barcode; string decoded_info; vector transform; const int count_experiments = 10; @@ -135,54 +147,40 @@ int showImageQRCodeDetect(string in, string out) total.stop(); transform_time += total.getTimeSec(); total.reset(); - if (!result_detection) { break; } + if (!result_detection) + continue; total.start(); decoded_info = qrcode.decode(src, transform, straight_barcode); total.stop(); transform_time += total.getTimeSec(); total.reset(); - if (decoded_info.empty()) { break; } - } double fps = count_experiments / transform_time; - if (!result_detection) { cout << "QR code not found\n"; return -2; } - if (decoded_info.empty()) { cout << "QR code cannot be decoded\n"; return -3; } + if (!result_detection) + cout << "QR code not found" << endl; + if (decoded_info.empty()) + cout << "QR code cannot be decoded" << endl; - Mat color_src = imread(in); - getMatWithQRCodeContour(color_src, transform); - getMatWithFPS(color_src, fps); + drawQRCodeContour(color_src, transform); + drawFPS(color_src, fps); - for(;;) + cout << "Input image file path: " << in_file << endl; + cout << "Output image file path: " << out_file << endl; + cout << "Size: " << color_src.size() << endl; + cout << "FPS: " << fps << endl; + cout << "Decoded info: " << decoded_info << endl; + + if (!out_file.empty()) { - imshow("Detect QR code on image", color_src); - if( waitKey(30) > 0 ) { break; } + imwrite(out_file, color_src); } - if (!out.empty()) + for(;;) { - getMatWithQRCodeContour(color_src, transform); - getMatWithFPS(color_src, fps); - - cout << "Input image file path: " << in << '\n'; - cout << "Output image file path: " << out << '\n'; - cout << "Size: " << color_src.size() << '\n'; - cout << "FPS: " << fps << '\n'; - cout << "Decoded info: " << decoded_info << '\n'; - - vector compression_params; - compression_params.push_back(IMWRITE_PNG_COMPRESSION); - compression_params.push_back(9); - try - { - imwrite(out, color_src, compression_params); - } - catch (const cv::Exception& ex) - { - cout << "Exception converting image to PNG format: "; - cout << ex.what() << '\n'; - return -3; - } + imshow("Detect QR code on image", color_src); + if (waitKey(0) == 27) + break; } return 0; } diff --git a/samples/cpp/logistic_regression.cpp b/samples/cpp/logistic_regression.cpp index b567dd2..365b32e 100644 --- a/samples/cpp/logistic_regression.cpp +++ b/samples/cpp/logistic_regression.cpp @@ -83,7 +83,7 @@ static float calculateAccuracyPercent(const Mat &original, const Mat &predicted) int main() { - const String filename = "../data/data01.xml"; + const String filename = samples::findFile("data01.xml"); cout << "**********************************************************************" << endl; cout << filename << " contains digits 0 and 1 of 20 samples each, collected on an Android device" << endl; diff --git a/samples/cpp/lsd_lines.cpp b/samples/cpp/lsd_lines.cpp index a5c7326..3feed9c 100644 --- a/samples/cpp/lsd_lines.cpp +++ b/samples/cpp/lsd_lines.cpp @@ -9,7 +9,7 @@ using namespace cv; int main(int argc, char** argv) { cv::CommandLineParser parser(argc, argv, - "{input i|../data/building.jpg|input image}" + "{input i|building.jpg|input image}" "{refine r|false|if true use LSD_REFINE_STD method, if false use LSD_REFINE_NONE method}" "{canny c|false|use Canny edge detector}" "{overlay o|false|show result on input image}" @@ -23,7 +23,7 @@ int main(int argc, char** argv) parser.printMessage(); - String filename = parser.get("input"); + String filename = samples::findFile(parser.get("input")); bool useRefine = parser.get("refine"); bool useCanny = parser.get("canny"); bool overlay = parser.get("overlay"); diff --git a/samples/cpp/mask_tmpl.cpp b/samples/cpp/mask_tmpl.cpp index 7216cbd..a953ac2 100644 --- a/samples/cpp/mask_tmpl.cpp +++ b/samples/cpp/mask_tmpl.cpp @@ -8,17 +8,27 @@ using namespace cv; int main( int argc, const char** argv ) { CommandLineParser parser(argc, argv, - "{ i | ../data/lena_tmpl.jpg |image name }" - "{ t | ../data/tmpl.png |template name }" - "{ m | ../data/mask.png |mask name }" + "{ i | lena_tmpl.jpg |image name }" + "{ t | tmpl.png |template name }" + "{ m | mask.png |mask name }" "{ cm| 3 |comparison method }"); - cout << "This program demonstrates the use of template matching with mask.\n\n"; + cout << "This program demonstrates the use of template matching with mask." << endl + << endl + << "Available methods: https://docs.opencv.org/3.4/df/dfb/group__imgproc__object.html#ga3a7850640f1fe1f58fe91a2d7583695d" << endl + << " TM_SQDIFF = " << (int)TM_SQDIFF << endl + << " TM_SQDIFF_NORMED = " << (int)TM_SQDIFF_NORMED << endl + << " TM_CCORR = " << (int)TM_CCORR << endl + << " TM_CCORR_NORMED = " << (int)TM_CCORR_NORMED << endl + << " TM_CCOEFF = " << (int)TM_CCOEFF << endl + << " TM_CCOEFF_NORMED = " << (int)TM_CCOEFF_NORMED << endl + << endl; + parser.printMessage(); - string filename = parser.get("i"); - string tmplname = parser.get("t"); - string maskname = parser.get("m"); + string filename = samples::findFile(parser.get("i")); + string tmplname = samples::findFile(parser.get("t")); + string maskname = samples::findFile(parser.get("m")); Mat img = imread(filename); Mat tmpl = imread(tmplname); Mat mask = imread(maskname); diff --git a/samples/cpp/matchmethod_orb_akaze_brisk.cpp b/samples/cpp/matchmethod_orb_akaze_brisk.cpp index 1eb0ded..890d673 100644 --- a/samples/cpp/matchmethod_orb_akaze_brisk.cpp +++ b/samples/cpp/matchmethod_orb_akaze_brisk.cpp @@ -12,7 +12,7 @@ static void help() { cout << "\n This program demonstrates how to detect compute and match ORB BRISK and AKAZE descriptors \n" "Usage: \n" - " ./matchmethod_orb_akaze_brisk --image1= --image2=\n" + " ./matchmethod_orb_akaze_brisk --image1= --image2=\n" "Press a key when image window is active to change algorithm or descriptor"; } @@ -28,34 +28,34 @@ int main(int argc, char *argv[]) typeDesc.push_back("AKAZE"); // see http://docs.opencv.org/trunk/d8/d30/classcv_1_1AKAZE.html typeDesc.push_back("ORB"); // see http://docs.opencv.org/trunk/de/dbf/classcv_1_1BRISK.html typeDesc.push_back("BRISK"); // see http://docs.opencv.org/trunk/db/d95/classcv_1_1ORB.html - // This algorithm would be used to match descriptors see http://docs.opencv.org/trunk/db/d39/classcv_1_1DescriptorMatcher.html#ab5dc5036569ecc8d47565007fa518257 + // This algorithm would be used to match descriptors see http://docs.opencv.org/trunk/db/d39/classcv_1_1DescriptorMatcher.html#ab5dc5036569ecc8d47565007fa518257 typeAlgoMatch.push_back("BruteForce"); typeAlgoMatch.push_back("BruteForce-L1"); typeAlgoMatch.push_back("BruteForce-Hamming"); typeAlgoMatch.push_back("BruteForce-Hamming(2)"); cv::CommandLineParser parser(argc, argv, - "{ @image1 | ../data/basketball1.png | }" - "{ @image2 | ../data/basketball2.png | }" + "{ @image1 | basketball1.png | }" + "{ @image2 | basketball2.png | }" "{help h ||}"); if (parser.has("help")) { help(); return 0; } - fileName.push_back(parser.get(0)); - fileName.push_back(parser.get(1)); + fileName.push_back(samples::findFile(parser.get(0))); + fileName.push_back(samples::findFile(parser.get(1))); Mat img1 = imread(fileName[0], IMREAD_GRAYSCALE); Mat img2 = imread(fileName[1], IMREAD_GRAYSCALE); - if (img1.rows*img1.cols <= 0) - { - cout << "Image " << fileName[0] << " is empty or cannot be found\n"; - return(0); - } - if (img2.rows*img2.cols <= 0) - { - cout << "Image " << fileName[1] << " is empty or cannot be found\n"; - return(0); - } + if (img1.empty()) + { + cerr << "Image " << fileName[0] << " is empty or cannot be found" << endl; + return 1; + } + if (img2.empty()) + { + cerr << "Image " << fileName[1] << " is empty or cannot be found" << endl; + return 1; + } vector desMethCmp; Ptr b; @@ -74,10 +74,10 @@ int main(int argc, char *argv[]) vector::iterator itMatcher = typeAlgoMatch.end(); if (*itDesc == "AKAZE-DESCRIPTOR_KAZE_UPRIGHT"){ b = AKAZE::create(AKAZE::DESCRIPTOR_KAZE_UPRIGHT); - } + } if (*itDesc == "AKAZE"){ b = AKAZE::create(); - } + } if (*itDesc == "ORB"){ b = ORB::create(); } @@ -157,12 +157,12 @@ int main(int argc, char *argv[]) } catch (const Exception& e) { + cerr << "Exception: " << e.what() << endl; cout << "Feature : " << *itDesc << "\n"; if (itMatcher != typeAlgoMatch.end()) { cout << "Matcher : " << *itMatcher << "\n"; } - cout << e.msg << endl; } } int i=0; diff --git a/samples/cpp/minarea.cpp b/samples/cpp/minarea.cpp index 133b684..9726472 100644 --- a/samples/cpp/minarea.cpp +++ b/samples/cpp/minarea.cpp @@ -18,7 +18,7 @@ int main( int /*argc*/, char** /*argv*/ ) { help(); - Mat img(500, 500, CV_8UC3); + Mat img(500, 500, CV_8UC3, Scalar::all(0)); RNG& rng = theRNG(); for(;;) diff --git a/samples/cpp/morphology2.cpp b/samples/cpp/morphology2.cpp index b7dc68f..2464e30 100644 --- a/samples/cpp/morphology2.cpp +++ b/samples/cpp/morphology2.cpp @@ -33,8 +33,8 @@ int erode_dilate_pos = 0; // callback function for open/close trackbar static void OpenClose(int, void*) { - int n = open_close_pos - max_iters; - int an = n > 0 ? n : -n; + int n = open_close_pos; + int an = abs(n); Mat element = getStructuringElement(element_shape, Size(an*2+1, an*2+1), Point(an, an) ); if( n < 0 ) morphologyEx(src, dst, MORPH_OPEN, element); @@ -46,8 +46,8 @@ static void OpenClose(int, void*) // callback function for erode/dilate trackbar static void ErodeDilate(int, void*) { - int n = erode_dilate_pos - max_iters; - int an = n > 0 ? n : -n; + int n = erode_dilate_pos; + int an = abs(n); Mat element = getStructuringElement(element_shape, Size(an*2+1, an*2+1), Point(an, an) ); if( n < 0 ) erode(src, dst, element); @@ -59,13 +59,13 @@ static void ErodeDilate(int, void*) int main( int argc, char** argv ) { - cv::CommandLineParser parser(argc, argv, "{help h||}{ @image | ../data/baboon.jpg | }"); + cv::CommandLineParser parser(argc, argv, "{help h||}{ @image | baboon.jpg | }"); if (parser.has("help")) { help(); return 0; } - std::string filename = parser.get("@image"); + std::string filename = samples::findFile(parser.get("@image")); if( (src = imread(filename,IMREAD_COLOR)).empty() ) { help(); @@ -78,7 +78,14 @@ int main( int argc, char** argv ) open_close_pos = erode_dilate_pos = max_iters; createTrackbar("iterations", "Open/Close",&open_close_pos,max_iters*2+1,OpenClose); + setTrackbarMin("iterations", "Open/Close", -max_iters); + setTrackbarMax("iterations", "Open/Close", max_iters); + setTrackbarPos("iterations", "Open/Close", 0); + createTrackbar("iterations", "Erode/Dilate",&erode_dilate_pos,max_iters*2+1,ErodeDilate); + setTrackbarMin("iterations", "Erode/Dilate", -max_iters); + setTrackbarMax("iterations", "Erode/Dilate", max_iters); + setTrackbarPos("iterations", "Erode/Dilate", 0); for(;;) { diff --git a/samples/cpp/npr_demo.cpp b/samples/cpp/npr_demo.cpp index c343969..4d8d787 100644 --- a/samples/cpp/npr_demo.cpp +++ b/samples/cpp/npr_demo.cpp @@ -28,26 +28,22 @@ using namespace cv; int main(int argc, char* argv[]) { - cv::CommandLineParser parser(argc, argv, "{help h||show help message}{@image|../data/lena.jpg|input image}"); + cv::CommandLineParser parser(argc, argv, "{help h||show help message}{@image|lena.jpg|input image}"); if (parser.has("help")) { parser.printMessage(); - exit(0); - } - if (parser.get("@image").empty()) - { - parser.printMessage(); - exit(0); + return 0; } + string filename = samples::findFile(parser.get("@image")); - Mat I = imread(parser.get("@image")); + Mat I = imread(filename); int num,type; if(I.empty()) { cout << "Image not found" << endl; - exit(0); + return 1; } cout << endl; diff --git a/samples/cpp/peopledetect.cpp b/samples/cpp/peopledetect.cpp index ea45ae9..c7640db 100644 --- a/samples/cpp/peopledetect.cpp +++ b/samples/cpp/peopledetect.cpp @@ -72,7 +72,10 @@ int main(int argc, char** argv) if (file.empty()) cap.open(camera); else - cap.open(file.c_str()); + { + file = samples::findFileOrKeep(file); + cap.open(file); + } if (!cap.isOpened()) { cout << "Can not open video stream: '" << (file.empty() ? "" : file) << "'" << endl; diff --git a/samples/cpp/points_classifier.cpp b/samples/cpp/points_classifier.cpp index 9945ba2..02e3934 100644 --- a/samples/cpp/points_classifier.cpp +++ b/samples/cpp/points_classifier.cpp @@ -2,11 +2,6 @@ #include "opencv2/imgproc.hpp" #include "opencv2/ml.hpp" #include "opencv2/highgui.hpp" -#ifdef HAVE_OPENCV_OCL -#define _OCL_KNN_ 1 // select whether using ocl::KNN method or not, default is using -#define _OCL_SVM_ 1 // select whether using ocl::svm method or not, default is using -#include "opencv2/ocl/ocl.hpp" -#endif #include diff --git a/samples/cpp/polar_transforms.cpp b/samples/cpp/polar_transforms.cpp index 4a6014f..b9b73c6 100644 --- a/samples/cpp/polar_transforms.cpp +++ b/samples/cpp/polar_transforms.cpp @@ -24,7 +24,7 @@ int main( int argc, char** argv ) if( arg.size() == 1 && isdigit(arg[0]) ) capture.open( arg[0] - '0' ); else - capture.open( arg.c_str() ); + capture.open(samples::findFileOrKeep(arg)); if( !capture.isOpened() ) { diff --git a/samples/cpp/segment_objects.cpp b/samples/cpp/segment_objects.cpp index 32b2598..3053bb8 100644 --- a/samples/cpp/segment_objects.cpp +++ b/samples/cpp/segment_objects.cpp @@ -73,7 +73,7 @@ int main(int argc, char** argv) if (input.empty()) cap.open(0); else - cap.open(input); + cap.open(samples::findFileOrKeep(input)); if( !cap.isOpened() ) { diff --git a/samples/cpp/select3dobj.cpp b/samples/cpp/select3dobj.cpp index 2953c1b..4f32f19 100644 --- a/samples/cpp/select3dobj.cpp +++ b/samples/cpp/select3dobj.cpp @@ -416,7 +416,7 @@ int main(int argc, char** argv) if ( parser.get("@input").size() == 1 && isdigit(parser.get("@input")[0]) ) cameraId = parser.get("@input"); else - inputName = parser.get("@input"); + inputName = samples::findFileOrKeep(parser.get("@input")); if (!parser.check()) { puts(help); diff --git a/samples/cpp/smiledetect.cpp b/samples/cpp/smiledetect.cpp index a60d642..ceac5e9 100644 --- a/samples/cpp/smiledetect.cpp +++ b/samples/cpp/smiledetect.cpp @@ -16,7 +16,7 @@ static void help() " [--try-flip]\n" " [video_filename|camera_index]\n\n" "Example:\n" - "./smiledetect --cascade=\"../../data/haarcascades/haarcascade_frontalface_alt.xml\" --smile-cascade=\"../../data/haarcascades/haarcascade_smile.xml\" --scale=2.0\n\n" + "./smiledetect --cascade=\"data/haarcascades/haarcascade_frontalface_alt.xml\" --smile-cascade=\"data/haarcascades/haarcascade_smile.xml\" --scale=2.0\n\n" "During execution:\n\tHit any key to quit.\n" "\tUsing OpenCV version " << CV_VERSION << "\n" << endl; } @@ -41,16 +41,16 @@ int main( int argc, const char** argv ) double scale; cv::CommandLineParser parser(argc, argv, "{help h||}{scale|1|}" - "{cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|}" - "{smile-cascade|../../data/haarcascades/haarcascade_smile.xml|}" + "{cascade|data/haarcascades/haarcascade_frontalface_alt.xml|}" + "{smile-cascade|data/haarcascades/haarcascade_smile.xml|}" "{try-flip||}{@input||}"); if (parser.has("help")) { help(); return 0; } - cascadeName = parser.get("cascade"); - nestedCascadeName = parser.get("smile-cascade"); + cascadeName = samples::findFile(parser.get("cascade")); + nestedCascadeName = samples::findFile(parser.get("smile-cascade")); tryflip = parser.has("try-flip"); inputName = parser.get("@input"); scale = parser.get("scale"); @@ -81,6 +81,7 @@ int main( int argc, const char** argv ) } else if( inputName.size() ) { + inputName = samples::findFileOrKeep(inputName); if(!capture.open( inputName )) cout << "Could not read " << inputName << endl; } diff --git a/samples/cpp/squares.cpp b/samples/cpp/squares.cpp index 480fe0a..b466e32 100644 --- a/samples/cpp/squares.cpp +++ b/samples/cpp/squares.cpp @@ -138,8 +138,8 @@ static void drawSquares( Mat& image, const vector >& squares ) int main(int argc, char** argv) { - static const char* names[] = { "../data/pic1.png", "../data/pic2.png", "../data/pic3.png", - "../data/pic4.png", "../data/pic5.png", "../data/pic6.png", 0 }; + static const char* names[] = { "data/pic1.png", "data/pic2.png", "data/pic3.png", + "data/pic4.png", "data/pic5.png", "data/pic6.png", 0 }; help(argv[0]); if( argc > 1) @@ -152,10 +152,11 @@ int main(int argc, char** argv) for( int i = 0; names[i] != 0; i++ ) { - Mat image = imread(names[i], IMREAD_COLOR); + string filename = samples::findFile(names[i]); + Mat image = imread(filename, IMREAD_COLOR); if( image.empty() ) { - cout << "Couldn't load " << names[i] << endl; + cout << "Couldn't load " << filename << endl; continue; } diff --git a/samples/cpp/stereo_calib.cpp b/samples/cpp/stereo_calib.cpp index ddc3a79..894261d 100644 --- a/samples/cpp/stereo_calib.cpp +++ b/samples/cpp/stereo_calib.cpp @@ -18,7 +18,6 @@ Homepage: http://opencv.org Online docs: http://docs.opencv.org Q&A forum: http://answers.opencv.org - Issue tracker: http://code.opencv.org GitHub: https://github.com/opencv/opencv/ ************************************************** */ @@ -46,11 +45,11 @@ static int print_help() " on the chessboards, and a flag: useCalibrated for \n" " calibrated (0) or\n" " uncalibrated \n" - " (1: use cvStereoCalibrate(), 2: compute fundamental\n" + " (1: use stereoCalibrate(), 2: compute fundamental\n" " matrix separately) stereo. \n" " Calibrate the cameras and display the\n" " rectified results along with the computed disparity images. \n" << endl; - cout << "Usage:\n ./stereo_calib -w= -h= -s= \n" << endl; + cout << "Usage:\n ./stereo_calib -w= -h= -s= \n" << endl; return 0; } @@ -347,11 +346,11 @@ int main(int argc, char** argv) Size boardSize; string imagelistfn; bool showRectified; - cv::CommandLineParser parser(argc, argv, "{w|9|}{h|6|}{s|1.0|}{nr||}{help||}{@input|../data/stereo_calib.xml|}"); + cv::CommandLineParser parser(argc, argv, "{w|9|}{h|6|}{s|1.0|}{nr||}{help||}{@input|stereo_calib.xml|}"); if (parser.has("help")) return print_help(); showRectified = !parser.has("nr"); - imagelistfn = parser.get("@input"); + imagelistfn = samples::findFile(parser.get("@input")); boardSize.width = parser.get("w"); boardSize.height = parser.get("h"); float squareSize = parser.get("s"); diff --git a/samples/cpp/stereo_match.cpp b/samples/cpp/stereo_match.cpp index 4868a63..166a450 100644 --- a/samples/cpp/stereo_match.cpp +++ b/samples/cpp/stereo_match.cpp @@ -65,8 +65,8 @@ int main(int argc, char** argv) print_help(); return 0; } - img1_filename = parser.get(0); - img2_filename = parser.get(1); + img1_filename = samples::findFile(parser.get(0)); + img2_filename = samples::findFile(parser.get(1)); if (parser.has("algorithm")) { std::string _alg = parser.get("algorithm"); diff --git a/samples/cpp/stitching.cpp b/samples/cpp/stitching.cpp index dd8c151..689c75e 100644 --- a/samples/cpp/stitching.cpp +++ b/samples/cpp/stitching.cpp @@ -112,7 +112,7 @@ int parseCmdArgs(int argc, char** argv) } else { - Mat img = imread(argv[i]); + Mat img = imread(samples::findFile(argv[i])); if (img.empty()) { cout << "Can't read image '" << argv[i] << "'\n"; diff --git a/samples/cpp/stitching_detailed.cpp b/samples/cpp/stitching_detailed.cpp index 27b6e02..f7f87d3 100644 --- a/samples/cpp/stitching_detailed.cpp +++ b/samples/cpp/stitching_detailed.cpp @@ -405,7 +405,7 @@ int main(int argc, char* argv[]) for (int i = 0; i < num_images; ++i) { - full_img = imread(img_names[i]); + full_img = imread(samples::findFile(img_names[i])); full_img_sizes[i] = full_img.size(); if (full_img.empty()) @@ -727,7 +727,7 @@ int main(int argc, char* argv[]) LOGLN("Compositing image #" << indices[img_idx]+1); // Read image and resize it if necessary - full_img = imread(img_names[img_idx]); + full_img = imread(samples::findFile(img_names[img_idx])); if (!is_compose_scale_set) { if (compose_megapix > 0) diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp index 2ed4ce2..7d6ab99 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp @@ -2,7 +2,7 @@ #include #include // OpenCV -#include +#include #include #include #include diff --git a/samples/cpp/tvl1_optical_flow.cpp b/samples/cpp/tvl1_optical_flow.cpp index 95871c7..bf45dda 100644 --- a/samples/cpp/tvl1_optical_flow.cpp +++ b/samples/cpp/tvl1_optical_flow.cpp @@ -164,8 +164,8 @@ int main(int argc, const char* argv[]) return -1; } - Mat frame0 = imread(frame0_name, IMREAD_GRAYSCALE); - Mat frame1 = imread(frame1_name, IMREAD_GRAYSCALE); + Mat frame0 = imread(samples::findFile(frame0_name), IMREAD_GRAYSCALE); + Mat frame1 = imread(samples::findFile(frame1_name), IMREAD_GRAYSCALE); if (frame0.empty()) { diff --git a/samples/cpp/warpPerspective_demo.cpp b/samples/cpp/warpPerspective_demo.cpp index 591e03d..04e1e95 100644 --- a/samples/cpp/warpPerspective_demo.cpp +++ b/samples/cpp/warpPerspective_demo.cpp @@ -20,7 +20,7 @@ static void help(char** argv) cout << "\nThis is a demo program shows how perspective transformation applied on an image, \n" "Using OpenCV version " << CV_VERSION << endl; - cout << "\nUsage:\n" << argv[0] << " [image_name -- Default ../data/right.jpg]\n" << endl; + cout << "\nUsage:\n" << argv[0] << " [image_name -- Default data/right.jpg]\n" << endl; cout << "\nHot keys: \n" "\tESC, q - quit the program\n" @@ -45,9 +45,9 @@ bool validation_needed = true; int main(int argc, char** argv) { help(argv); - CommandLineParser parser(argc, argv, "{@input| ../data/right.jpg |}"); + CommandLineParser parser(argc, argv, "{@input| data/right.jpg |}"); - string filename = parser.get("@input"); + string filename = samples::findFile(parser.get("@input")); Mat original_image = imread( filename ); Mat image; diff --git a/samples/cpp/watershed.cpp b/samples/cpp/watershed.cpp index 0991bb0..f3fefa7 100644 --- a/samples/cpp/watershed.cpp +++ b/samples/cpp/watershed.cpp @@ -13,7 +13,7 @@ static void help() { cout << "\nThis program demonstrates the famous watershed segmentation algorithm in OpenCV: watershed()\n" "Usage:\n" - "./watershed [image_name -- default is ../data/fruits.jpg]\n" << endl; + "./watershed [image_name -- default is fruits.jpg]\n" << endl; cout << "Hot keys: \n" @@ -48,18 +48,18 @@ 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 | | }{ @input | ../data/fruits.jpg | }"); + cv::CommandLineParser parser(argc, argv, "{help h | | }{ @input | fruits.jpg | }"); if (parser.has("help")) { help(); return 0; } - string filename = parser.get("@input"); + string filename = samples::findFile(parser.get("@input")); Mat img0 = imread(filename, 1), imgGray; if( img0.empty() ) { - cout << "Couldn'g open image " << filename << ". Usage: watershed \n"; + cout << "Couldn't open image " << filename << ". Usage: watershed \n"; return 0; } help(); diff --git a/samples/data/calibration.yml b/samples/data/calibration.yml new file mode 100644 index 0000000..8d30f53 --- /dev/null +++ b/samples/data/calibration.yml @@ -0,0 +1,15 @@ +%YAML:1.0 +images: + - left01.jpg + - left02.jpg + - left03.jpg + - left04.jpg + - left05.jpg + - left06.jpg + - left07.jpg + - left08.jpg + - left09.jpg + - left11.jpg + - left12.jpg + - left13.jpg + - left14.jpg diff --git a/samples/python/facedetect.py b/samples/python/facedetect.py index 4067dc8..eb020d2 100755 --- a/samples/python/facedetect.py +++ b/samples/python/facedetect.py @@ -43,10 +43,10 @@ if __name__ == '__main__': cascade_fn = args.get('--cascade', "../../data/haarcascades/haarcascade_frontalface_alt.xml") nested_fn = args.get('--nested-cascade', "../../data/haarcascades/haarcascade_eye.xml") - cascade = cv.CascadeClassifier(cascade_fn) - nested = cv.CascadeClassifier(nested_fn) + cascade = cv.CascadeClassifier(cv.samples.findFile(cascade_fn)) + nested = cv.CascadeClassifier(cv.samples.findFile(nested_fn)) - cam = create_capture(video_src, fallback='synth:bg=../data/lena.jpg:noise=0.05') + cam = create_capture(video_src, fallback='synth:bg={}:noise=0.05'.format(cv.samples.findFile('samples/data/lena.jpg'))) while True: ret, img = cam.read() -- 2.7.4