我想做一个从图像到RGB色彩空间的3D直方图的特征提取。我有以下python代码,我想在c++下完成:
hist = cv2.calcHist([image], [0, 1, 2], None, self.bins, [0, 256, 0, 256, 0, 256])
hist = cv2.normalize(hist)
return hist.flatten()
我做了这样的事情:
float range[] = { 0, 255 } ;
const float* histRange = { range };
int channels[] = {0};
cv::calcHist( &image, 1, channels, cv::Mat(), r_hist, 1, &sizeVector[0], &histRange);
channels[0] = 1;
cv::calcHist( &image, 1, channels, cv::Mat(), g_hist, 1, &sizeVector[0], &histRange);
channels[0] = 2;
cv::calcHist( &image, 1, channels, cv::Mat(), b_hist, 1, &sizeVector[0], &histRange);
但后来我发现它们不一样,因为在python中直方图是基于3d的计数,如何将代码转换为c++?
以下是OpenCv文档中的代码示例:
http://docs.opencv.org/doc/tutorials/imgproc/histograms/histogram_calculation/histogram_calculation.html代码这里的方法是首先分割三个通道,然后计算每个通道的直方图。
3D直方图,参考以下答案:
如何使用OpenCV在c++中访问3D直方图值?