-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
highgui: wayland: too high cpu usage #25501
Copy link
Copy link
Closed
Labels
Description
System Information
OpenCV version: 4.x ( 2cd3304 )
Operating System / Platform: Ubuntu 24.04
Compiler & compiler version: GCC 13.2
Detailed description
We expect that cv::waitKey(1000) requests low cpu usage.
However, with Wayland backend, user application runs with 100% cpu usage.
opencv/modules/highgui/src/window_wayland.cpp
Lines 2450 to 2458 in 12e2cc9
| auto elapsed = end_time - start_time; | |
| if (limit.count() > 0 && elapsed >= limit.count()) { | |
| break; | |
| } | |
| auto sleep_time = 64000 - elapsed; | |
| if (sleep_time > 0) { | |
| std::this_thread::sleep_for(ch::nanoseconds(sleep_time)); | |
| } |
When elapsed is larger then 64000(nanosec = 64 millisec), sleep_time will be negative.
In this case std::this_thread::sleep_for() will not be called.
So CvWlCore::getInstance().display().run_once(); is called again and again.
It makes high CPU usage.
Steps to reproduce
// g++ main.cpp -o a.out -I /usr/local/include/opencv4 -lopencv_core -lopencv_highgui -lopencv_imgcodecs
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <iostream>
#include <string>
int main(int argc, char *argv[])
{
std::cout << "cv::currentUIFramework() returns " << cv::currentUIFramework() << std::endl;
cv::Mat src;
src = cv::imread("opencv-logo.png");
cv::namedWindow("src");
int key = 0;
do
{
cv::imshow("src", src);
key = cv::waitKey(1000);
} while( key != 'q' );
return 0;
}Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)
Reactions are currently unavailable