I'm trying to calculate the histogram of a matrix composed by only one row. I wrote this code in VS2015:
//Create matrix stromal pop
cv::Mat stromalHistogram(1, i_stromalIID.size(), CV_64F);
double * ref_ptr = stromalHistogram.ptr<double>(0);
std::copy(i_stromalIID.begin(), i_stromalIID.end(), stdext::checked_array_iterator<double *>(ref_ptr, stromalHistogram.cols));
#ifdef _DEBUG
std::cout << "Matrix =" << std::endl << stromalHistogram << std::endl;
#endif
// calculate histogram for stromal pop
auto itRangesRef = std::minmax_element(i_stromalIID.begin(), i_stromalIID.end());
float stromalRanges[] = {*itRangesRef.first, *itRangesRef.second};
const float * rangesRef[] = { stromalRanges };
const int channel = 0;
const int histSize = 256;
std::vector<double> hist_out;
cv::calcHist(&stromalHistogram, 1, &channel, cv::Mat(), hist_out, 1, &histSize, rangesRef);
i_stromalIID
is a std::vector<double>
passed from the extern. The cv::Mat stromalHistogram
is filled correctly because when I print it, everything is as I expected (1 row, 1204 columns). But when the program runs the cv::calcHist
, I receive the following error:
OpenCV Error: Assertion failed (d == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0)) in cv::_OutputArray::create, file D:\Development\lib\OpenCV3.1\opencv-master\modules\core\src\matrix.cpp, line 2363
What am I doing wrong? Any help is appreciated! Thanks!