-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjdet.cpp
More file actions
52 lines (39 loc) · 1.17 KB
/
objdet.cpp
File metadata and controls
52 lines (39 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <stdio.h>
#include<deque>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
using namespace cv;
using namespace std;
int main(){
//vector<vector<Point> >contour;
//vector<Vec4i>hir;
//VideoCapture vid(0);
int ans;
Mat img;
Mat tepl;
//int LV=150;
//while(vid.isOpened()) {
//vid>>img;
img=imread("img.jpg",1);
tepl=imread("imgt.jpg",1);
int res_col=img.cols-tepl.cols+1;
int res_row=img.rows-tepl.rows+1;
namedWindow("IP",WINDOW_AUTOSIZE);
namedWindow("TEMPL",WINDOW_AUTOSIZE);
namedWindow("OP",WINDOW_AUTOSIZE);
imshow("IP",img);
imshow("TEMPL",tepl);
Mat op(res_row,res_col,CV_32FC1,Scalar(0));
// op=img.clone();
matchTemplate(img,tepl,op,CV_TM_SQDIFF_NORMED);
double minVal; double maxVal; Point minLoc; Point maxLoc;
Point matchLoc;
minMaxLoc( op, &minVal, &maxVal, &minLoc, &maxLoc, Mat() );
matchLoc=minLoc;
// rectangle(op,matchLoc,Point(matchLoc.x+tepl.cols,matchLoc.y+tepl.rows),Scalar(0,0,0),1,8,0);
rectangle(img,matchLoc,Point(matchLoc.x+tepl.cols,matchLoc.y+tepl.rows),Scalar(0,0,0),2);
imshow("OP",img);
waitKey(0);
}