2
我与服用浮点数据OpenCV中的直方图挣扎:如何使用OpenCV的直方图?
cv::ocl::setUseOpenCL(true);
auto rows = 2048;
auto cols = 2064;
auto input_d = cv::UMat(rows, cols, CV_32F, cv::USAGE_ALLOCATE_DEVICE_MEMORY);
cv::UMat hist_d;
cv::randn(input_d, 0, 0.5);
std::vector<int> channels = { 0 };
std::vector<int> histSize = { 256 };
std::vector<float> ranges = { 0, 1 };//run the histogram to track values 0 to 1
cv::calcHist(input_d, channels, cv::UMat(), hist_d, histSize, ranges, false);
我发现了一个错误,如:
OpenCV Error: Assertion failed (0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows) in cv::Mat::Mat, file src\matrix.cpp, line 452
任何人都知道如何使用这个功能呢?
下面的代码工作,但计算不会对GPU
auto rows = 2048;
auto cols = 2064;
auto input_d = cv::Mat(rows, cols, CV_32F);
cv::MatND hist_d;
cv::randn(input_d, 0, 0.5);
int histSize[1] = { 256 };
float hranges[2] = { 0.0, 256.0 };
const float* range[1] = { hranges };
int channels[1] = { 0 };
cv::calcHist(&input_d, 1, channels, cv::Mat(), hist_d, 1, histSize, range);
发生,我怀疑是富不应该是零号,但我不明白怎么回事。
cv::InputArray& foo = input_d;
cv::calcHist(foo, channels, cv::UMat(), hist_d, histSize, ranges, false);