ATG
ATG

Reputation: 752

How to get the row and col of a particular element in OpenCV?

I am trying to get the row and col of a particular element from a CvMat which is a 3-channel matrix.

Is there any function in OpenCV with which I can get this? Something like Matlab's 'find' function, maybe?

Upvotes: 0

Views: 329

Answers (3)

Barney Szabolcs
Barney Szabolcs

Reputation: 12514

If that "particular element" is a color pixel and it is unique, you can mask it using

inRange(src,your_color,your_color,mask)

then use minMaxLoc() to get the index of that unique point you are looking for.

Of course this is only worth it if you are not after a single pixel (get the single pixel rather with a simple loop), but if you don't do too many of this it could be easier to do this overkill, as it is short, afterall.

If you are looking for a submatrix, use matchTemplate then minMaxLoc to get the index.

Upvotes: 1

andrea
andrea

Reputation: 1358

I never heard about such function in Opencv. still you can scan your matrix looking for the value you need to find. I think also "find" function works in a similar way.

Upvotes: 0

kyon
kyon

Reputation: 73

if you use cpp,it's OK to write like this:

Mat readmat = imread("pic", 0);
cols = readmat.cols;
rows = readmat.rows;

BTW,you can refer here

Upvotes: 0

Related Questions