Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB sub2ind / ind2sub in OpenCV /C++

Are there any functions in OpenCV which are equal to MATLAB's sub2ind and ind2sub functions? I need both functions for my C++ app. If OpenCV lacks of these functions, are there any C++ libs which provide equivalent functionality?

like image 429
wildcat Avatar asked Feb 11 '14 18:02

wildcat


1 Answers

You can write them yourself:

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;
}
like image 168
3 revs, 3 users 97% Avatar answered Oct 06 '22 07:10

3 revs, 3 users 97%