Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

asked 2017-03-28 04:27:00 -0600

Nbb gravatar image

efficient access of matrices

I know I can access matrices in 2 ways, http://docs.opencv.org/2.4/doc/tutorials/core/how_to_scan_images/how_to_scan_images.html

Either using Mat.at<uchar>(row,col) or using the method below. My question is, if I am using Visual Studio and am targetting real-time applications. Will there be a difference between the two methods ? Visual Studio has a release build so I am not sure if accessing matrices becomes a lot more optimized.

Mat& ScanImageAndReduceC(Mat& I, const uchar* const table)
{
// accept only char type matrices
CV_Assert(I.depth() == CV_8U);

int channels = I.channels();

int nRows = I.rows;
int nCols = I.cols * channels;

if (I.isContinuous())
{
    nCols *= nRows;
    nRows = 1;
}

int i,j;
uchar* p;
for( i = 0; i < nRows; ++i)
{
    p = I.ptr<uchar>(i);
    for ( j = 0; j < nCols; ++j)
    {
        p[j] = table[p[j]];
    }
}
return I;

}