OpenCV/C++中的MATLAB sub2ind/ind2sub

wil*_*cat 6 c++ algorithm matlab opencv image-processing

OpenCV中是否有与MATLAB sub2indind2sub函数相同的函数?我需要两个函数用于我的C++应用程序.如果OpenCV缺少这些功能,是否有任何C++库提供相同的功能?

pag*_*hdv 8

你可以自己写:

int sub2ind(const int row,const int col,const int cols,const int rows)
{
   return row*cols+col;
}

void ind2sub(const int sub,const int cols,const int rows,int &row,int &col)
{
   row=sub/cols;
   col=sub%cols;
}
Run Code Online (Sandbox Code Playgroud)