Here is my code:
img = Image.open('data/img.jpg')
lb = Image.open('data/label.png')
img.show('img')
img.close()
lb.show('lb')
lb.close()
After running this program, the first image is successfully showed, but the second image will not be shown unless I comment the code associated with the first image. What is the cause of this problem.
You can multithread to display both at once:
#!/usr/local/bin/python3
from PIL import Image
from threading import Thread
def display(im):
im.show()
im1 = Image.open('1.jpg')
im2 = Image.open('2.jpg')
t1=Thread(target=display,args=(im1,))
t1.start()
t2=Thread(target=display,args=(im2,))
t2.start()
Or you can temporarily concatenate the images into one:
#!/usr/local/bin/python3
from PIL import Image
import numpy as np
im1 = Image.open('1.jpg')
im2 = Image.open('2.jpg')
Image.fromarray(np.hstack((np.array(im1),np.array(im2)))).show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With