cv3.io.imdecode
- cv3.io.imdecode(buf, flag)[source]
Decode an image from a buffer.
- Parameters:
buf (numpy.ndarray) – Buffer containing the image data.
flag (int or str) – Flag specifying the color type of the decoded image. Can be one of: ‘color’, ‘gray’, ‘alpha’, ‘unchanged’ or OpenCV flags.
- Returns:
Decoded image.
- Return type:
numpy.ndarray
Example
>>> import cv3 >>> import numpy as np >>> # Read image file as bytes >>> with open('image.jpg', 'rb') as f: ... buf = np.frombuffer(f.read(), dtype=np.uint8) >>> # Decode image >>> img = cv3.imdecode(buf, 'color')