【发布时间】:2013-09-22 09:51:46
【问题描述】:
这是我在程序中使用的代码:
calcHist( &pre_img, 1, channels, Mat(), // do not use mask
hist, 1, histSize, ranges,
true, // the histogram is uniform
false );
Mat histNorm = hist / (pre_img.rows * pre_img.cols);
double entropy = 0.0;
for (int i=0; i<histNorm.rows; i++)
{
float binEntry = histNorm.at<float>(i,0);
if (binEntry != 0.0)
{
entropy -= binEntry * log(binEntry);
}
}
cout<<entropy<<endl;
第一件事是当我像 entropy -= binEntry * log2(binEntry); 这样输入它时,它给我在 log2 上的错误,我在 VS 2010 中添加了数学和数字库,但仍然收到错误,代码中的第二点是每当我在同一个视频上运行它时,它在每次执行时都会给我不同的值,比如它给我10.0 , 2.0 , 0.05,而不是下一次运行程序时给我的同一帧显示8.0 , 1.5 , 0.01these are sample values not exact
【问题讨论】:
-
您看到了什么错误?
-
@AlanStokes
Identifier log2 is not defined -
你有
#include <math.h>吗? -
@AlanStokes 是的,我正在使用它
-
log2仅在 C99 标准中定义。试试define functionlog2yourself
标签: c++ opencv computer-vision entropy