Ask Your Question

Revision history [back]

Mat::data empty after image operation (threshold())

Dear all,

In my code I want to

  1. read in an image from file
  2. use threshold-operation on that image
  3. access the data from thresholded image, in order to read the pixel values

    `// read image source
    Mat src = imread("image.png", CV_LOAD_IMAGE_COLOR); if(src.empty()) {
    return -1; }

    cvtColor(src,src,CV_RGB2GRAY);

    threshold(src, src, 220, 255, CV_THRESH_BINARY );

    int line[1200];
    

    int lineCount = 0;

    for(int i=src.rows; i>src.rows/2; i-=10)
    { uchar* rowi = src.ptr(i-1);

    int columnCount = 0;
    // begin on the left of the image
    for(int j=0; j<src.cols; j++)
    {
        uchar grayscale = src.at<uchar>(rowi[j]);   
    
        // write data to array
        line[columnCount] = grayscale;
    
        columnCount++;
    }`
    

My Problem: After using the threshold-operation on the image the src::date is " ". What can I do to fix that?

Thanks, Cima

click to hide/show revision 2
retagged

updated 2014-05-27 11:23:03 -0600

berak gravatar image

Mat::data empty after image operation (threshold())

Dear all,

In my code I want to

  1. read in an image from file
  2. use threshold-operation on that image
  3. access the data from thresholded image, in order to read the pixel values

    `// read image source
    Mat src = imread("image.png", CV_LOAD_IMAGE_COLOR); if(src.empty()) {
    return -1; }

    cvtColor(src,src,CV_RGB2GRAY);

    threshold(src, src, 220, 255, CV_THRESH_BINARY );

    int line[1200];
    

    int lineCount = 0;

    for(int i=src.rows; i>src.rows/2; i-=10)
    { uchar* rowi = src.ptr(i-1);

    int columnCount = 0;
    // begin on the left of the image
    for(int j=0; j<src.cols; j++)
    {
        uchar grayscale = src.at<uchar>(rowi[j]);   
    
        // write data to array
        line[columnCount] = grayscale;
    
        columnCount++;
    }`
    

My Problem: After using the threshold-operation on the image the src::date is " ". What can I do to fix that?

Thanks, Cima