您的位置:首页 > 运维架构

opencv 通过指针访问图像像素值,输出为空的问题

2016-04-18 10:27 387 查看
for (int i = 0; i < img_roi_gray_at.rows; ++i)
{
uchar* datatemp = img_roi_gray_at.ptr<uchar>(i);
for (int j = 0; j < img_roi_gray_at.cols; ++j)
{
//cout << (int)datatemp[j] << endl;
cout << datatemp[j] << endl;
}
}


如代码所示,此时输出为空,按道理说应该输出具体的像素值才对

下面的代码是经过大神修改后的,问题出在输出的时候把像素值当成字符型来输出了,因此需进行类型转换,转换成int型输出,即可得到正确结果。

for (int i = 0; i < img_roi_gray_at.rows; ++i)
{
uchar* datatemp = img_roi_gray_at.ptr<uchar>(i);
for (int j = 0; j < img_roi_gray_at.cols; ++j)
{
cout << (int)datatemp[j] << endl;
//cout << datatemp[j] << endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: