Program loosing performance with window in full screen

asked 2020-08-13 06:21:46 -0600

litwi gravatar image

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?

edit retag flag offensive close merge delete

Comments

hard to say what's causing this. resampling the image to fit the window size should not take that much time... but maybe it does. try creating the window with the OPENGL flag.

crackwitz gravatar imagecrackwitz ( 2020-08-17 20:44:11 -0600 )edit

The weird thing is that the image originally has the maximum resolution of the screen, so by deffect it already has the size. The fullscreen tag is just it gets well aligned and without any borders. In any case, thanks for the answer! Can I ask, to create the window with the OPENGL flag, do I just just put OPENGL inside namedWindow?

litwi gravatar imagelitwi ( 2020-08-20 03:52:43 -0600 )edit

cv::WINDOW_OPENGL. flags can be combined by or'ing them together (bitwise 'or', not logical 'or')

crackwitz gravatar imagecrackwitz ( 2020-08-22 16:24:47 -0600 )edit