简体   繁体   中英

OpenCV - gaussianKernel with filter2D and double values

Firstly, getGaussianKernel and filter2D work with double values? If yes, how?

I have this:

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;
        }
    }
}

The error occurs in the first use of filter2D . The error is the following:

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

I tried use cv::GaussianBlur(cos_angles, cos_angles, cv::Size(5,5), 1.0); instead, but occurs the same error.

You access matrix with wrong coordinate order. First coordinate must be row index and second - column index:

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));
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM