Ask Your Question

Revision history [back]

Hello, the problem here is that your code was wrong, when user presses 'G' for example, if flag grayscaleOpen==true (I guest you set this value as the beginning of the program) then the first if clause is executed and grayscaleOpen will be false, which causes the second if clause executes and grayscaleOpen will be true again and the program can not destroy the window as you wish. Another problem is the calling to waitKey() function, if you call waitKey(0), your prgram will wait for a keypress event infinitely and unless you press some key, it can not display image, so you should change that statement to waitKey(10) ect. I provide you with a small code below, which is run, but I think since your program works with video, you should try with thread based approach for more efficient. if (grayscaleOpen) imshow("Grayscale", imageGrayscale);

keyPressed = waitKey(10); if(keyPressed==27) break; if (103 == keyPressed) { switch(grayscaleOpen) { case true: std::cout << "Grayscale window closed\n"; destroyWindow("Grayscale"); grayscaleOpen = false; break; case false: std::cout << "Grayscale window opened\n"; grayscaleOpen = true; } } } Hope this help.

Hello, the problem here is that your code was wrong, when user presses 'G' for example, if flag grayscaleOpen==true (I guest you set this value as the beginning of the program) then the first if clause is executed and grayscaleOpen will be false, which causes the second if clause executes and grayscaleOpen will be true again and the program can not destroy the window as you wish. Another problem is the calling to waitKey() function, if you call waitKey(0), your prgram will wait for a keypress event infinitely and unless you press some key, it can not display image, so you should change that statement to waitKey(10) ect. I provide you with a small code below, which is run, but I think since your program works with video, you should try with thread based approach for more efficient. efficient.

if (grayscaleOpen)
    imshow("Grayscale", imageGrayscale);

imageGrayscale); keyPressed = waitKey(10); if(keyPressed==27) break; if (103 == keyPressed) { switch(grayscaleOpen) { case true: std::cout << "Grayscale window closed\n"; destroyWindow("Grayscale"); grayscaleOpen = false; break; case false: std::cout << "Grayscale window opened\n"; grayscaleOpen = true; } } }

Hope this help.

Hello, the problem here is that your code was wrong, when user presses 'G' for example, if flag grayscaleOpen==true (I guest you set this value as the beginning of the program) then the first if clause is executed and grayscaleOpen will be false, which causes the second if clause executes and grayscaleOpen will be true again and the program can not destroy the window as you wish. Another problem is the calling to waitKey() function, if you call waitKey(0), your prgram will wait for a keypress event infinitely and unless you press some key, it can not display the next image, so you should change that statement to waitKey(10) ect. I provide you with a small code below, which is run, but I think since your program works with video, you should try with thread based approach for more efficient.

if (grayscaleOpen)
    imshow("Grayscale", imageGrayscale);

keyPressed = waitKey(10);
if(keyPressed==27)
    break;
if (103 == keyPressed)
{
    switch(grayscaleOpen)
    {
        case true:
            std::cout << "Grayscale window closed\n";
            destroyWindow("Grayscale");
            grayscaleOpen = false;
        break;
        case false:
            std::cout << "Grayscale window opened\n";
            grayscaleOpen = true;
        }
    }
}

Hope this help.