What is meant by img.at<uchar>(i,j)?

Haris_tech picture Haris_tech · Mar 19, 2013 · Viewed 8.9k times · Source

Its kind a basic question. I don't know what this structure.

img.at<uchar>(i,j) 

is meant to be? I try to find the definition of at, but can't understand it. and what this syntax means?

<uchar> 

Similarly, what is meant by

img.at<cv::Vec3b>(row,col)[channel] 

Yes, Mat is matrix class to manipulate matrix data. I understand the behavior of those above lines but can't understand theory behind them?

What does this syntax mean?

img.at<cv::Vec3b>

Answer

sgarizvi picture sgarizvi · Mar 19, 2013

at is an overloaded C++ template function of the class cv::Mat.

The < > is the syntax for invoking a C++ template.

img.at<uchar>(i,j) 

The above line means, we are accessing the pixel (i,j) and specifying its data type to be unsigned char.

In simple English, fetch 1 pixel from index (i, j) i.e. row number i and column number j.

img.at<cv::Vec3b>

The above is used for a 3 channel image. Same as the first one, but fetching the pixel values of all the three channels. The value returned is a Vec3b structure containing 3 values, one for each channel.