Ask Your Question

Revision history [back]

Program loosing performance with window in full screen

Hello,

I am creating a program where I read a video and display it in my second monitor. The relevant part of the code is as follows:

void MainScreen::DisplayVideo()
{
cv::Mat frame;
// open input video
cv::VideoCapture inVideo("video.avi");

//Open a window and set it in fullscreen size
cv::namedWindow("Screen", cv::WINDOW_NORMAL);
cv::setWindowProperty("Screen", cv::WND_PROP_FULLSCREEN, cv::WINDOW_FULLSCREEN);

//Display the first image and wait for a key to start
inVideo.read(frame);
cv::imshow("Screen", frame);

if (cv::waitKey(0))
{
    timeBeginPeriod(1);

    while (inVideo.read(frame))
    {
        if (frame.empty()) { break; }

        cv::imshow("Screen", frame);

        cv::waitKey(1);
    }
    timeEndPeriod(1);
}
inVideo.release();
}

If I show the video without the fullscreen method, the program displays the video at around 30-45 fps depending on the encoder used to create the video. However, when I put it in fullscreen, the computer then it drops in fps (in debug it drops down to 9 fps, in release the drop is lower but still noticeable). The only thing I change is the line of code from

cv::namedWindow("Screen", cv::WINDOW_AUTOSIZE); to cv::namedWindow("Screen", cv::WINDOW_NORMAL);

Looking at the task manager, I can see that when it is not in fullscreen mode, the program uses all the CPU available until reaching 100%, however, in fullscreen mode it only uses remaining resources to leave it up to 60% usage. The disk usage during this remains relatively low, never near 100%.

I am using visual studio 2019 and opencv 4.1.1 with c++ on Windows 10 64 bit. This happened both in debug and release modes.

Anyone knows why this could be?