【发布时间】:2015-02-10 03:41:54
【问题描述】:
我正在尝试在 16 位灰度 OpenCV Mat 上进行非常简单(类似 LUT)的操作,这种操作非常高效且不会减慢调试器的速度。
虽然有一个 very detailed page in the documentation 正好解决了这个问题,但它没有指出大多数这些方法仅适用于 8 位图像(包括完美的优化 LUT 功能)。
我尝试了以下方法:
uchar* p = mat_depth.data;
for (unsigned int i = 0; i < depth_width * depth_height * sizeof(unsigned short); ++i)
{
*p = ...;
*p++;
}
真的很快,可惜只支持 uchart(就像 LUT)。
int i = 0;
for (int row = 0; row < depth_height; row++)
{
for (int col = 0; col < depth_width; col++)
{
i = mat_depth.at<short>(row, col);
i = ..
mat_depth.at<short>(row, col) = i;
}
}
改编自这个答案:https://stackoverflow.com/a/27225293/518169。对我不起作用,而且速度很慢。
cv::MatIterator_<ushort> it, end;
for (it = mat_depth.begin<ushort>(), end = mat_depth.end<ushort>(); it != end; ++it)
{
*it = ...;
}
运行良好,但它使用大量 CPU 并使调试器超级慢。
这个答案https://stackoverflow.com/a/27099697/518169 指向source code of the built-in LUT function,但是它只提到了高级优化技术,如 IPP 和 OpenCL。
我正在寻找的是一个非常简单的循环,就像第一个代码一样,但是对于 ushorts。
你推荐什么方法来解决这个问题?我不是在寻找极端优化,只是在 .data 上与单循环的性能相提并论。
【问题讨论】:
标签: c++ opencv image-processing