1

首先,getGaussianKernel 和 filter2D 使用双精度值吗?如果是,如何?

我有这个:

void smoothAngles(cv::Mat& cos_angles, cv::Mat& angles){
    cv::Mat sin_angles;

    cos_angles.create(angles.size(), CV_64FC1);
    sin_angles.create(angles.size(), CV_64FC1);

    for(int i = 0; i < cos_angles.cols; i++){
        for(int j = 0; j < cos_angles.rows; j++){
            cos_angles.at<double>(i, j) = std::cos(2 * angles.at<double>(i, j));
            sin_angles.at<double>(i, j) = std::sin(2 * angles.at<double>(i, j));
        }
    }

    cv::Mat gaussKernel = cv::getGaussianKernel(5, 1.0, CV_32FC1);

    // aplica o filtro gaussiano low-pass
    cv::filter2D(cos_angles, cos_angles, cos_angles.depth(), gaussKernel);
    cv::filter2D(sin_angles, sin_angles, sin_angles.depth(), gaussKernel);

    for (int i = 0; i < cos_angles.cols; i++) {
        for (int j = 0; j < cos_angles.rows; j++) {
            cos_angles.at<double>(i, j) = std::atan2(sin_angles.at<double>(i, j), cos_angles.at<double>(i, j)) / 2;
        }
    }
}

错误发生在第一次使用filter2D. 错误如下:

FingerPrint - 01(11534) malloc: *** error for object 0x10081a408: incorrect 
checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug

我尝试使用cv::GaussianBlur(cos_angles, cos_angles, cv::Size(5,5), 1.0);,但出现相同的错误。

4

1 回答 1

3

您以错误的坐标顺序访问矩阵。第一个坐标必须是行索引和第二个 - 列索引:

for(int i = 0; i < cos_angles.rows; i++){
    for(int j = 0; j < cos_angles.cols; j++){
        cos_angles.at<double>(i, j) = std::cos(2 * angles.at<double>(i, j));
        sin_angles.at<double>(i, j) = std::sin(2 * angles.at<double>(i, j));
    }
}
于 2013-08-30T04:42:42.387 回答