用户可以通过调用图片解码以及图像处理接口(抠图、缩放、补边等操作对应接口),得到待编码的Image对象,通过调用ImageProcessor类的Encode接口输出到内存或者保存到本地。
图片编码调用流程参考如下:
关键步骤说明如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from mindx.sdk import base from mindx.sdk.base import ImageProcessor, Rect, Image def process(): # 图像解码 # 初始化ImageProcessor对象 imageProcessor = ImageProcessor(device_id) image_path = "image_data/test_image.jpg" # 读取图片路径进行解码,解码格式为nv12(YUV_SP_420) decoded_image = imageProcessor.decode(image_path, base.nv12) # 图像处理操作(抠图) crop_para = [Rect(300, 100, 550, 350)] croped_images = imageProcessor.crop(decoded_image, crop_para) # 图像编码 image_save_path = "croped_image.jpg" imageProcessor.encode(croped_images[0], image_save_path) if __name__ == "__main__": base.mx_init() # 资源初始化 process() base.mx_deinit() # 资源去初始化 |