我正在用C++写一个实时视频处理程序,希望能够用相同的mjpeg流在颜色,灰度和单色上切换三个窗口。我正在运行所有图像提要,但是,由于我的屏幕很小,我希望能够分别打开和关闭它们。为此,我编写了以下代码,但调用destroyWindow(“[windowname]”);而是停止整个程序。我已经阅读过文档,在文档前加空白无济于事。有人可以告诉我我在做什么错吗?
这是代码(,它处于无限循环中,直到您在下面看到的中断称为):
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/