hby001
hby001

Reputation: 145

Does OpenGL display image faster than OpenCV?

I am using OpenCV to show image on the projector. But it seems the cv::imshow is not fast enough or maybe the data transfer is slow from my CPU to GPU then to projector, so I wonder if there is a faster way to display than OpenCV?

I considered OpenGL, since OpenGL directly uses GPU, the command may be faster than from CPU which is used by OpenCV. Correct me if I am wrong.

Upvotes: 9

Views: 15063

Answers (3)

elena
elena

Reputation: 111

I know it's an old question, but I happened to have exactly the same problem. And from my observations I've concluded that the root of the problem is the projector's own latency, especially if one is using an older model.

How have I concluded it?

I displayed the same video sequence with cv::imshow() on the laptop monitor and on the projector. Then I waved my hand. It was obvious, that projector introduces significant latency.

To double-check, I've opended a webcam video, waved my hand in front of it and observed the difference on the monitor and on the projector. Webcam does no processing, no opencv operations, so in my understanding the only thing that would explain the latency would be the projector itself.

Upvotes: 0

ypnos
ypnos

Reputation: 52357

OpenCV already supports OpenGL for image output by itself. No need to write this yourself!

See the documentation: http://docs.opencv.org/modules/highgui/doc/user_interface.html#imshow http://docs.opencv.org/modules/highgui/doc/user_interface.html#namedwindow

Create the window first with namedWindow, where you can pass the WINDOW_OPENGL flag. Then you can even use OpenGL buffers or GPU matrices as input to imshow (the data never leaves the GPU). But it will also use OpenGL to show regular matrix data.

Please note:

To enable OpenGL support, configure OpenCV using CMake with WITH_OPENGL=ON . Currently OpenGL is supported only with WIN32, GTK and Qt backends on Windows and Linux (MacOS and Android are not supported). For GTK backend gtkglext-1.0 library is required.

Note that this is OpenCV 2.4.8 and this functionality has changed quite recently. I know there was OpenGL support in earlier versions in conjunction with the Qt backend, but I don't remember when it was introduced.

About the performance: It is a quite popular optimization in the CV community to output images using OpenGL, especially when outputting video sequences.

Upvotes: 11

Dannie
Dannie

Reputation: 2480

OpenGL is optimised for rendering images, so it's likely faster. It really depends if the OpenCV implementation uses any GPU acceleration AND if the bottleneck is on rendering side of things.

Have you tried GPU accelerated OpenCV? - http://opencv.org/platforms/cuda.html

How big is the image you are displaying? How long does it take to display the image using cv::imshow now?

Upvotes: 6

Related Questions