Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.64 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Unhandled exception after reading histogram (created with calcHist)
  2. //int histSize[3];
  3. //float hranges[2];
  4. //const float* ranges[3];
  5. //int channels[3];
  6.  
  7. ColorHistogram::ColorHistogram()
  8. {
  9.     // Prepare arguments for a color histogram
  10.     histSize[0]= histSize[1]= histSize[2]= 256;
  11.     hranges[0]= 0.0; // BRG range
  12.     hranges[1]= 255.0;
  13.     ranges[0]= hranges; // all channels have the same range
  14.     ranges[1]= hranges;
  15.     ranges[2]= hranges;
  16.     channels[0]= 0; // the three channels
  17.     channels[1]= 1;
  18.     channels[2]= 2;
  19. }
  20.  
  21. cv::MatND ColorHistogram::getHistogram(const cv::Mat &image)
  22. {
  23.     cv::MatND hist;
  24.     // Compute histogram
  25.     cv::calcHist(&image,
  26.         1, // histogram of 1 image only
  27.         channels, // the channel used
  28.         cv::Mat(), // no mask is used
  29.         hist, // the resulting histogram
  30.         3, // it is a 3D histogram
  31.         histSize, // number of bins
  32.         ranges // pixel value range
  33.         );
  34.     return hist;
  35. }
  36.        
  37. cv::Mat ColorHistogram::getHistogramImage(const cv::Mat &image){
  38.     // Compute histogram first
  39.     cv::MatND hist = getHistogram(image);
  40.     // Get min and max bin values
  41.     double maxVal=0;
  42.     double minVal=0;
  43.     cv::minMaxLoc(hist, &minVal, &maxVal, 0, 0);
  44. //....
  45. }
  46.        
  47. void cv::minMaxLoc( InputArray _img, double* minVal, double* maxVal,
  48.                 Point* minLoc, Point* maxLoc, InputArray mask )
  49. {
  50.     Mat img = _img.getMat();
  51.     CV_Assert(img.dims <= 2); // <-- This is the line that is asserting for you...
  52.  
  53.     minMaxIdx(_img, minVal, maxVal, (int*)minLoc, (int*)maxLoc, mask);
  54.     if( minLoc )
  55.         std::swap(minLoc->x, minLoc->y);
  56.     if( maxLoc )
  57.         std::swap(maxLoc->x, maxLoc->y);
  58. }