imencode
-
Description: Encodes a numpy image into bytes with the requested format.
-
Parameters
- img (
np.ndarray): Image array. - imgtyp (
str | int | IMGTYP): Image type. SupportsIMGTYP.JPEG/IMGTYP.PNG. Default isIMGTYP.JPEG.
- img (
-
Returns
- bytes | None: Encoded bytes; returns
Noneon failure.
- bytes | None: Encoded bytes; returns
-
Notes
- For backward compatibility,
IMGTYP=...is also accepted (providing bothimgtypandIMGTYPraisesTypeError).
- For backward compatibility,
-
Example
from capybara.vision.improc import IMGTYP, imencode, imread
img = imread('lena.png')
encoded_bytes = imencode(img, imgtyp=IMGTYP.PNG)