gpt4 book ai didi

qt - 我需要做什么才能将 cout 与 opencv 一起使用?

转载 作者:太空宇宙 更新时间:2023-11-03 21:53:50 25 4
gpt4 key购买 nike

我在 QT Creator 中使用 OpenCV 2.4.8,我试图在控制台中打印一些输出,但控制台仍然是空的。

这是一个简约的代码示例:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

int main(){
std::cout << "File not found" << std::endl;
cv::waitKey(5000);

return 1;
}

当我省略 cv::waitKey(5000) 行时,一切正常并且打印了文本。这段代码有什么问题?

编辑:我将代码更改为:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

int main(){
cv::Mat image;
std::cout << "File not found" << std::endl;

return 1;
}

控制台打开并显示类似“按 Return 关闭控制台”的内容。当我删除行 cv::Mat 图像时,一切正常。控制台打开并显示“找不到文件”,并在下一行显示“按回车键关闭控制台”。当我使用 OpenCV 代码时,cout 不起作用。没有 OpenCV 代码一切正常。

EDIT2:现在我插入了一个 std::cin.get();在 std::cout 行之后一切正常。我不知道有什么问题。但这对我来说没问题。

最佳答案

例如,您是否尝试刷新 cout

std::cout << "File not found" << std::endl;
std::cout << std::flush;

关于qt - 我需要做什么才能将 cout 与 opencv 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25135551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com