Ask Your Question

How can I use the GPU with Qt? (non-nvidia)

asked 2015-09-26 13:44:14 -0600

misty marshes gravatar image

updated 2015-09-27 13:38:46 -0600

Hello everyone, this is my first time with OpenCV. I am sorry I couldn't formulate my question better, I have been searching the Internet and the tags on OpenCV Answers but I couldn't solve my problem.

I've been programming a simple video player with OpenCV and Qt, but I have noticed it raises CPU usage too much. I looked for ways of using the GPU instead and found that imshow already supports OpenGL for image output but, as I need to use Qt for the UI, this is of no use to me.

How can I read a frame from a video file, process it with OpenCV and display it in Qt using the GPU instead of the CPU?

edit retag flag offensive close merge delete


This is rather a Qt related issue than an OpenCV related issue, so I guess you will get more help on a Qt specific forum with this. That being said, I will leave it open due to the answer of @kbarna.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-02 03:40:12 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-10-02 03:24:20 -0600

kbarna gravatar image

Qt works well with OpenGL. Did you try QGLWidget or QOpenGLWidget?

IIRC the QOpenGLWidget is a low-level class that gives you direct access to the OpenGL routines, while QGLWidget is higher level that can use Qt functions for drawing (still with hardware acceleration).

Here is an example:

To display an OpenCV Mat in Qt, you have to convert it to QImage (BGR->RGB), then to QPixmap. There are several examples how to do this. If you are using OpenGL routines, I think you can display directly a gpuMat image (but I never tried this).

edit flag offensive delete link more


Thank you. Yes, I managed to implement what I needed with QOpenGLWidget and by converting OpenCV Mat directly into textures on the GPU with the OpenGL wrapper that Qt provides - this is much faster than converting the Mat into a QImage and displaying it with QPixmap.

misty marshes gravatar imagemisty marshes ( 2015-10-26 12:32:04 -0600 )edit

Hi, can you share a sample code to this? We are in a similar situation, where we need to render gpuMat directly in QT instead of downloading and rendering.

SelChen gravatar imageSelChen ( 2020-03-10 07:09:27 -0600 )edit

Question Tools

1 follower


Asked: 2015-09-26 13:44:14 -0600

Seen: 3,006 times

Last updated: Oct 02 '15