簡體   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