繁体   English   中英

OpenCV直方图不计算来自灰色的BGR中的白色像素

[英]OpenCV Histogram doesn't count white pixels in BGR from GRAY

我将OpenCV与C ++结合使用以获取BGR中图像的直方图(使用calcHist函数),该图像是使用GREY2BGR从灰度转换而成的。

奇怪的是,直方图似乎要计算除白色像素(255、255、255)以外的所有像素。

会是什么情况? 当然,我可以将其转换为HSV并查找S = 0以检测白色像素(我希望它可以工作,尚未进行过测试),但是当我已经计算完直方图后为什么要这样做呢? ? 你有什么想法?

PS。 当涉及到代码时,我使用流行的“ OpenCV Cookbook”第4章中的配方对颜色直方图进行计数。 我在这行中读取了特定的直方图bin:

int val1 = histo.at<float>(col1.blue(),col1.green(),col1.red());

其中col1是QColor类型(RGB,所以我按上面显示的顺序读取值以获得BGR)。

您是否正确设置了范围?

根据示例: http : //docs.opencv.org/modules/imgproc/doc/histograms.html#calchist

cv::Mat bgr(480, 640, CV_8UC3, cv::Scalar(255.0, 255.0, 255.0));

// Quantize the B, G and R channels to 30 levels
int histSize[] = {30, 30, 30};

// B, G and R varies from 0 to 255
float bRanges[] = { 0, 256 };
float gRanges[] = { 0, 256 };
float rRanges[] = { 0, 256 };
const float* ranges[] = { bRanges, gRanges, rRanges };

// we compute the histogram from the 0th and 2nd channels
int channels[] = {0, 1, 2};

cv::MatND hist;
cv::calcHist(&bgr, 1, channels, cv::Mat(), hist, 2, histSize, ranges, true, false);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM