9

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.

2
  • how is the framerate on the projector? And how is it on your own screen?As far as know, on PC platforms imshow() runs pretty fast. Commented Jan 15, 2014 at 5:39
  • Well, the projector is a DLP projector, so the max fps is 120Hz. My screen is 60Hz. Commented Jan 15, 2014 at 6:01

3 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you. Yeah, from the OpenCV document, it seems the image must be stored in ogl::Buffer, ogl::Texture2D or gpu::GpuMat when using imshow. I am adding OpenGL support to OpenCV from source. But my project works with WIN64. I will test if this support is only with WIN32.
The WIN32 backend works with 32bit as well as 64bit. It is just the crude API naming of Windows. Furthermore, imshow works with cv::Mat, the other formats are additional!
It works with my 64 bit compiler! Now I can show image faster with OpenGL support by storing image in gpu::GpuMat. But which structure is the fastest when input to imshow, ogl::Buffer, ogl::Texture2D or gpu::GpuMat?
I wouldn't expect a noticable difference. The first two do not depend on CUDA, so I would prefer them.
Can someone share a sample code to use opengl with opencv?
6

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?

4 Comments

I compiled CUDA with OpenCV source code. But I have no idea how to show image using CUDA. My image is 640x480, RGB 8 bit. The execution time of 'cv::imshow' is 0.002s.
CUDA does not help at all. It has no output functionality.
@hby001 0.002s is pretty quick, that means you can do 500 of those in 1sec? (500fps) How fast do you need it to be?
@DannieSim It seems fast, but this is only the code running time, as for the time the projector display the image, I don't think it is only 0.002s.
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.