Skip to content
Advertisement

Efficiently render 3D numpy bitmap array (y, x, RGB) to window on macOS (using openCV or otherwise)

I’m rendering a dynamically changing numpy bitmap array and trying to improve my framerate.

Currently I’m using openCV:

JavaScript

This takes ~20ms, which is not bad.

But can I do better?

JavaScript

Setting this has no noticeable effect. But does openCV offer a better technique than imshow to make use of a GL drawing surface?

And is there any viable alternative to openCV? import OpenGL is a verified can of worms.

REF: Display numpy array cv2 image in wxpython correctly

REF: https://pypi.org/project/omgl/0.0.1/

Advertisement

Answer

You may render the video using external sub-process video renderer.

I tested the suggested solution by piping the video frames to FFplay.
The solution is not working so well – the last frames are not shown.

Treat the solution as conceptual solution.

The code opens FFplay as sub-process, and write the raw frames to stdin pipe of FFplay.

Here is the code:

JavaScript

Result (Windows 10):

JavaScript

On my machine the differences are very small.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement