samples: use findFile() in T-API samples

pull/12354/head
Alexander Alekhin 6 years ago
parent e8e2197032
commit 9ea8c775f8
  1. 8
      samples/tapi/clahe.cpp
  2. 4
      samples/tapi/hog.cpp
  3. 2
      samples/tapi/opencl_custom_kernel.cpp
  4. 8
      samples/tapi/pyrlk_optical_flow.cpp
  5. 4
      samples/tapi/squares.cpp
  6. 22
      samples/tapi/ufacedetect.cpp

@ -63,8 +63,9 @@ int main(int argc, char** argv)
setTrackbarPos("Tile Size", "CLAHE", cur_tilesize.width); setTrackbarPos("Tile Size", "CLAHE", cur_tilesize.width);
setTrackbarPos("Clip Limit", "CLAHE", cur_clip); setTrackbarPos("Clip Limit", "CLAHE", cur_clip);
if(infile != "") if(!infile.empty())
{ {
infile = samples::findFile(infile);
imread(infile).copyTo(frame); imread(infile).copyTo(frame);
if(frame.empty()) if(frame.empty())
{ {
@ -87,7 +88,10 @@ int main(int argc, char** argv)
else else
imread(infile).copyTo(frame); imread(infile).copyTo(frame);
if(frame.empty()) if(frame.empty())
continue; {
waitKey();
break;
}
cvtColor(frame, frame, COLOR_BGR2GRAY); cvtColor(frame, frame, COLOR_BGR2GRAY);
pFilter->apply(frame, outframe); pFilter->apply(frame, outframe);

@ -61,7 +61,7 @@ int main(int argc, char** argv)
"{ h help | | print help message }" "{ h help | | print help message }"
"{ i input | | specify input image}" "{ i input | | specify input image}"
"{ c camera | -1 | enable camera capturing }" "{ c camera | -1 | enable camera capturing }"
"{ v video | ../data/vtest.avi | use video as input }" "{ v video | vtest.avi | use video as input }"
"{ g gray | | convert image to gray one or not}" "{ g gray | | convert image to gray one or not}"
"{ s scale | 1.0 | resize the image before detect}" "{ s scale | 1.0 | resize the image before detect}"
"{ o output | | specify output path when input is images}"; "{ o output | | specify output path when input is images}";
@ -107,7 +107,7 @@ App::App(CommandLineParser& cmd)
make_gray = cmd.has("gray"); make_gray = cmd.has("gray");
resize_scale = cmd.get<double>("s"); resize_scale = cmd.get<double>("s");
vdo_source = cmd.get<string>("v"); vdo_source = samples::findFileOrKeep(cmd.get<string>("v"));
img_source = cmd.get<string>("i"); img_source = cmd.get<string>("i");
output = cmd.get<string>("o"); output = cmd.get<string>("o");
camera_id = cmd.get<int>("c"); camera_id = cmd.get<int>("c");

@ -72,7 +72,7 @@ int main(int argc, char** argv)
string image_file = args.get<string>("i"); string image_file = args.get<string>("i");
if (!image_file.empty()) if (!image_file.empty())
{ {
Mat image = imread(image_file); Mat image = imread(samples::findFile(image_file));
if (image.empty()) if (image.empty())
{ {
cout << "error read image: " << image_file << endl; cout << "error read image: " << image_file << endl;

@ -96,8 +96,8 @@ int main(int argc, const char* argv[])
} }
bool defaultPicturesFail = true; bool defaultPicturesFail = true;
string fname0 = cmd.get<string>("left"); string fname0 = samples::findFile(cmd.get<string>("left"));
string fname1 = cmd.get<string>("right"); string fname1 = samples::findFile(cmd.get<string>("right"));
string vdofile = cmd.get<string>("video"); string vdofile = cmd.get<string>("video");
string outfile = cmd.get<string>("output"); string outfile = cmd.get<string>("output");
int points = cmd.get<int>("points"); int points = cmd.get<int>("points");
@ -105,9 +105,9 @@ int main(int argc, const char* argv[])
int inputName = cmd.get<int>("c"); int inputName = cmd.get<int>("c");
UMat frame0; UMat frame0;
imread(fname0, cv::IMREAD_GRAYSCALE).copyTo(frame0); imread(fname0, IMREAD_GRAYSCALE).copyTo(frame0);
UMat frame1; UMat frame1;
imread(fname1, cv::IMREAD_GRAYSCALE).copyTo(frame1); imread(fname1, IMREAD_GRAYSCALE).copyTo(frame1);
vector<cv::Point2f> pts(points); vector<cv::Point2f> pts(points);
vector<cv::Point2f> nextPts(points); vector<cv::Point2f> nextPts(points);

@ -156,7 +156,7 @@ int main(int argc, char** argv)
cout << "OpenCL was disabled" << endl; cout << "OpenCL was disabled" << endl;
} }
string inputName = cmd.get<string>("i"); string inputName = samples::findFile(cmd.get<string>("i"));
string outfile = cmd.get<string>("o"); string outfile = cmd.get<string>("o");
int iterations = 10; int iterations = 10;
@ -164,7 +164,7 @@ int main(int argc, char** argv)
vector<vector<Point> > squares; vector<vector<Point> > squares;
UMat image; UMat image;
imread(inputName, 1).copyTo(image); imread(inputName, IMREAD_COLOR).copyTo(image);
if( image.empty() ) if( image.empty() )
{ {
cout << "Couldn't load " << inputName << endl; cout << "Couldn't load " << inputName << endl;

@ -28,9 +28,6 @@ void detectAndDraw( UMat& img, Mat& canvas, CascadeClassifier& cascade,
CascadeClassifier& nestedCascade, CascadeClassifier& nestedCascade,
double scale, bool tryflip ); double scale, bool tryflip );
string cascadeName = "../../data/haarcascades/haarcascade_frontalface_alt.xml";
string nestedCascadeName = "../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml";
int main( int argc, const char** argv ) int main( int argc, const char** argv )
{ {
VideoCapture capture; VideoCapture capture;
@ -44,8 +41,8 @@ int main( int argc, const char** argv )
double scale; double scale;
cv::CommandLineParser parser(argc, argv, cv::CommandLineParser parser(argc, argv,
"{cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|}" "{cascade|data/haarcascades/haarcascade_frontalface_alt.xml|}"
"{nested-cascade|../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|}" "{nested-cascade|data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|}"
"{help h ||}{scale|1|}{try-flip||}{@filename||}" "{help h ||}{scale|1|}{try-flip||}{@filename||}"
); );
if (parser.has("help")) if (parser.has("help"))
@ -53,8 +50,8 @@ int main( int argc, const char** argv )
help(); help();
return 0; return 0;
} }
cascadeName = parser.get<string>("cascade"); string cascadeName = samples::findFile(parser.get<string>("cascade"));
nestedCascadeName = parser.get<string>("nested-cascade"); string nestedCascadeName = samples::findFileOrKeep(parser.get<string>("nested-cascade"));
scale = parser.get<double>("scale"); scale = parser.get<double>("scale");
tryflip = parser.has("try-flip"); tryflip = parser.has("try-flip");
inputName = parser.get<string>("@filename"); inputName = parser.get<string>("@filename");
@ -66,10 +63,10 @@ int main( int argc, const char** argv )
} }
if ( !nestedCascade.load( nestedCascadeName ) ) if ( !nestedCascade.load( nestedCascadeName ) )
cerr << "WARNING: Could not load classifier cascade for nested objects" << endl; cerr << "WARNING: Could not load classifier cascade for nested objects: " << nestedCascadeName << endl;
if( !cascade.load( cascadeName ) ) if( !cascade.load( cascadeName ) )
{ {
cerr << "ERROR: Could not load classifier cascade" << endl; cerr << "ERROR: Could not load classifier cascade: " << cascadeName << endl;
help(); help();
return -1; return -1;
} }
@ -84,9 +81,8 @@ int main( int argc, const char** argv )
} }
else else
{ {
if( inputName.empty() ) inputName = samples::findFileOrKeep(inputName);
inputName = "../data/lena.jpg"; imread(inputName, IMREAD_COLOR).copyTo(image);
image = imread( inputName, 1 ).getUMat(ACCESS_READ);
if( image.empty() ) if( image.empty() )
{ {
if(!capture.open( inputName )) if(!capture.open( inputName ))
@ -133,7 +129,7 @@ int main( int argc, const char** argv )
len--; len--;
buf[len] = '\0'; buf[len] = '\0';
cout << "file " << buf << endl; cout << "file " << buf << endl;
image = imread( buf, 1 ).getUMat(ACCESS_READ); imread(samples::findFile(buf), IMREAD_COLOR).copyTo(image);
if( !image.empty() ) if( !image.empty() )
{ {
detectAndDraw( image, canvas, cascade, nestedCascade, scale, tryflip ); detectAndDraw( image, canvas, cascade, nestedCascade, scale, tryflip );

Loading…
Cancel
Save