有时,需要进行opencv Mat图片数据和二进制数据互转操作,转换如下 with open(image_path, "rb") as file: jpg_bin = file.read() image = cv2.imdecode(np.asarray(bytearray(jpg_bin),dtype='uint8'), cv2.IMREAD_COLOR) with open(tmp_image_path, 'wb') as tmp_file: tmp_jpg_bin = np.array(cv2.imencode('.jpg', image)[1]).tobytes() tmp_file.write(tmp_jpg_bin)
python 二进制图片数据和cv2图片数据互转
最新推荐文章于 2023-07-30 15:54:31 发布