How to get opencv image in an enaml space - Is it possible?

237 Views Asked by At

Is it possible to have enaml as target for OpenCV?

I'm thinking how to setup GUI and what to use. Nothing too complicated, I need to be able to set some bitmap background, draw rectangles and circles over it, but also have the possibility to select/move these graphics objects.

Also, I would like that I do not have to take care of all these elements when I stretch the window, etc. they should do this automatically since they would be defined in some "absolute" space. I think I could easily make it work for the bitmaps (even from memory), by overriding request_image in ImageProvider object (even though I see some strange cache happening in provider/enaml view).

Problem that I'm having now with OpenCV (OSX 64) is that even when I get resize to work with qt backend and CV_WINDOW_NORMAL, the content does not stretch. I like OpenCV, because easily I get basic UI functions.

On the other hand I started to like enaml so I'm thinking did anyone manage to get these to to work together. I'm thinking if link with MPL works, it's possible that coupling with OpenCV should be possible :)

Thanks!

2

There are 2 best solutions below

0
On

This should do it:

from enaml.image import Image
from cv2 import imread, imencode

open_cv_image = imread('./cat.png')
png_image = imencode('.png', open_cv_image)[1].tostring()
enaml_image = Image(data=png_image)
0
On

If you can get your image into argb32 or png format, you can use an Enaml ImageView to display it.

Take a look at the ImageView example: https://github.com/nucleic/enaml/blob/master/examples/widgets/image_view.enaml