Image Utils¶
Util methods for operation on image
-
class
eyewitness.image_utils.
Image
(image_id, raw_image_path=None, pil_image_obj=None)¶ Bases:
object
Image object is use to represent a Image in whole eyewitness project
To initialize a Image obj, image_id is required, and one of raw_image_path, pil_image_obj should be given, while only giving raw_image_path is kind of lazy evaluation, will read the image only when image_obj.pil_image_obj called
Parameters: - image_id (ImageId) -- the id of image
- raw_image_path (Optional[str]) -- the raw image path
- pil_image_obj (Optional[PIL.Image.Image]) -- the pil image obj
-
fetch_bbox_pil_objs
(bbox_objs)¶ Parameters: - bbox_objs (List[BoundedBoxObject]) -- List of bbox objs, which used to generate bbox pil_image_obj
- Returns --
- -------- --
- output_list (List[PIL.Image.Image]) --
-
pil_image_obj
¶ pil_image_obj is a property of the Image, if _pil_image_obj exist will directly return the obj, else will read from raw_image_path.
-
class
eyewitness.image_utils.
ImageHandler
¶ Bases:
object
util functions for image processing including: save, read from file, read from bytes, draw bounding box.
-
classmethod
draw_bbox
(image, detections, colors=None, font_path='/home/docs/checkouts/readthedocs.org/user_builds/eyewitness/checkouts/latest/eyewitness/font/FiraMono-Medium.otf')¶ draw bbox on to image.
Parameters: - image (PIL.Image.Image) -- image to be draw
- detections (List[BoundedBoxObject]) -- bbox to draw
- colors (Optional[dict]) -- color to be used
- font_path (str) -- font to be used
-
classmethod
read_image_bytes
(image_byte)¶ PIL.Image.open support BytesIO input.
Parameters: image_path (BytesIO) -- read image from ByesIO obj Returns: pil_image_obj -- PIL.Image.Image instance Return type: PIL.Image.Image
-
classmethod
read_image_file
(image_path)¶ PIL.Image.open read from file.
Parameters: image_path (str) -- source image path Returns: pil_image_obj -- PIL.Image.Image instance Return type: PIL.Image.Image
-
classmethod
save
(image, output_path)¶ Parameters: - image (PIL.Image) -- image obj
- output_path (str) -- path to be save
-
classmethod
-
class
eyewitness.image_utils.
ImageProducer
¶ Bases:
object
ImageProducer abstract class, should produce_method property and produce_image function
-
produce_image
()¶
-
produce_method
¶
-
-
class
eyewitness.image_utils.
PostBytesImageProducer
(host, protocol='http')¶ Bases:
eyewitness.image_utils.ImageProducer
PostBytes Image Producer, will sent the image bytes to destination by Http post
-
produce_image
(image_id, image_bytes, raw_image_path=None)¶
-
produce_method
¶
-
-
class
eyewitness.image_utils.
PostFilePathImageProducer
(host, protocol='http')¶ Bases:
eyewitness.image_utils.ImageProducer
PostFilePath Image Producer, will sent the image_path string to destination by Http post
-
produce_image
(image_id, raw_image_path)¶
-
produce_method
¶
-
-
eyewitness.image_utils.
resize_and_stack_image_objs
(resize_shape, pil_image_objs)¶ resize images and concat into numpy array
Parameters: - resize_shape (tuple[int]) -- the target resize shape (w, h)
- pil_image_objs (List[PIL.Image.Image]) -- List of image objs
Returns: batch_images_array
Return type: np.array with shape (n, w, h, c)
-
eyewitness.image_utils.
swap_channel_rgb_bgr
(image)¶ reverse the color channel image: convert image (w, h, c) with channel rgb -> bgr, bgr -> rgb.
Parameters: image (np.array) -- Returns: image Return type: np.array