Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The fastest way to access all Mat elements is:

Size contSize = mat.size();
if (mat.isContinous())
{
    contSize.width *= contSize.height;
    contSize.height = 1;
}
for (int i = 0; i < contSize.height; ++i)
{
    T* ptr = mat.ptr<T>(y);
    for (int j = 0; j < contSize.width; ++j)
    {
        ptr[j] = ...;
    }
}