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

asked 2014-05-27 11:13:11 -0600

Cima gravatar image

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

berak gravatar image

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

edit retag flag offensive close merge delete

Comments

did you mean, that you get an all-black(all pixels==0) image after the threshold ? try a smaller value than 220.

berak gravatar imageberak ( 2014-05-27 11:22:36 -0600 )edit

No I am sure there are values above 220 ( I am able to display the thresholded image with imshow()). Simply the data-array of the new mat is 0 (it has no values, but mat.empty() is NOT true).

I think it could be something with referencing and copying mat::data

Cima gravatar imageCima ( 2014-05-27 12:18:45 -0600 )edit

ok. sorry, misunderstood you then.

berak gravatar imageberak ( 2014-05-27 12:23:08 -0600 )edit