c++ - 使用 waitKey() 时无法打印像素值

标签 c++ opencv

我正在编写代码以将 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/

相关文章:

python-2.7 - 从目录中读取图像并用空格分隔 python 传递每个图像

python - 迭代图像并在给定的色调范围内选择亮度/饱和度值,而不是使用嵌套的 for 循环

opencv - qt.qpa.xcb : could not connect to displayerror while using OpenCV on ec2 ubuntu server 20. 0

android - 如何修复 FeatureDetector.detect (OpenCV-2.4.11 Android) 中的段错误 (SIGSEGV)?

c++ - 查找 Microsoft Edge 版本(通过 WinApi)

c++ - WSN 中的 NS3 移动模型

c++ - PkgConfig 模块 : INCLUDE_DIRS not listing all directories

c++ - 使用委托(delegate)调用 C++ 函数时 VS2015 应用程序崩溃

c - 从文件夹加载图像(使用 C、OpenCV、Visual Studio 2008)

c++ - 多重继承中的内存布局