首先,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);
代替,但发生了同样的错误。
答案 0 :(得分: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));
}
}