Attention! This forum will be made read-only by Dec-20. Please migrate to https://forum.opencv.org. Most of existing active users should've received invitation by e-mail.
Ask Your Question

Revision history [back]

The simple way is:

for (int row=0;row<image.height;row++) 
{ 
    unsigned char data = image.ptr(row); 
    for (int col=0;col<image.width;col++) 
    { 
          // then use *data for the pixel value
          if(image.at<uchar>(i,j) != 0)//do what you want; 
    } 
}

that pixel access isn't the fastest,,, if you need more speed:

for (int row=0;row<image.height;row++) 
{ 
    unsigned char data = image.ptr(row); 
    for (int col=0;col<image.width;col++) 
    { 
          // then use *data for the pixel value
          if(*data==1)//do what you want; 
          data++;
    } 
}

The simple way is:

for (int row=0;row<image.height;row++) 
{ 
    unsigned char data = image.ptr(row); 
    for (int col=0;col<image.width;col++) 
    { 
          // then use *data for the pixel value
{
          if(image.at<uchar>(i,j) != 0)//do what you want; 
    } 
}

that pixel access isn't the fastest,,, if you need more speed:

for (int row=0;row<image.height;row++) 
{ 
    unsigned char data = image.ptr(row); 
    for (int col=0;col<image.width;col++) 
    { 
          // then use *data for the pixel value
          if(*data==1)//do what you want; 
          data++;
    } 
}

The simple way is:

for (int row=0;row<image.height;row++) 
{ 
    unsigned char data = image.ptr(row); 
    for (int col=0;col<image.width;col++) 
    {
          if(image.at<uchar>(i,j) != 0)//do what you want; 
    } 
}

that pixel access isn't the fastest,,, if you need more speed:

for (int row=0;row<image.height;row++) 
{ 
    unsigned char data = image.ptr(row); 
    for (int col=0;col<image.width;col++) 
    { 
          // then use *data for the pixel value
          if(*data==1)//do what you want; 
          data++;
    } 
}