Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Make Border and sum

I want to create a border around an image, but only on the bottom and the right, with zeros with the purpose of doing a DFT. I have this piece of code:

cv::Mat computeDFT(cv::Mat image, int optimal_rows, int optimal_cols) {
    cv::Mat padded;

    std::cout << image.rows << " " << image.cols << " " << image.type() << " " << cv::sum(image) << std::endl;

    cv::copyMakeBorder(image, padded, 0, optimal_rows - image.rows, 0, optimal_cols - image.cols, cv::BORDER_CONSTANT, cv::Scalar(0));

    std::cout << padded.rows << " " << padded.cols << " " << padded.type() << " " << cv::sum(padded) << std::endl;


    cv::Mat complexImage(padded.rows, padded.cols, CV_64FC2);
    cv::dft(padded, complexImage, CV_HAL_DFT_COMPLEX_OUTPUT);
    return complexImage;
}

The strange thing is that when i call this function with a motion kernel as image with cos and sines as data, the output is this:

65 65 6 [1, 0, 0, 0]  
482 600 6 [0.99999999999999956, 0, 0, 0]

First one makes sense as it's a 65x65x1 kernel (6 = CV_64FC1), while in the second one i don't have the same sum. Anybody know why?