Weird output while finding entropy of frames of a video in opencv

我的梦境 提交于 2019-12-04 07:39:46

It might be the case that prob[i] = 0 for some i, therefore you are calculating log(0) which is undefined. To fix that you simply discard such "probabilities":

for (int i = 0; i < numBins; ++i) {
    if (prob[i])
        entropy += prob[i]*log(prob[i]);
}

For the other error you found regarding the 0 value in the bin 255, that is due to the range you specified. OpenCV considers the range for the relevant function as [start, end), so specifying a range of [0, 255) is going to ignore the end value of 255. What you want is to keep both 0 and 255, therefore:

float range[] = {0, numBins};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!