Answers for "pillow image to cv2"

2

convert opencv image to pil image

import cv2
import numpy as np
from PIL import Image

img = cv2.imread("path/to/img.png")

# You may need to convert the color.
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
im_pil = Image.fromarray(img)

# For reversing the operation:
im_np = np.asarray(im_pil)
Posted by: Guest on June-26-2020
4

python pillow convert jpg to png

from PIL import Image

im1 = Image.open(r'C:\Users\Ron\Desktop\Test\autumn.jpg')
im1.save(r'C:\Users\Ron\Desktop\Test\new_autumn.png')
Posted by: Guest on May-11-2020
3

python pillow convert jpg to png

from PIL import Image

im1 = Image.open(r'path where the JPG is stored\file name.jpg')
im1.save(r'path where the PNG will be stored\new file name.png')
Posted by: Guest on May-11-2020

Python Answers by Framework

Browse Popular Code Answers by Language