Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

calcHist Exception, CvtHelper:Invalid number of channels , when dims = 3 (n-dimensional histogram)

Hi all, I would like to generate a 3-dimensional HSV Histogram. It works for 2-D HS Histogram but fails to generate Histogram for 3-dimension. Can someone help me understand what I am doing wrong?

  cv::cvtColor(matImage, matImageHSV, CV_BGR2HSV);

  // Quanta Ratio
  int scale = 10;

  // Quantize the hue to 36 levels
  // and the saturation to 25 levels
  int hbins = 36, sbins = 25,  vbins = 25;
  int histSize[] = {hbins, sbins, vbins};

  // hue varies from 0 to 179, see cvtColor
  float hranges[] = { 0, 180 };

  // saturation varies from 0 (black-gray-white) to
  // 255 (pure spectrum color)
  float sranges[] = { 0, 256 };
  float vranges[] = { 0, 256 };

  const float* ranges[] = { hranges, sranges, vranges };

  // we compute the histogram from the 0-th and 1-st channels
  int channels[] = {0, 1, 2};

  int dims = 3;

  int nImages = 1;

  // Calculate histogram
  cv::MatND hist;

  cv::calcHist(&matImageHSV, nImages, channels, cv::Mat(), // do not use mask
           hist, dims, histSize, ranges,
           true, // the histogram is uniform
           false );

Following exception is thrown.

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.5) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/imgproc/src/color.hpp:255: error: (-2:Unspecified error) in function 'cv::CvtHelper<cv::set&lt;3, -1,="" -1="">, cv::Set<3, 4, -1>, cv::Set<0, 5, -1>, cv::NONE>::CvtHelper(cv::InputArray, cv::OutputArray, int) [VScn = cv::Set<3, -1, -1>, VDcn = cv::Set<3, 4, -1>, VDepth = cv::Set<0, 5, -1>, sizePolicy = cv::NONE]'

Invalid number of channels in input image: 'VScn::contains(scn)' where 'scn' is 1

calcHist Exception, CvtHelper:Invalid number of channels , when dims = 3 (n-dimensional histogram)

Hi all, I would like to generate a 3-dimensional HSV Histogram. It works for 2-D HS Histogram but fails to generate Histogram for 3-dimension. Can someone help me understand what I am doing wrong?

  cv::cvtColor(matImage, matImageHSV, CV_BGR2HSV);

  // Quanta Ratio
  int scale = 10;

  // Quantize the hue to 36 levels
  // and the saturation to 25 levels
  int hbins = 36, sbins = 25,  vbins = 25;
  int histSize[] = {hbins, sbins, vbins};

  // hue varies from 0 to 179, see cvtColor
  float hranges[] = { 0, 180 };

  // saturation varies from 0 (black-gray-white) to
  // 255 (pure spectrum color)
  float sranges[] = { 0, 256 };
  float vranges[] = { 0, 256 };

  const float* ranges[] = { hranges, sranges, vranges };

  // we compute the histogram from the 0-th and 1-st channels
  int channels[] = {0, 1, 2};

  int dims = 3;

  int nImages = 1;

  // Calculate histogram
  cv::MatND hist;

  cv::calcHist(&matImageHSV, nImages, channels, cv::Mat(), // do not use mask
           hist, dims, histSize, ranges,
           true, // the histogram is uniform
           false );

Following exception is thrown.

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.5) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/imgproc/src/color.hpp:255: error: (-2:Unspecified error) in function 'cv::CvtHelper<cv::set&lt;3, -1,="" -1="">, cv::Set<3, 4, -1>, cv::Set<0, 5, -1>, cv::NONE>::CvtHelper(cv::InputArray, cv::OutputArray, int) [VScn = cv::Set<3, -1, -1>, VDcn = cv::Set<3, 4, -1>, VDepth = cv::Set<0, 5, -1>, sizePolicy = cv::NONE]'

Invalid number of channels in input image: 'VScn::contains(scn)' where 'scn' is 1

calcHist Exception, CvtHelper:Invalid number of channels , invalid Mat when dims = 3 (n-dimensional histogram)

Hi all, I would like to generate a 3-dimensional HSV Histogram. It works for 2-D HS Histogram but fails to generate Histogram for 3-dimension. Can someone help me understand what I am doing wrong?

  cv::cvtColor(matImage, matImageHSV, CV_BGR2HSV);

  // Quanta Ratio
  int scale = 10;

  // Quantize the hue to 36 levels
  // and the saturation to 25 levels
  int hbins = 36, sbins = 25,  vbins = 25;
  int histSize[] = {hbins, sbins, vbins};

  // hue varies from 0 to 179, see cvtColor
  float hranges[] = { 0, 180 };

  // saturation varies from 0 (black-gray-white) to
  // 255 (pure spectrum color)
  float sranges[] = { 0, 256 };
  float vranges[] = { 0, 256 };

  const float* ranges[] = { hranges, sranges, vranges };

  // we compute the histogram from the 0-th and 1-st channels
  int channels[] = {0, 1, 2};

  int dims = 3;

  int nImages = 1;

  // Calculate histogram
  cv::MatND hist;

  cv::calcHist(&matImageHSV, nImages, channels, cv::Mat(), // do not use mask
           hist, dims, histSize, ranges,
           true, // the histogram is uniform
           false );

Following There is no exception or error is thrown.

libc++abi.dylib: terminating But the output hist matrix is invalid with uncaught exception of type cv::Exception: OpenCV(3.4.5) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/imgproc/src/color.hpp:255: error: (-2:Unspecified error) in function 'cv::CvtHelper<cv::set&lt;3, -1,="" -1="">, cv::Set<3, 4, -1>, cv::Set<0, 5, -1>, cv::NONE>::CvtHelper(cv::InputArray, cv::OutputArray, int) [VScn = cv::Set<3, -1, -1>, VDcn = cv::Set<3, 4, -1>, VDepth = cv::Set<0, 5, -1>, sizePolicy = cv::NONE]'values (rows, cols) as (-1, -1).

Invalid number of channels in input image: 'VScn::contains(scn)' where 'scn' is 1