Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 熵改变每次执行时的值_C++_Opencv_Computer Vision_Entropy - Fatal编程技术网

C++ 熵改变每次执行时的值

C++ 熵改变每次执行时的值,c++,opencv,computer-vision,entropy,C++,Opencv,Computer Vision,Entropy,以下是我在程序中使用的代码: 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_i

以下是我在程序中使用的代码:

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;
calcHist(&pre_img,1,channels,Mat(),//不要使用掩码
历史,1,历史大小,范围,
true,//直方图是一致的
假);
Mat histNorm=hist/(预模拟行*预模拟列);
双熵=0.0;

对于(int i=0;i
log2
仅在C99标准中定义。不使用
log2
的解决方法可能是将其替换为不同的基数,因为对数
logb(x)
可以使用以下公式从任意基
k
x
b
的对数计算得出:

所以你可以替换

if (binEntry != 0.0)
          {
            entropy -= binEntry * log2(binEntry);
          }


你看到了什么错误?@AlanStokes
标识符log2没有定义
你有
#include
吗?@AlanStokes是的,我正在使用它
log2
仅在C99标准中定义。请注意你没有明白我的问题,我说我在声明
log2
甚至
log(2)时有错误
,您的代码仍然显示错误。您可以使用其他数学函数吗?我正在使用三个库,
#include#include#include
您可以使用math.h中的任何其他函数吗,即sin?请尝试
log(2.0)
,因为参数应该是
float
double
if (binEntry != 0.0)
          {
            entropy -= binEntry * log(binEntry)/log(2.0);
                                                     ^
                                                also you should use `log(2.0)`
                                                because the argument should be
                                                double or float
          }