(Apr-25-2018, 05:26 AM)wavic Wrote: You can use io module.
Something like this:
from io import BytesIO
with BytesIO()as image:
img.save(image, format='GIF') # the img is the picture you have already opened
image.seek(0) # move the pointer back to the beginning of the "file"
my_gif = Image.open(image)
Now you can work with my_gif object.
Thank you! The solution you provided me works but I get an error when I try to implement it in my filter. Here is my code. Further below is the error. smoothImage is a function from mean_filter.py that improves the quality of pixelated images by applying a filter to them.
[inline]
import cv2
import io
from io import BytesIO
from mean_filter import *
myImage = cv2.imread("people3_pix.bmp")
cv2.imwrite("output.bmp", myImage)
with open("output.bmp", "r+") as img:
imageToFilter = img.read()
with BytesIO() as image:
imageToFilter.save(image, format = "GIF")
image.seek(0)
my_gif = Image.open(image)
myImage1 = smoothImage(my_gif)
[/inline]
[inline]Traceback (most recent call last):
File "test.py", line 10, in <module>
imageToFilter = img.read()
File "/usr/lib/python3.6/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 2: invalid start byte
[/inline]