“转换”OpenCV cv::Mat
的有效方法是什么?
对于 shift 我的意思是如果我有这样一行
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
然后我将它移动 3 个位置,我会得到这样的一行
3, 4, 5, 6, 7, 8, 9, 0, 1, 2
现在我正在使用这个功能:
void shift( const cv::Mat& in, cv::Mat& out, int shift )
{
if ( shift < 0 || shift > in.cols ) return;
if ( shift == 0 || shift==in.cols ) {
out = in.clone();
} else {
cv::hconcat(in(cv::Rect(shift,0,in.cols-shift,in.rows)),in(cv::Rect(0,0,shift,in.rows)),out);
}
}
但我正在寻找一种更有效的方法。
最佳答案
如果你的数组的大小不是很大并且 rows=1 那么你可以像这样重复你的数组 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9 然后移动它移动数组的数据指针
关于c++ - 使用 OpenCV 移动 cv::Mat 的高效 C++ 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28328754/