0

我正在处理来自 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 );

但是,它不起作用:(。我将此代码用于灰度图像,它工作正常。我不知道

什么是错误?

谢谢!

4

1 回答 1

0

深度的范围大于0-256(您应该假设0-10000),也许这就是失败的原因......

于 2013-08-22T13:24:03.797 回答