C++ 绘制深度图像的直方图?
我正在使用kinect的深度图像。我想计算深度图像的直方图,a/f:C++ 绘制深度图像的直方图?,c++,visual-c++,opencv,kinect,openni,C++,Visual C++,Opencv,Kinect,Openni,我正在使用kinect的深度图像。我想计算深度图像的直方图,a/f: Mat depth; //(take from kinect sdk) int histSize = 64; // Set the ranges ( for B,G,R) ) float range[] = { 0, 256 } ; const float* histRange = { range }; bool uniform = true; bool accumulate =
Mat depth; //(take from kinect sdk)
int histSize = 64;
// Set the ranges ( for B,G,R) )
float range[] = { 0, 256 } ;
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat depth_hist;
// Compute the histograms:
calcHist( &depth, 1, 0, Mat(), depth_hist, 1, &histSize, &histRange, uniform, accumulate );
// Draw the histograms for depth
int hist_w = 320; int hist_h = 240;
int bin_w = cvRound( (double) hist_w/histSize );
Mat histImage( hist_h, hist_w, CV_8UC1, 1 );
// Normalize the result to [ 0, histImage.rows ]
normalize(depth_hist, depth_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
// Draw for each channel
for( int i = 1; i < histSize; i++ )
{
line( histImage, Point( bin_w*(i-1), hist_h - cvRound(depth_hist.at<float>(i-1)) ) ,
Point( bin_w*(i), hist_h - cvRound(depth_hist.at<float>(i)) ),
Scalar( 255), 2, 8, 0 );
}
// Display
namedWindow("calcHist Demo", WINDOW_AUTOSIZE );
imshow("calcHist Demo", histImage );
Mat深度//(摘自kinect sdk)
int histSize=64;
//设置范围(对于B、G、R))
浮动范围[]={0,256};
常量浮点*histRange={range};
布尔一致=真;布尔累积=假;
铺层深度;
//计算直方图:
calcHist(&depth,1,0,Mat(),depth_hist,1,&histSize,&histRange,uniform,累加);
//绘制深度直方图
int hist_w=320;int hist_h=240;
int bin_w=cvRound((双)hist_w/histSize);
Mat histImage(hist_h、hist_w、CV_8UC1、1);
//将结果规格化为[0,histImage.rows]
规格化(深度历史,深度历史,0,histImage.rows,NORM\u MINMAX,-1,Mat());
//为每个通道绘制
对于(int i=1;i
但是,它不起作用:(.我把这段代码用于灰度图像,它工作得很好。我不知道
什么是错误
谢谢!深度的范围大于0-256(你应该假设为0-10000),也许这就是失败的原因…到底什么不起作用。你得到了什么,你期望得到什么。另外,请发布任何与你如何获得深度图像相关的代码,如果对其进行了任何处理,请发布任何代码。