void speedy_convolution(const CvMat* A, const CvMat* B, CvMat* C)
{
int dft_M = cvGetOptimalDFTSize(A->rows + B->rows - 1);
int dft_N = cvGetOptimalDFTSize(A->cols + B->cols - 1);
CvMat* dft_A = cvCreateMat(dft_M, dft_N, A->type);
CvMat* dft_B = cvCreateMat(dft_M, dft_N, B->type);
CvMat tmp;
//copy A to dft_A and pad dft_A with zeros
cvGetSubRect(dft_A, &tmp, cvRect(0, 0, A->cols, A->rows));
cvCopy(A, &tmp);
cvGetSubRect(dft_A, &tmp, cvRect(A->cols, 0, dft_A->cols - A->cols, A->rows));
cvZero(&tmp);
}
这个函数里,当然我只写了一半,是学习Opencv中文版204页上的,不理解
//copy A to dft_A and pad dft_A with zeros
cvGetSubRect(dft_A, &tmp, cvRect(0, 0, A->cols, A->rows));
cvCopy(A, &tmp);
cvGetSubRect(dft_A, &tmp, cvRect(A->cols, 0, dft_A->cols - A->cols, A->rows));
cvZero(&tmp);
这一段,cvZero之后,那tmp里不就全是0了么?那这么多还有啥意义,而且cvCopy(A, &tmp);这个不是把上一部的数据覆盖了吗?
求大神解答!!
{
int dft_M = cvGetOptimalDFTSize(A->rows + B->rows - 1);
int dft_N = cvGetOptimalDFTSize(A->cols + B->cols - 1);
CvMat* dft_A = cvCreateMat(dft_M, dft_N, A->type);
CvMat* dft_B = cvCreateMat(dft_M, dft_N, B->type);
CvMat tmp;
//copy A to dft_A and pad dft_A with zeros
cvGetSubRect(dft_A, &tmp, cvRect(0, 0, A->cols, A->rows));
cvCopy(A, &tmp);
cvGetSubRect(dft_A, &tmp, cvRect(A->cols, 0, dft_A->cols - A->cols, A->rows));
cvZero(&tmp);
}
这个函数里,当然我只写了一半,是学习Opencv中文版204页上的,不理解
//copy A to dft_A and pad dft_A with zeros
cvGetSubRect(dft_A, &tmp, cvRect(0, 0, A->cols, A->rows));
cvCopy(A, &tmp);
cvGetSubRect(dft_A, &tmp, cvRect(A->cols, 0, dft_A->cols - A->cols, A->rows));
cvZero(&tmp);
这一段,cvZero之后,那tmp里不就全是0了么?那这么多还有啥意义,而且cvCopy(A, &tmp);这个不是把上一部的数据覆盖了吗?
求大神解答!!