|
static int | templateMatching (cv::Mat img, std::vector< cv::Mat > templVector, std::vector< std::vector< cv::Point >> *found4CornersVector, std::vector< double > *bestValues, int templ_method=cv::TM_SQDIFF, std::vector< double > scaleFactors=std::vector< double >(), bool showDisplay=true) |
| Detector::templateMatching check function below, this one is used if multiple templates want be used. More...
|
|
static int | templateMatching (cv::Mat img, cv::Mat templ, std::vector< cv::Point > *found4Corners, double *bestValue=NULL, int templ_method=cv::TM_SQDIFF, std::vector< double > scaleFactors=std::vector< double >(), bool showDisplay=true) |
| Detector::templateMatching template Matching method using opencv functions. Various method can be choosen It detects the template and return a rectangle (represented as the 4 corners) around the best match. So if a precise detection is needed, template and image should have same rotation, and be both square as possible. Size of template is not important because various scaling of the original image are tried and the best match returned (i.e. scale invariant template matching) More...
|
|
static void | drawSquares (cv::Mat image, const std::vector< std::vector< cv::Point > > squares, const char *wndname="Square Detection Demo") |
| Detector::drawSquares function to draw square in images. More...
|
|
static int | findSquare (cv::Mat &image, std::vector< std::vector< cv::Point >> *found4CornersVector, int threshLevels=11, int cannyThresh=50) |
| Detector::findSquare find all square in images, exploiting functions of opencv. In practice is a blob detector but specific for the squares, e.g. it check if polygon founded have 4 side and four 90 degree angle (with some margins), and of a certain minimum area (to ot consider false positive). Code from opencv tutorial: https://docs.opencv.org/3.4/db/d00/samples_2cpp_2squares_8cpp-example.html#a20. More...
|
|
Definition at line 12 of file detector.h.
void Detector::drawSquares |
( |
cv::Mat |
image, |
|
|
const std::vector< std::vector< cv::Point > > |
squares, |
|
|
const char * |
wndname = "Square Detection Demo" |
|
) |
| |
|
static |
int Detector::findSquare |
( |
cv::Mat & |
image, |
|
|
std::vector< std::vector< cv::Point >> * |
found4CornersVector, |
|
|
int |
threshLevels = 11 , |
|
|
int |
cannyThresh = 50 |
|
) |
| |
|
static |
Detector::findSquare find all square in images, exploiting functions of opencv. In practice is a blob detector but specific for the squares, e.g. it check if polygon founded have 4 side and four 90 degree angle (with some margins), and of a certain minimum area (to ot consider false positive). Code from opencv tutorial: https://docs.opencv.org/3.4/db/d00/samples_2cpp_2squares_8cpp-example.html#a20.
functions for METHOD FIND SQUARES
- Parameters
-
image | in which look for squares. Both gray and colored image are accepted |
*found4CornersVector | OUT each element contain a vector of 4 point (ie, defining a square). |
threshLevels | OPTIONAL number of threshold level. The more they are the more the result is good, but obviously also more computation time |
threshold | for opencv Canny function, it is the maximum threshold. Canny is used only once, for the thresholdLevel equal to zero. Check _findSquares comments. |
- Returns
- 0 correct execution
- Note
- Please note that there is no way to understand which is the more precise square (if they are more than one). Various trial show that is the squares are more than one, they are almost on the same position, so they are not really false positive (it is because we have three channels one for each color so a squares is detected for each channel.
-
If a colored image is used, the result will be more precise because detection is done on each color channel.
- Todo:
- various parameters are hardcoded in _findSquares. Maybe they can be setted from external caller.
Definition at line 28 of file detector.cpp.
int Detector::templateMatching |
( |
cv::Mat |
img, |
|
|
std::vector< cv::Mat > |
templVector, |
|
|
std::vector< std::vector< cv::Point >> * |
found4CornersVector, |
|
|
std::vector< double > * |
bestValues, |
|
|
int |
templ_method = cv::TM_SQDIFF , |
|
|
std::vector< double > |
scaleFactors = std::vector<double>() , |
|
|
bool |
showDisplay = true |
|
) |
| |
|
static |
Detector::templateMatching check function below, this one is used if multiple templates want be used.
functions for METHOD TEMPLATE MATCHING
- Parameters
-
img | image input where to find the match |
templVector | vector of templates |
*found4CornersVector | OUT each element will contain the 4 corners for each template |
*bestValues | OUT each element will contain the best value for each template (warning at MIN MAX based on method) |
templ_method | OPTIONAL 0 TM_SQDIFF : squared differences (BEST is MIN) 1 SQDIFF_NORMED: squared differences normed (BEST is MIN) 2 CCORR : cross correlation? (BEST is MAX) 3 CCORR_NORMED cross correlation normed? (BEST is MAX) 4 CCOEFF: ? (BEST is MAX) 5 CCOEFF_NORMED: ? (BEST is MAX) |
scaleFactors | OPTIONAL the list of scaling factor default one is provided in the code |
showDisplay | OPTIONAL, choose if show template matching result in a window image |
- Returns
- 0 correct execution
Definition at line 269 of file detector.cpp.
int Detector::templateMatching |
( |
cv::Mat |
img, |
|
|
cv::Mat |
templ, |
|
|
std::vector< cv::Point > * |
found4Corners, |
|
|
double * |
bestValue = NULL , |
|
|
int |
templ_method = cv::TM_SQDIFF , |
|
|
std::vector< double > |
scaleFactors = std::vector<double>() , |
|
|
bool |
showDisplay = true |
|
) |
| |
|
static |
Detector::templateMatching template Matching method using opencv functions. Various method can be choosen It detects the template and return a rectangle (represented as the 4 corners) around the best match. So if a precise detection is needed, template and image should have same rotation, and be both square as possible. Size of template is not important because various scaling of the original image are tried and the best match returned (i.e. scale invariant template matching)
- Parameters
-
img | image input where to find the match |
templ | the template |
*found4Corners | OUT the founded4Corners passed by reference |
*bestValue | OUT OPTIONAL the value of the best match among all scalings. NOTE that depending on method can be a MAX or MIN value |
templ_method | OPTIONAL 0 TM_SQDIFF : squared differences (BEST is MIN) 1 SQDIFF_NORMED: squared differences normed (BEST is MIN) 2 CCORR : cross correlation? (BEST is MAX) 3 CCORR_NORMED cross correlation normed? (BEST is MAX) 4 CCOEFF: ? (BEST is MAX) 5 CCOEFF_NORMED: ? (BEST is MAX) |
scaleFactors | OPTIONAL the list of scaling factor default one is provided in the code |
showDisplay | OPTIONAL, choose if show template matching result in a window image |
- Note
- the found4Corners are in CLOCKWISE order beginning from the TOP LEFT
-
template matching is good until no lighthing/transformations can happen, so not really suitable for continuosly detect something in a video.
-
there is not a huge difference between the different summing methods, formulas can be found in the opencv documentation :
- Returns
- 0 correct execution
Definition at line 315 of file detector.cpp.
The documentation for this class was generated from the following files: