【发布时间】:2015-02-26 14:31:29
【问题描述】:
我正在阅读 OpenCV 2 Computer Vision Application Programming Cookbook 并在其中实施示例。
不幸的是,在第 4 章中,颜色直方图示例不起作用。
代码如下。但是这段代码没有给我直方图或任何错误。此外,它说彩色图像直方图是三维的。我不明白为什么是你而不是两个。
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\core\core.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(){
Mat image = imread("waves.jpg");
int histSize[3];
float hranges[2];
const float* ranges[3];
int channels[3];
// Prepare arguments for a color histogram
histSize[0] = histSize[1] = histSize[2] = 256;
hranges[0] = 0.0; // BRG range
hranges[1] = 255.0;
ranges[0] = hranges; // all channels have the same range
ranges[1] = hranges;
ranges[2] = hranges;
channels[0] = 0; // the three channels
channels[1] = 1;
channels[2] = 2;
Mat hist;
// Compute histogram
calcHist(&image,
1, // histogram of 1 image only
channels, // the channel used
cv::Mat(), // no mask is used
hist, // the resulting histogram
3, // it is a 3D histogram
histSize, // number of bins
ranges // pixel value range
);
cout << hist.at<int>(100, 100, 0) << endl;
cout << hist.at<int>(100, 100, 1) << endl;
cout << hist.at<int>(100, 100, 2) << endl;
return 0;
}
【问题讨论】:
标签: c++ opencv image-processing computer-vision histogram