用法:
mxnet.image.imdecode(buf, *args, **kwargs)
- buf:(
str/bytes/bytearray
or
numpy.ndarray
) - 二進製圖像數據作為字符串或 numpy ndarray。 - flag:(
int
,
optional
,
default=1
) - 1 用於三通道顏色輸出。 0 表示灰度輸出。 - to_rgb:(
int
,
optional
,
default=1
) - 1 用於 RGB 格式輸出(MXNet 默認)。 0 用於 BGR 格式輸出(OpenCV 默認)。 - out:(
NDArray
,
optional
) - 輸出緩衝區。采用None
用於自動分配。
- buf:(
包含圖像的
NDArray
。
參數:
返回:
返回類型:
將圖像解碼為 NDArray。
注意:
imdecode
使用 OpenCV(不是 CV2 Python 庫)。 MXNet 必須使用 USE_OPENCV=1 構建,imdecode
才能工作。示例:
>>> with open("flower.jpg", 'rb') as fp: ... str_image = fp.read() ... >>> image = mx.img.imdecode(str_image) >>> image <NDArray 224x224x3 @cpu(0)>
設置
flag
參數為0得到灰度輸出>>> with open("flower.jpg", 'rb') as fp: ... str_image = fp.read() ... >>> image = mx.img.imdecode(str_image, flag=0) >>> image <NDArray 224x224x1 @cpu(0)>
將
to_rgb
參數設置為 0 以獲取 OpenCV 格式 (BGR) 的輸出>>> with open("flower.jpg", 'rb') as fp: ... str_image = fp.read() ... >>> image = mx.img.imdecode(str_image, to_rgb=0) >>> image <NDArray 224x224x3 @cpu(0)>
相關用法
- Python mxnet.image.imresize用法及代碼示例
- Python mxnet.image.imread用法及代碼示例
- Python mxnet.image.resize_short用法及代碼示例
- Python mxnet.image.random_crop用法及代碼示例
- Python mxnet.image.center_crop用法及代碼示例
- Python mxnet.image.CreateAugmenter用法及代碼示例
- Python mxnet.image.ImageIter.read_image用法及代碼示例
- Python mxnet.image.CreateMultiRandCropAugmenter用法及代碼示例
- Python mxnet.image.CreateDetAugmenter用法及代碼示例
- Python mxnet.image.ImageDetIter.sync_label_shape用法及代碼示例
- Python mxnet.image.ImageDetIter.draw_next用法及代碼示例
- Python mxnet.image.scale_down用法及代碼示例
- Python mxnet.io.PrefetchingIter用法及代碼示例
- Python mxnet.initializer.register用法及代碼示例
- Python mxnet.initializer.One用法及代碼示例
- Python mxnet.io.NDArrayIter用法及代碼示例
- Python mxnet.io.ResizeIter用法及代碼示例
- Python mxnet.initializer.Constant.dumps用法及代碼示例
- Python mxnet.initializer.Mixed用法及代碼示例
- Python mxnet.initializer.Zero用法及代碼示例
注:本文由純淨天空篩選整理自apache.org大神的英文原創作品 mxnet.image.imdecode。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。