I have a problem in OpenCV C++. I read in an image from file and use the threshold-function to get a binary image. After that I want to access the pixel values of the thresholded image.
PROBLEM: The Mat::data array of the thresholded image is 0.
I use threshold(src, img, 220, 255, CV_THRESH_BINARY); with src and img beig cv::Mat.
After that call in the img::data = " "
Here is my code:
// 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++;
}
}
I think the problem might be about cv::Mat with referencing and copying Mat::data:
Thanks for your help!
NULL
? Are all the values zero? Also, what is the problem you're trying to solve? I'm confident there is a better solution than using nested loops. – Aurelius