gpt4 book ai didi

c++ - destroyWindow(来自 opencv)关闭所有窗口并停止 c++ 程序

转载 作者:行者123 更新时间:2023-11-28 07:05:40 26 4
gpt4 key购买 nike

我正在用 C++ 编写实时视频处理程序,并希望能够在彩色、灰度和单色模式下切换具有相同 mjpeg 流的三个窗口。我的所有图像源都在运行,但是,由于我的屏幕很小,我希望能够单独打开和关闭它们。为此,我编写了下面的代码,但调用了 destroyWindow("[windowname]");相反,停止整个程序。我已经阅读了文档,将 void 放在它前面并没有帮助。谁能告诉我我做错了什么?这是代码(它处于无限循环中,直到您在下方看到的中断被调用):


    imshow("Color", imageColor);
imshow("Monochrome", imageMonochrome);
imshow("Grayscale", imageGrayscale);

int keyPressed = waitKey(0);
if (keyPressed > 0)
{
cout << keyPressed;
cout << "key was pressed\n";
// Press C to toggle color window
if (99 == keyPressed)
{
if (colorOpen)
{
cout << "Color window closed\n";
void destroyWindow("Color");
colorOpen = false;
}
if (!colorOpen)
{
cout << "Color window opened\n";
imshow("Color", imageColor);
colorOpen = true;
}
}

// Press M to toggle monochrome window
if (109 == keyPressed)
{
if (monochromeOpen)
{
cout << "Monochrome window closed\n";
void destroyWindow("Monochrome");
monochromeOpen = false;
}
if (!monochromeOpen)
{
cout << "Monochrome window opened\n";
imshow("Monochrome", imagebw);
monochromeOpen = true;
}
}

// Press G to toggle grayscale window
if (103 == keyPressed)
{
if (grayscaleOpen)
{
cout << "Grayscale window closed\n";
void destroyWindow("Grayscale");
grayscaleOpen = false;
}
if (!grayscaleOpen)
{
cout << "Grayscale window opened\n";
imshow("Grayscale", image);
grayscaleOpen = true;
}
}
// Break out of infinite loop when [ESC] is pressed:
if (27 == keyPressed)
{
cout << "Escape Pressed\n";
break;
}
}

最佳答案

您粘贴的代码在调用 destroyWindow 后终止(通过运行 main 的末尾)。如果这不是您想要发生的情况,请编写在调用 destroyWindow 之后执行其他操作的代码。也许你想要一个循环?

关于c++ - destroyWindow(来自 opencv)关闭所有窗口并停止 c++ 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21807826/

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