C++ OpenCV随机林CvRTrees错误
我在OpenCV中使用随机林时出现此错误:C++ OpenCV随机林CvRTrees错误,c++,linux,opencv,random-forest,C++,Linux,Opencv,Random Forest,我在OpenCV中使用随机林时出现此错误: OpenCV Error: Bad argument (5273-th value of 220-th (ordered) variable (=-1.70141e+38) is too large) in CvDTreeTrainData::set_data, file /home/XXX/Downloads/opencv-2.4.6.1/modules/ml/src/tree.cpp, line 551 terminate called after
OpenCV Error: Bad argument (5273-th value of 220-th (ordered) variable (=-1.70141e+38) is too large) in CvDTreeTrainData::set_data, file /home/XXX/Downloads/opencv-2.4.6.1/modules/ml/src/tree.cpp, line 551
terminate called after throwing an instance of 'cv::Exception'
what(): /home/XXX/Downloads/opencv-2.4.6.1/modules/ml/src/tree.cpp:551: error: (-5) 5273-th value of 220-th (ordered) variable (=-1.70141e+38) is too large in function CvDTreeTrainData::set_data
Aborted (core dumped)
这很奇怪,因为打印的数字没有超出浮动范围
(-3.4E+38至+3.4E+38)
我找到了opencv源代码中的打印位置,但我无法理解问题出在哪里:
该文件是tree.cpp
for( i = 0; i < sample_count; i++ )
{
float val = ord_nan;
int si = sidx ? sidx[i] : i;
if( !mask || !mask[(size_t)si*m_step] )
{
if( idata )
val = (float)idata[(size_t)si*step];
else
val = fdata[(size_t)si*step];
if( fabs(val) >= ord_nan )
{
sprintf( err, "%d-th value of %d-th (ordered) "
"variable (=%g) is too large", i, vi, val );
CV_ERROR( CV_StsBadArg, err );
}
num_valid++;
}
if (is_buf_16u)
udst[i] = (unsigned short)i; // TODO: memory corruption may be here
else
idst[i] = i;
_fdst[i] = val;
}
for(i=0;i=ord_nan)
{
sprintf(错误,“%d-th的第%d个值(已订购)”
“变量(=%g)太大”,i,vi,val);
CV_错误(CV_StsBadArg,err);
}
num_valid++;
}
如果(is_buf_16u)
udst[i]=(无符号短)i;//TODO:内存可能已损坏
其他的
idst[i]=i;
_fdst[i]=val;
}
有人能给我一个提示吗?如果您检查tree.cpp文件中的第551行,您可以看到
fabs(val)>=ord\u nan
是必需的,其中ord\u nan=FLT\u MAX*0.5f
。因此,当val==-1.70141e+38
时失败,因为它大于此限制。您的帖子中可能有错误,因为您显示的是第400行,但您的错误消息显示的是第551行。您是对的,但代码来自互联网,我还检查了复制到我的机器上的opencv的来源,结果是一样的。不过,谢谢你。是的,但是如果你看看这个错误,问题是:如果(val==INT_MAX),昨天晚上深入查看,我意识到问题可能是这段代码已经从windows移植到linux,所以可能之前的计算使用了不同的浮点精度。@Bacci我认为你是不对的。错误消息是不同的!如果如果(val==INT_MAX)
失败,错误消息将是“…-th(分类)变量…”,正如您在文章中所述(第418行)。但是您收到的错误消息是“…-th(ordered)variable…”,它位于第549行。他们不匹配。