我正在编写代码以将 mask 应用于图像。 写到一半我意识到:
//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<<"\n\nFunction just called\n\n";
/*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<<"\n\nHi\n\n";
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++ - 使用 waitKey() 时无法打印像素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44548167/