具有双值的一维直方图 opencv
我正在尝试使用 opencv 创建直方图。我有一个来自模糊操作的图像(32 位),所以我只知道这些值在 [-0.5; 范围内]。 0.5]但我对起始数据一无所知。
问题是我不明白如何设置参数来计算这样的直方图。 我写的代码是:
int numbins=1000;
float range[]={-0.5, 0.5};
float *ranges[]={range};
CvHistogram *hist=cvCreateHist(1, &numbins, CV_HIST_ARRAY, ranges, 1);
cvCalcHist(&img, hist);
img 是我想要获取直方图的图像。如果我尝试打印直方图,我只会得到一张黑色图片,而使用相同的功能,如果使用灰度 8 位图像,我会得到正确的直方图。
I'm trying to create an histogram using opencv. I have an image (32 bit) that came out from a blurring operation, so I just know that the values are in the range [-0.5; 0.5] but I don't know anything else about the starting data.
the problem is that I don't understand how to set the parameters to compute such histogram.
the code I wrote is:
int numbins=1000;
float range[]={-0.5, 0.5};
float *ranges[]={range};
CvHistogram *hist=cvCreateHist(1, &numbins, CV_HIST_ARRAY, ranges, 1);
cvCalcHist(&img, hist);
were img is the image I want to get the histogram. if I try to print the histogram I just get a black picture, while with the same function I get a correct histogram if use a grayscale 8bit image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你看过calcHist 示例?此外, camshiftdemo 大量使用直方图。
您是否使用 normalize 显示之前(camshiftdemo 展示了如何做到这一点)?接近 0 的值在显示时会显示为黑色,但在 0 到 255 之间标准化时会很好地显示。
Have you looked at the calcHist example? Also, the camshiftdemo makes heavy use of histograms.
Are you normalizing the histogram output with normalize before display (camshiftdemo shows how to do this)? Values near 0 will appear black when displayed, but when normalized between say 0 and 255 will show up nicely.