Mat::data empty after image operation (threshold())
Dear all,
In my code I want to
- read in an image from file
- use threshold-operation on that image
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
did you mean, that you get an all-black(all pixels==0) image after the threshold ? try a smaller value than 220.
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
ok. sorry, misunderstood you then.