Skip to content

Commit b467cd4

Browse files
committed
Búsqueda de patrones (actualización)
Actualizando el tutorial búsqueda de patrones aplicando template matching con OpenCV 3.x
1 parent 86ee897 commit b467cd4

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

template-match/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ find_package( OpenCV REQUIRED )
44

55
project( Match_Template )
66

7-
file(COPY ../data/messi.jpg ../data/templ.jpg DESTINATION image)
7+
file(COPY images DESTINATION data)
88

99
add_executable( ${PROJECT_NAME} example.cpp )
1010
target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS} )

template-match/example.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ using namespace cv;
66

77
int main(int, char** argv)
88
{
9-
const char* image_window = "Source Image";
9+
const char* image_window = "Busqueda de patrones";
1010
const char* result_window = "Result window";
1111

12-
Mat img_src = imread("image/messi.jpg", 1);
13-
Mat templ = imread("image/templ.jpg", 1);
12+
Mat img_src = imread("data/images/image.png", CV_LOAD_IMAGE_COLOR);
13+
Mat templ = imread("data/images/banana.png", CV_LOAD_IMAGE_COLOR);
14+
Mat mask = imread("data/images/mascara.png", CV_LOAD_IMAGE_COLOR);
1415

1516
// obtener las dimensiones para el cv::Mat resultado
1617
int result_cols = img_src.cols - templ.cols + 1;
@@ -19,10 +20,10 @@ int main(int, char** argv)
1920
Mat result(result_rows, result_cols, CV_32FC1);
2021

2122
// establecer el match template mode
22-
cv::TemplateMatchModes match_mode = cv::TemplateMatchModes::TM_CCOEFF_NORMED;
23+
cv::TemplateMatchModes match_mode = cv::TemplateMatchModes::TM_SQDIFF;
2324

2425
// aplicar match template con el modo indicado y normalizar el resultado
25-
matchTemplate(img_src, templ, result, match_mode);
26+
matchTemplate(img_src, templ, result, match_mode, mask);
2627
normalize(result, result, 0, 1, NORM_MINMAX, -1, Mat());
2728

2829
double minVal, maxVal;
@@ -40,10 +41,13 @@ int main(int, char** argv)
4041
rectangle(img_src, matchLoc, Point(matchLoc.x + templ.cols, matchLoc.y + templ.rows), Scalar(0, 255, 0), 2, CV_AA, 0);
4142

4243
// mostrar las imagenes
43-
imshow(result_window, result);
4444
imshow(image_window, img_src);
4545

46+
imshow("MASCARA", mask);
47+
imshow("PATRON", templ);
48+
4649
waitKey(0);
50+
4751
return 0;
4852
}
4953

template-match/images/banana.png

19.5 KB
Loading

template-match/images/image.png

695 KB
Loading

template-match/images/mascara.png

512 Bytes
Loading

0 commit comments

Comments
 (0)