#include <iostream>
int main(
int argc,
const char** argv )
{
"{ 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." << endl
<< endl
<< "Available methods: https://docs.opencv.org/5.x/df/dfb/group__imgproc__object.html#ga3a7850640f1fe1f58fe91a2d7583695d" << endl
<<
" TM_CCORR = " << (int)
TM_CCORR << endl
<< endl;
{
cout << "can not open " << filename << endl;
return -1;
}
{
cout << "can not open " << tmplname << endl;
return -1;
}
if(mask.empty())
{
cout << "can not open " << maskname << endl;
return -1;
}
int method = parser.
get<
int>(
"cm");
double minVal, maxVal;
minMaxLoc(res, &minVal, &maxVal, &minLoc, &maxLoc);
else
imshow(
"detected template", img);
return 0;
}
Designed for command line parsing.
Definition utility.hpp:915
T get(const String &name, bool space_delete=true) const
Access arguments by name.
Definition utility.hpp:981
void printMessage() const
Print help message.
Comma-separated Matrix Initializer.
Definition mat.hpp:964
MatSize size
Definition mat.hpp:2511
bool empty() const
Returns true if the array has no elements.
void minMaxLoc(InputArray src, double *minVal, double *maxVal=0, Point *minLoc=0, Point *maxLoc=0, InputArray mask=noArray())
Finds the global minimum and maximum in an array.
Rect2i Rect
Definition types.hpp:499
Point2i Point
Definition types.hpp:209
Scalar_< double > Scalar
Definition types.hpp:712
cv::String findFile(const cv::String &relative_path, bool required=true, bool silentMode=false)
Try to find requested data file.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
Loads an image from a file.
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a simple, thick, or filled up-right rectangle.
void matchTemplate(InputArray image, InputArray templ, OutputArray result, int method, InputArray mask=noArray())
Compares a template against overlapped image regions.
@ TM_SQDIFF_NORMED
Definition imgproc.hpp:3591
@ TM_CCORR
Definition imgproc.hpp:3598
@ TM_SQDIFF
Definition imgproc.hpp:3587
@ TM_CCOEFF
Definition imgproc.hpp:3609
@ TM_CCOEFF_NORMED
Definition imgproc.hpp:3621
@ TM_CCORR_NORMED
Definition imgproc.hpp:3602
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3