gpt4 book ai didi

c++ - 如何使用OpenCV的直方图?

转载 作者:搜寻专家 更新时间:2023-10-31 02:20:15 25 4
gpt4 key购买 nike

我正在努力在 OpenCV 中获取 float 据的直方图:

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);

我怀疑 foo 的大小不应该为零,但我不明白这是怎么回事。

cv::InputArray& foo = input_d;
cv::calcHist(foo, channels, cv::UMat(), hist_d, histSize, ranges, false);

最佳答案

看起来它需要包装。

std::vector<cv::UMat> foo = { input_d };// should ref count, and avoid a deep copy?
cv::calcHist(foo, channels, cv::UMat(), hist_d, histSize, ranges, false);

关于c++ - 如何使用OpenCV的直方图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32929735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com