1 | initial version |
The 'efficient' way of scanning an image is to iterate over rows, as described here:
void ScanImageAndDoYourStuff(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; // assuming channels==1 in binary image;
int i,j;
uchar* p;
for( i = 0; i < nRows; ++i)
{
p = I.ptr<uchar>(i);
for ( j = 0; j < nCols; ++j)
{
// do your stuff
}
}
}
If you need to scan columns, just transpose your image (effcient way of rotating) and then your columns will become rows. Does it make sense?
PS. As described in the document mentioned above, using .at<t>(u,v) is not efficient -especially for scanning whole image.
2 | No.2 Revision |
The 'efficient' way of scanning an image is to iterate over rows, as described here:
void ScanImageAndDoYourStuff(Mat& I, const uchar* const table)
{
// accept only char type matrices
CV_Assert(I.depth() CV_Assert(I.type() == CV_8U);
CV_8UC1);
int channels = I.channels();
int nRows = I.rows;
int nCols = I.cols; // assuming channels==1 in binary image;
int i,j;
uchar* p;
for( i = 0; i < nRows; ++i)
{
p = I.ptr<uchar>(i);
for ( j = 0; j < nCols; ++j)
{
// do your stuff
}
}
}
If you need to scan columns, just transpose your image (effcient way of rotating) and then your columns will become rows. Does it make sense?
PS. As described in the document mentioned above, using .at<t>(u,v) is not efficient -especially for scanning whole image.
3 | No.3 Revision |
The 'efficient' way of scanning an image is to iterate over rows, as described here:
void ScanImageAndDoYourStuff(Mat& I, const uchar* const table)
{
// accept only 1-channel char type matrices
CV_Assert(I.type() == CV_8UC1);
int channels = I.channels();
int nRows = I.rows;
int nCols = I.cols; // assuming channels==1 in binary image;
I.cols;
int i,j;
uchar* p;
for( i = 0; i < nRows; ++i)
{
p = I.ptr<uchar>(i);
for ( j = 0; j < nCols; ++j)
{
// do your stuff
// p[j] is now same as I.at<uchar>(i,j), but accessing it sequentially is muuuuch faster
}
}
}
If you need to scan columns, just transpose your image (effcient way of rotating) and then your columns will become rows. Does it make sense?
PS. As described in the document mentioned above, using .at<t>(u,v) cv::Mat::at<T>(u,v)
is not efficient -especially for scanning whole image.
4 | No.4 Revision |
The 'efficient' way of scanning an image is to iterate over rows, as described here:
void ScanImageAndDoYourStuff(Mat& I, const uchar* const table)
I)
{
// accept only 1-channel char type matrices
CV_Assert(I.type() == CV_8UC1);
int channels = I.channels();
int nRows = I.rows;
int nCols = I.cols;
int i,j;
uchar* p;
for( i = 0; i < nRows; ++i)
{
p = I.ptr<uchar>(i);
for ( j = 0; j < nCols; ++j)
{
// do your stuff
// p[j] is now same as I.at<uchar>(i,j), but accessing it sequentially is muuuuch faster
}
}
}
If you need to scan columns, just transpose your image (effcient way of rotating) and then your columns will become rows. Does it make sense?
PS. As described in the document mentioned above, using cv::Mat::at<T>(u,v)
is not efficient -especially for scanning whole image.
5 | No.5 Revision |
The 'efficient' way of scanning an image is to iterate over rows, as described here:
void ScanImageAndDoYourStuff(Mat& I)
{
// accept only 1-channel char type matrices
CV_Assert(I.type() == CV_8UC1);
int channels = I.channels();
int nRows = I.rows;
int nCols = I.cols;
int i,j;
uchar* p;
for( i = 0; i < nRows; ++i)
{
p = I.ptr<uchar>(i);
for ( j = 0; j < nCols; ++j)
{
// do your stuff
// p[j] is now same as I.at<uchar>(i,j), but accessing it sequentially is muuuuch faster
}
}
}
If you need to scan columns, just transpose your image (effcient way of rotating) and then your columns will become rows. Does it make sense?
PS. As described in the document mentioned above, using cv::Mat::at<T>(u,v)
is not efficient -especially for scanning whole image.
6 | No.6 Revision |
The 'efficient' way of scanning an image is to iterate over rows, as described here:
void ScanImageAndDoYourStuff(Mat& I)
{
// accept only 1-channel char type matrices
CV_Assert(I.type() == CV_8UC1);
int nRows = I.rows;
int nCols = I.cols;
int i,j;
uchar* p;
for( i = 0; i < nRows; ++i)
i+=10)
{
p = I.ptr<uchar>(i);
for ( j = 0; j < nCols; ++j)
{
// do your stuff
stuff, eg.
if (p[j]==0) cout << "0 binary=" << endl;
else cout << "1 binary=" << endl;
// p[j] is now same as I.at<uchar>(i,j), but accessing it sequentially is muuuuch faster
}
}
}
If you need to scan columns, just transpose your image (effcient way of rotating) and then your columns will become rows. Does it make sense?
PS. As described in the document mentioned above, using cv::Mat::at<T>(u,v)
is not efficient -especially for scanning whole image.
7 | No.7 Revision |
The 'efficient' way of scanning an image is to iterate over rows, as described here:
void ScanImageAndDoYourStuff(Mat& I)
{
// accept only 1-channel char type matrices
CV_Assert(I.type() == CV_8UC1);
int nRows = I.rows;
int nCols = I.cols;
int i,j;
uchar* p;
for( i = 0; i < nRows; i+=10)
{
p = I.ptr<uchar>(i);
for ( j = 0; j < nCols; ++j)
{
// do your stuff, eg.
if (p[j]==0) cout << "0 binary=" << endl;
else cout << "1 binary=" << endl;
// p[j] is now same as I.at<uchar>(i,j), but accessing it sequentially is muuuuch faster
}
}
}
If you need to scan columns, just transpose ([cv::transpose](http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#transpose)
) your image (effcient way of rotating) rotating in your case) and then your columns will become rows. Does it make sense?
PS. As described in the document mentioned above, using cv::Mat::at<T>(u,v)
is not efficient -especially for scanning whole image.
8 | No.8 Revision |
The 'efficient' way of scanning an image is to iterate over rows, as described here:
void ScanImageAndDoYourStuff(Mat& I)
{
// accept only 1-channel char type matrices
CV_Assert(I.type() == CV_8UC1);
int nRows = I.rows;
int nCols = I.cols;
int i,j;
uchar* p;
for( i = 0; i < nRows; i+=10)
{
p = I.ptr<uchar>(i);
for ( j = 0; j < nCols; ++j)
{
// do your stuff, eg.
if (p[j]==0) cout << "0 binary=" << endl;
else cout << "1 binary=" << endl;
// p[j] is now same as I.at<uchar>(i,j), but accessing it sequentially is muuuuch faster
}
}
}
If you need to scan columns, just transpose (
) your image (effcient way of rotating in your case) and then your columns will become rows. Does it make sense?[cv::transpose](http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#transpose)cv::transpose
PS. As described in the document mentioned above, using cv::Mat::at<T>(u,v)
is not efficient -especially for scanning whole image.