Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

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<opencv2opencv.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);

}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...