Add convert_to_pil_image to pil util (#31825)
* Update pil.py * Update doods and tensorflow to use convert_to_pil_image * Update pil.py * Add log messages on bad data * Drop convert_to_pil_image Just perform conversion in the integrations without seperate convert_to_pil_image()pull/32031/head
parent
7a6b13cb0d
commit
a7d5e898ba
|
@ -3,7 +3,7 @@ import io
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw, UnidentifiedImageError
|
||||||
from pydoods import PyDOODS
|
from pydoods import PyDOODS
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -274,7 +274,11 @@ class Doods(ImageProcessingEntity):
|
||||||
|
|
||||||
def process_image(self, image):
|
def process_image(self, image):
|
||||||
"""Process the image."""
|
"""Process the image."""
|
||||||
img = Image.open(io.BytesIO(bytearray(image)))
|
try:
|
||||||
|
img = Image.open(io.BytesIO(bytearray(image))).convert("RGB")
|
||||||
|
except UnidentifiedImageError:
|
||||||
|
_LOGGER.warning("Unable to process image, bad data")
|
||||||
|
return
|
||||||
img_width, img_height = img.size
|
img_width, img_height = img.size
|
||||||
|
|
||||||
if self._aspect and abs((img_width / img_height) - self._aspect) > 0.1:
|
if self._aspect and abs((img_width / img_height) - self._aspect) > 0.1:
|
||||||
|
|
|
@ -4,7 +4,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw, UnidentifiedImageError
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -287,7 +287,11 @@ class TensorFlowImageProcessor(ImageProcessingEntity):
|
||||||
inp = img[:, :, [2, 1, 0]] # BGR->RGB
|
inp = img[:, :, [2, 1, 0]] # BGR->RGB
|
||||||
inp_expanded = inp.reshape(1, inp.shape[0], inp.shape[1], 3)
|
inp_expanded = inp.reshape(1, inp.shape[0], inp.shape[1], 3)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
img = Image.open(io.BytesIO(bytearray(image))).convert("RGB")
|
try:
|
||||||
|
img = Image.open(io.BytesIO(bytearray(image))).convert("RGB")
|
||||||
|
except UnidentifiedImageError:
|
||||||
|
_LOGGER.warning("Unable to process image, bad data")
|
||||||
|
return
|
||||||
img.thumbnail((460, 460), Image.ANTIALIAS)
|
img.thumbnail((460, 460), Image.ANTIALIAS)
|
||||||
img_width, img_height = img.size
|
img_width, img_height = img.size
|
||||||
inp = (
|
inp = (
|
||||||
|
|
Loading…
Reference in New Issue