Strange image name generated by C ++ and opencv

Below is a very simple example of using openCV to display a 2D matrix. Oddly enough, the title of the image cannot be displayed correctly. Any suggestion please?

#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;
}

      

+3


source to share


1 answer


There is a problem in your code, the string passed to namedWindow is the window id (not exactly the title).

To display an image in a window imshow

, the name of a previously created window is required. And I think you want to use the one you defined in namedWindow

.

The correct code would be something like this:



string Something ("Some text");

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

      

Perhaps this is more than what you like?

The variable Something is the window identifier.

0


source







All Articles