获取二值图像的值
getting a value in binary image
我试图在二进制图像中获得一组值来反转它。但是我有麻烦索引矩阵,我的代码的第一行是。
std::string path = "img/lena.jpg";
//Our color image
cv::Mat imageMat = cv::imread(path, CV_LOAD_IMAGE_GRAYSCALE);
if(imageMat.empty())
{
std::cerr << "ERROR: Could not read image " << argv[1] << std::endl;
return 1;
}
//Grayscale matrix
cv::Mat grayscaleMat (imageMat.size(), CV_8U);
//Convert BGR to Gray
cv::cvtColor( imageMat, grayscaleMat, CV_BGR2GRAY );
//Binary image
cv::Mat binaryMat(grayscaleMat.size(), grayscaleMat.type());
//Apply thresholding
cv::threshold(grayscaleMat, binaryMat, 100, 255, cv::THRESH_BINARY);
现在我需要使用binaryMat中的值,但我不知道如何得到它…
1:使用opencv的c++ api,您不需要分配输出/结果Mat's。
//Convert BGR to Gray
cv::Mat grayscaleMat;
cv::cvtColor( imageMat, grayscaleMat, CV_BGR2GRAY );
//Apply thresholding
cv::Mat binaryMat;
cv::threshold(grayscaleMat, binaryMat, 100, 255, cv::THRESH_BINARY);
2:现在访问像素:
uchar p = binaryMat.at<uchar>(y,x); // row,col world !
binaryMat.at<uchar>(5,5) = 17;
相关文章:
- 当映射包含字符串向量作为值时,从值中获取键的有效方法
- 如何从 QString 中包含的十六进制值中获取 ASCII 字符?
- 从std::map值中获取密钥的有效方法
- 从指针访问值或获取其默认值(如果为 null)的最干净方法
- 静态断言 std::array 的大小,其类型是使用 decltype 从成员函数的返回值中获取的
- 想要从图像获取绿色 RGB 通道时出错
- 如何从QSpinBox更改的值中获取整数值
- 从共享指针的取消引用值中获取共享指针
- Winrt/XML/C++:从字符串值中获取颜色
- CImg:图像二值化结果失败
- 非单连通二值图像的周长
- 在rgb图像上应用二值阈值滤波器
- 获取二值图像的值
- OpenCV和c++;比较两个二值图像并获得输出(结果)
- Opencv将二值图像的像素值写入文件
- 绘制从二值图像中检索到的轮廓
- 二值图像的特征提取
- 二维哈尔小波变换软阈值图像去噪(c++)
- 如何修改这个python opencv程序来从阈值图像中获取xy坐标
- 如何将二值图像数据转换为栅格图像