【发布时间】:2014-05-27 18:57:38
【问题描述】:
我在 OpenCV C++ 中有一个问题。 我从文件中读取图像并使用阈值函数来获取二进制图像。 之后我想访问阈值图像的像素值。
问题: 阈值图像的 Mat::data 数组为 0。
我用 阈值(src、img、220、255、CV_THRESH_BINARY); 带有 src 和 img beig cv::Mat。
在 img::data = " " 中调用之后
这是我的代码:
// 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++;
}
}
我认为问题可能是关于 cv::Mat 引用和复制 Mat::data:
感谢您的帮助!
【问题讨论】:
-
目前还不清楚您的问题到底是什么。 Mat::data 数组 ... 为 0 是什么意思?是指针
NULL?所有的值都为零吗?另外,您要解决的问题是什么?我相信有比使用嵌套循环更好的解决方案。
标签: c++ image opencv computer-vision mat