Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
OPENCV - Topic 5 - Template Matching

OPENCV - Topic 5 - Template Matching

Ratings: (0)|Views: 1,192|Likes:
Published by huahongquan2007

More info:

Published by: huahongquan2007 on Oct 05, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

12/10/2013

pdf

text

original

 
#include <iostream>  #include <fstream>  using namespacestd; #include <opencv2\core\core.hpp>  #include <opencv2\highgui\highgui.hpp>  #include <opencv2\imgproc\imgproc.hpp>  using namespacecv; intham(int** &tImg,char* fname,int&tWidth,int&tHeight,float& tAverage){Mat tInput = imread("tMatching_template.jpg");Mat input;cvtColor(tInput,input,CV_RGB2GRAY);tHeight = input.rows;tWidth = input.cols;tImg =new int* [tHeight]; tAverage = 0;for(inti = 0 ; i < tHeight ; i++) tImg[i] =new int[tWidth]; for(inti = 0 ; i < tHeight ; i++) for(intj = 0 ; j < tWidth ; j++){ tImg[i][j] = (int)input.at<uchar>(i,j);tAverage += tImg[i][j];}tAverage = tAverage / (tHeight* tWidth);//nMask = 0; //for(int i = 0 ; i <m ; i++) // for(int j = 0 ; j <n ; j++) // nMask += mask[i][j]; //nMask = (nMask==0)?1:nMask; // namedWindow("TEMP");imshow("TEMP",input);return0;}voidmain(){Mat input = imread("pic1.jpg");Mat img;// START IMAGE cvtColor(input,img,CV_RGB2GRAY);Mat img_new = img.clone();// FINAL IMAGE inttWidth = 45;// TEMPLATE WIDTH  inttHeight = 29;// TEMPLATE HEIGHT  floattAverage = 0;// Average Gray Level of Template 
 
 int** tImg = NULL;// Template Image  ham(tImg,"tMatching_template.jpg", tWidth, tHeight, tAverage);//---------------------------------// cout <<"iWIDTH : "<< img.cols<<endl;cout <<"iHEIGHT : "<< img.rows<<endl;cout <<"tWIDTH : "<< tWidth<<endl;cout <<"tHEIGHT : "<< tHeight<<endl;cout <<"tAverage : "<< tAverage<<endl;namedWindow("BEFORE");imshow("BEFORE",img);//------------------------------------------ // TEMPLATE MATCHING floatiAverage = 0;// Average Gray Level of Image  floatthreshold = 0.800;//Threshold  floatcor = 0;intfoundX= 0, foundY = 0;/// COMPUTE for(inti = 0 ; i < img.rows ; i++){ if( (img.rows - i) < tHeight )break; for(intj = 0 ; j < img.cols ; j ++){ if( (img.cols - j) < tWidth )break; /// FIND AVERAGE GRAY LEVEL OF SECTION IMAGE for(intk = 0; k < tHeight; k++) for(intl = 0; l < tWidth ; l++){ iAverage += (int)img.at<uchar>(i + k, j + l);}iAverage = iAverage / (tHeight * tWidth);/// COMPUTE COR floatnumerator = 0;//tu so  floatdenominator = 0;// mau so  floattCor = 0;// numerator / denominator  floatsumxix = 0;// sum xi - x  floatsumyiy = 0;// sum yi - y //denominator =sqrt(sumxix * sumyiy) for(intk = 0; k < tHeight; k++) for(intl = 0; l < tWidth ; l++){ intxi = tImg[k][l];intyi = img_new.at<uchar>(i + k, j + l);numerator += (xi - tAverage)*(yi - iAverage);

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->