include “opencv2/core/core.hpp”
include “opencv2/imgproc/imgproc.hpp”
include “opencv2/highgui/highgui.hpp”
include
using namespace cv;
using namespace std;
Mat getTemplateImage(Mat sourceImage);
Mat getSquareSourceIntegrationImage(Mat sourceImage);
void convolveDFT(Mat A, Mat B, Mat& C)
{
// reallocate the output array if needed
//A.convertTo(A, CV_8U);
//tempB.convertTo(tempB, CV_8U);
//cv::imshow(“A”, A);
C.create(abs(A.rows - B.rows) + 1, abs(A.cols - B.cols) + 1, A.type());
Size dftSize;
// calculate the size of DFT transform
dftSize.width = getOptimalDFTSize(A.cols + B.cols - 1);
dftSize.height = getOptimalDFTSize(A.rows + B.rows - 1);
// allocate temporary buffers and initialize them with 0's
Mat tempA(dftSize, A.type(), Scalar::all(0));//initial 0
Mat tempB(dftSize, B.type(), Scalar::all(0));
// copy A and B to the top-left corners of tempA and tempB, respectively
Mat roiA(tempA, Rect(0, 0, A.cols, A.rows));
A.copyTo(roiA);
Mat roiB(tempB, Rect(0, 0, B.cols, B.rows));
B.copyTo(roiB);
// now transform the padded A & B in-place;
// use "nonzeroRows" hint for faster processing
//tempA.convertTo(tempA, CV_8U);
//tempB.convertTo(tempB, CV_8U);
//cv::imshow("tempA", tempA);
//cv::imshow("tempB", tempB);
//cv::waitKey();
double start = double(getTickCount());
dft(tempA, tempA, 0, A.rows);
dft(tempB, tempB, 0, B.rows);
// multiply the spectrums;
// the function handles packed spectrum representations well
mulSpectrums(tempA, tempB, tempA, DFT_COMPLEX_OUTPUT, true);
//mulSpectrums(tempA, tempB, tempA, DFT_REAL_OUTPUT);
// transform the product back from the frequency domain.
// Even though all the result rows will be non-zero,
// you need only the first C.rows of them, and thus you
// pass nonzeroRows == C.rows
dft(tempA, tempA, DFT_INVERSE + DFT_SCALE, C.rows);
// now copy the result back to C.
tempA(Rect(0, 0, C.cols, C.rows)).copyTo(C);
double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();//计时
cout << "time consu