我在网上搜索,没有找到我的问题的任何好的答案。所以这是我的问题:我使用OpenCV,有一个叫做replaceInvalidDisparties的函数,我必须搜索像素,检查实际值是否为inf,OpenCv中有一个名为cvIsInf(double value)的标准函数来检查值是否为inf,但不知何故,我总是得到分割错误。
using namespace cv;
cv::Mat replaceInvalidDisparities(const cv::Mat &original_disp)
{
cv::Mat output = orignal_disp.clone();
//access pixel
for(int i = 0; i< output.rows; i++)
{
for(int j=0; j<output.cols; j++)
{
//now here i want to check if the actual pixel is inf
cvIsInf(output.at<double>(i,j));
}
}
}但不知何故,它总是给我一个分割错误。有人知道问题出在哪里吗?
发布于 2018-03-14 18:42:48
我看到的第一个问题是没有使用cvIsInf函数的返回值。根据opencv docs:https://docs.opencv.org/3.1.0/db/de0/group__core__utils.html#gae04046b1211c77ff19a535bd78c15964,如果参数是正负无穷大(按照IEEE754标准定义),则函数返回1,否则返回0。
因此,您应该像这样替换循环内的代码以smth:
if (cvIsInf(output.at<double>(i,j))) {
output.at<double>(i,j) = new_value;
}第二个问题是你没有从函数中返回输出矩阵:
return output;发布于 2018-03-15 23:28:46
首先,确保返回一个值。不返回值是一种未定义的行为:Is a return statement mandatory for C++ functions that do not return void?。
函数的其余部分似乎不是分段错误的原因,我建议更改
cv::Mat output = orignal_disp.clone();
至
cv::Mat output(100, 100, CV_64F);
只是为了确保你的矩阵不是病态的。(我准备发表评论;没有足够的声誉。)
https://stackoverflow.com/questions/49273797
复制相似问题