Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display an image and my code keeps running in the background?

I take part in a project in which we are making a sudoku solver. I want to print the image of the solved sudoku grid on the screen while our drawing table is drawing the solution on the paper grid. But I can't find a way to display an image and my code keeps running.

I have looked into - I think - all of the opencv and matplotlib.pyplot functions to display images but every time the code stops when the image is displayed and continues once the image is closed (plt.show() or using cv2.waitKey()).

So if anyone has an idea of a way to display an image while the python code keeps running, I'd be glad to hear it.

Thanks

like image 716
Yann POURCENOUX Avatar asked Sep 12 '25 20:09

Yann POURCENOUX


1 Answers

The PIL/Pillow Image.show() method will leave your image showing on the screen and your code will continue to run.

If you have a black and white image in a Numpy/OpenCV array, you can make it into a PIL Image and display it like this:

from PIL import Image

Image.fromarray(NumpyImg).show()

If your image is colour, you'll need to go from BGR to RGB either using cv2.cvtColor(...BGR2RGB..) or by reversing your 3rd channel something like (untested):

Image.fromarray(NumpyImg[:,:,::-1]).show()
like image 130
Mark Setchell Avatar answered Sep 15 '25 09:09

Mark Setchell