Harihara
Harihara

Reputation: 2747

Python PIL. Image does not open

Below is my code for opening an image:

import Image

filename = "Golden-Gauranga.png"
image = Image.open(filename, "r")
image.show()

However, the image does not open. Nothing happens.

Upvotes: 0

Views: 1203

Answers (2)

Harihara
Harihara

Reputation: 2747

For now, I am opening the image file using the below code:

import os
os.system("gvfs-open today")

I am on an Ubuntu system and today is the name of the image file.

Upvotes: 0

albusdemens
albusdemens

Reputation: 6624

You could try using cv2 and pyplot instead of Image. First you need to install OpenCV and the other modules, and then change your code to something like

import cv2
import numpy
import matplotlib.pyplot as plt
filename = "Golden-Gauranga.png"
im = cv2.imread(filename, -1)
imarray = numpy.array(im)
plt.imshow(imarray)
plt.show

Upvotes: 1

Related Questions