LI Ke
LI Ke

Reputation: 75

why opencv imshow() create a new window has the same name as namedWindow() does in Debug Mode?

I want to create a mat and show it in a window named "figure".

If there is nothing wrong, there should be a window named "figure", and accept any key to stop.

In Release mode, the following code works finely. but in Debug mode, the imshow() will create a new window which has the same name with the window create by nameWindow(). and only the figure created by namedWindow() accepts my input.

#include<opencv2\opencv.hpp>

const std::string winName = "figure";
int main() {
    cv::Mat m;
    cv::namedWindow(winName,cv::WINDOW_AUTOSIZE);
    m.create(300, 300, CV_32FC3);
    m.setTo(cv::Scalar(0.0f, 2.0f, 5.0f));

    cv::imshow(winName, m);
    cv::waitKey(0);

}

Upvotes: 2

Views: 3734

Answers (1)

Miki
Miki

Reputation: 41775

This problem is due to wrong linking settings.

  • In Debug, you need to link only to the debug library opencv_world331d.lib
  • In Release, you need to link only to the release library opencv_world331.lib

Upvotes: 7

Related Questions