由 c++ 和 opencv 生成的奇怪图像标题

Strange image title generated by c++ and opencv

本文关键字:图像 标题 c++ opencv      更新时间:2023-10-16

下面是一个非常简单的例子,使用openCV显示2D矩阵。奇怪的是,图像标题无法正确显示。请问,有什么建议吗?

#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <string>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, const char** argv )
{
    Mat M(200, 200, CV_8UC3, Scalar(0, 0, 255));
    string Something ("Some text");
    namedWindow("Hello", CV_WINDOW_AUTOSIZE);// Create a window for display.
    imshow(Something, M);
    waitKey(0);
    return 0;
}

代码中存在问题,传递给 namedWindow 的字符串是窗口的标识符(不完全是标题)。

要将图像输出到窗口,imshow需要以前创建的窗口的名称。我想你想使用你在namedWindow中定义的那个.

正确的代码是这样的:

string Something ("Some text");
namedWindow(Something, CV_WINDOW_AUTOSIZE);// Create a window for display.
imshow(Something, M);

也许这更像是你喜欢做的事情?

变量 Something 是窗口的标识符。