05/14 끝
This commit is contained in:
34
ch13/template/main.cpp
Normal file
34
ch13/template/main.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <iostream>
|
||||
#include "opencv2/opencv.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
int main() {
|
||||
Mat img = imread("../../resources/images/circuit.bmp", IMREAD_COLOR);
|
||||
Mat templ = imread("../../resources/images/crystal.bmp", IMREAD_COLOR);
|
||||
|
||||
img = img + Scalar(50, 50, 50);
|
||||
|
||||
Mat noise(img.size(), CV_32SC3);
|
||||
randn(noise, 0, 10);
|
||||
add(img, noise, img, Mat(), CV_8UC3);
|
||||
|
||||
Mat res, res_norm;
|
||||
matchTemplate(img, templ, res, TM_CCOEFF_NORMED);
|
||||
normalize(res, res_norm, 0, 255, NORM_MINMAX, CV_8U);
|
||||
|
||||
double maxv;
|
||||
Point maxloc;
|
||||
minMaxLoc(res, 0, &maxv, 0, &maxloc);
|
||||
cout << "maxv: " << maxv << endl;
|
||||
|
||||
rectangle(img, Rect(maxloc.x, maxloc.y, templ.cols, templ.rows), Scalar(0, 0, 255), 2);
|
||||
|
||||
imshow("templ", templ);
|
||||
imshow("res_norm", res_norm);
|
||||
imshow("img", img);
|
||||
|
||||
waitKey();
|
||||
destroyAllWindows();
|
||||
}
|
||||
Reference in New Issue
Block a user