使用 waitKey () 时无法打印像素值
Cannot print a pixel value when using waitKey()
我正在编写一个代码来将蒙版应用于图像。在编写代码的中途,我意识到:
//applying a mask throughout the image using user defined function.
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace cv;
using namespace std;
void sharpen(Mat& src, Mat& dst)
{ cout<<"nnFunction just callednn";
/*for (int i=1; i<src.rows-1;i++)
{
for (int j=1; j<src.cols-1;j++)
{
//dst(i,j)=(-1*(src(i-1,j-1)+src(i-1,j)+src(i-1,j+1)+src(i,j-1)+src(i,j+1)+src(i+1,j-1)+src(i+1,j)+src(i+1,j+1))+8*src(i,j))/9;
}
}*/
dst=src;
imshow("src",src);
imshow("dst",dst);
//cout<<src;
}
int main()
{
Mat src,dst;
src=imread("/home/krishna/Downloads/door1.jpg", CV_LOAD_IMAGE_GRAYSCALE);
namedWindow("src",WINDOW_NORMAL);
namedWindow("dst",WINDOW_NORMAL);
cout<<"nnHinn";
cout<<(int)src.at<uchar>(155,155);
//sharpen(src,dst);
//waitKey(-1);
return 0;
}
如果我取消注释waitKey
和/或sharpen()
,则不会打印(155,155(处的像素。我尝试更改src.at<>()
的数据类型,但徒劳无功...
更改此行:
cout<<(int)src.at<uchar>(155,155);
由:
cout<<(int)src.at<uchar>(155,155)<<endl;
此std::endl
将插入换行符并刷新流。
您也可以只使用std::flush
来刷新输出流。
相关文章:
- 如何在不产生任何垃圾的情况下获得C中的像素
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 如何将CMSampleBufferRef/CIImage/UIImage转换为像素,例如uint8_t[]
- 在C++中查找像素 RGB 数据的最快方法是什么?
- 是否可以从 OpenGL 缓冲区获取原始大小的像素?
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 如何使用 sdl2 快速绘制像素网格?
- 如何在C++中进行像素操作? - Linux
- 他们如何将红外锁定像素转换为镜头前方 1m 的正常平面上的位置
- 访问随机图像像素的快速方法,最多一次
- OpenCV 像素访问点与 at() - 不同的值
- 如何使用 freetype2 访问单色位图中的像素状态
- 尝试渲染像素坐标时,简单线条渲染失败
- 计算另一个图像像素满足条件的像素值的平均值
- 使用 waitKey () 时无法打印像素值
- 打印像素值,但图像重叠.图像是其应有大小的三倍
- 打印时像素值奇怪
- 使用 OpenCV 将鼠标指针悬停在图像上时在图像上打印像素坐标