python-imaging-library

how to display PIL image with pygame?

时光毁灭记忆、已成空白 提交于 2021-01-02 20:29:34
问题 I am trying to do some video stream from my raspberry pi over the wifi. I used pygame, because i also have to use gamepad in my project. Unfortunately I stucked on displaying received frame. Shortly: i get jpeg frame, open it with PIL, convert to string - after that i can load image from string image_stream = io.BytesIO() ... frame_1 = Image.open(image_stream) f = StringIO.StringIO() frame_1.save(f, "JPEG") data = f.getvalue() frame = pygame.image.fromstring(frame_1,image_len,"RGB") screen

how to display PIL image with pygame?

a 夏天 提交于 2021-01-02 20:28:29
问题 I am trying to do some video stream from my raspberry pi over the wifi. I used pygame, because i also have to use gamepad in my project. Unfortunately I stucked on displaying received frame. Shortly: i get jpeg frame, open it with PIL, convert to string - after that i can load image from string image_stream = io.BytesIO() ... frame_1 = Image.open(image_stream) f = StringIO.StringIO() frame_1.save(f, "JPEG") data = f.getvalue() frame = pygame.image.fromstring(frame_1,image_len,"RGB") screen

Outline text on image in Python

谁都会走 提交于 2021-01-02 06:26:20
问题 I have been using PIL Image I am trying to draw text on an image. I want this text to have a black outline like most memes. I've attempted to do this by drawing a shadow letter of a bigger font behind the letter in front. I've adjusted the x and y postions of the shadow accordingly. The shadow is slightly off though. The letter in front should be exactly in the middle of the shadow letter, but this isn't the case. The question mark certainly isn't centered horizontally, and all the letters

Python: How to cut out an area with specific color from image (OpenCV, Numpy)

ⅰ亾dé卋堺 提交于 2020-12-30 09:46:36
问题 so I've been trying to code a Python script, which takes an image as input and then cuts out a rectangle with a specific background color. However, what causes a problem for my coding skills, is that the rectangle is not on a fixed position in every image (the position will be random). I do not really understand how to manage the numpy functions. I also read something about OpenCV, but I'm totally new to it. So far I just cropped the images through the ".crop" function, but then I would have

Compare images Python PIL

老子叫甜甜 提交于 2020-12-29 09:12:51
问题 How can I compare two images? I found Python's PIL library, but I do not really understand how it works. 回答1: To check does jpg files are exactly the same use pillow library: from PIL import Image from PIL import ImageChops image_one = Image.open(path_one) image_two = Image.open(path_two) diff = ImageChops.difference(image_one, image_two) if diff.getbbox(): print("images are different") else: print("images are the same") 回答2: based on Victor Ilyenko's answer, I needed to convert the images to

Save numpy array as single channel png with custom colors

白昼怎懂夜的黑 提交于 2020-12-26 18:56:26
问题 I have an integer numpy array representing image with few values (about 2-5). And I would like to save it to png file with custom color for every value. I was trying it like this: import numpy as np from PIL import Image array = np.zeros([100, 200, 4], dtype=np.uint8) array[:,:100] = [255, 128, 0, 255] #Orange left side array[:,100:] = [0, 0, 255, 255] #Blue right side img = Image.fromarray(array) img.save(r'D:\test.png') The result is ok, but it has 4 channels. I need the result to be single

Save numpy array as single channel png with custom colors

馋奶兔 提交于 2020-12-26 18:50:47
问题 I have an integer numpy array representing image with few values (about 2-5). And I would like to save it to png file with custom color for every value. I was trying it like this: import numpy as np from PIL import Image array = np.zeros([100, 200, 4], dtype=np.uint8) array[:,:100] = [255, 128, 0, 255] #Orange left side array[:,100:] = [0, 0, 255, 255] #Blue right side img = Image.fromarray(array) img.save(r'D:\test.png') The result is ok, but it has 4 channels. I need the result to be single

How to make Pillow recognisable by pycharm

て烟熏妆下的殇ゞ 提交于 2020-12-15 05:00:33
问题 I get the error: ModuleNotFoundError: No module named 'PIL' I installed PIL using pip but get the error. I used the code below to import Pillow library: from PIL import ImageTk,Image Any help? 回答1: PyCharm uses a virtual environment for every project. You may have installed PIL outside of your venv. To install it inside, do this. Open your project At the bottom of your screen, hit Terminal From there, pip install -U pillow Note: When making the project, you may not have checked the button,

Accessing extracted zip file in Colab

微笑、不失礼 提交于 2020-12-14 11:43:56
问题 Some case study here. I am trying to play with PIL library in Google Colab, and can't get ImageFont to read my originally zipped file. The code: import requests, zipfile, io r3 = requests.get('https://sources.archlinux.org/other/community/ttf-roboto/ttf-roboto-hinted-2.138.zip') z3 = zipfile.ZipFile(io.BytesIO(r3.content)) z3.extractall() So far so good, and if I browse my directory with ls, it shows me the elements: ls Shows: LICENSE RobotoCondensed-Regular.ttf __MACOSX/ Roboto-Italic.ttf

Accessing extracted zip file in Colab

放肆的年华 提交于 2020-12-14 11:40:50
问题 Some case study here. I am trying to play with PIL library in Google Colab, and can't get ImageFont to read my originally zipped file. The code: import requests, zipfile, io r3 = requests.get('https://sources.archlinux.org/other/community/ttf-roboto/ttf-roboto-hinted-2.138.zip') z3 = zipfile.ZipFile(io.BytesIO(r3.content)) z3.extractall() So far so good, and if I browse my directory with ls, it shows me the elements: ls Shows: LICENSE RobotoCondensed-Regular.ttf __MACOSX/ Roboto-Italic.ttf