我正在使用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 = 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 );
但是,它无法正常工作:(。我将此代码用于灰度图像,它运行正常。我不知道
什么是错误?
谢谢!
答案 0 :(得分:0)
深度的范围大于0-256(你应该假设0-10000),也许这就是失败的原因......