无法从灰度图像访问像素值
Unable to access pixel values from greyscale image
我正在读取大小为1600x1200的灰度图像,然后试图访问位置(1201,0)的像素值。最后我得到了段错误,如注释所示:
Mat gray_image = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE); // Read the file
if(! gray_image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
const int width = gray_image.cols;
const int height = gray_image.rows;
cout<<gray_image.cols<<endl; // 1600
cout<<gray_image.rows<<endl; // 1200
cout<<(int)gray_image.at<uchar>(1201,0)<<endl; //SEGFAULT
您已经说过您正在读取大小为1600x1200
的图像,那么您如何仅从总共1200行中访问1201
元素,实际上您误解了mat.at<>()
的约定。我建议您以这种方式使用mat.at<>(cv::Point(p_x, p_y))
,您永远不会与mat.at<>()
中传递的行和颜色混淆。
EDIT:然而,创建一个新的cv::Point
并不是@Micka建议的访问像素的推荐方式,因此将其视为一种变通方法,不要完全依赖cv::Point()
来访问像素。迭代像素的最佳方法在Opencv文档中定义。
应该是。at(row,col)而不是(col,row)并且你没有第1201行这就是为什么它是一个分段错误
相关文章:
- 访问随机图像像素的快速方法,最多一次
- OpenCV 像素访问点与 at() - 不同的值
- 如何使用 freetype2 访问单色位图中的像素状态
- 访问和更改基于另一个图像的像素颜色-opencv c++
- OpenCV 访问像素的颜色值
- 如何在OpenCV Cuda(GpuMat)中访问像素
- 使用glgetTeximage()访问像素
- 如何在opencv C++中访问特定的超像素
- OpenCV VisualStudio,C 代码错误尝试访问像素
- 从SDL_Texture访问像素颜色
- 不能通过基于指针的访问像素强度来分割 RGB 图像
- 访问 openCV 中某个图像中所有像素的 RGB 值
- 如何使用OpenCV快速访问像素值C++
- 访问图像像素;MatIterator_<> 和 Mat::at 运算符的比较
- 提高 OpenCV 中垫像素访问的性能
- 如何访问指向 QWidget 像素的指针
- 在OpenCV Android中访问相机帧像素
- 快速像素访问 opencv
- OpenCV积分图像像素访问错误
- OpenCV单个像素访问