一、常用图片库:
opencv、PIL
二、图片的数据类型
1.rgb或bgr byte array是一个可变的序列,每个元素的值的取值范围是[0, 255]
2.二进制流
3.BytesIO对象
6.pil image
三、之间的转换关系
BytesIO对象 二进制
二进制 -> BytesIO对象
BytesIO对象 = io.BytesIO(二进制)
BytesIO对象 -> 二进制
二进制 = BytesIO对象.getvalue()
BytesIO对象 np序列
BytesIO对象 -> np序列
np序列 = cv2.imdecode(np.frombuffer(BytesIO对象.getvalue(), np.uint8), 1)
np序列 -> BytesIO对象
is_success, buffer = cv2.imencode(".jpg", np序列)
BytesIO对象 = io.BytesIO(buffer)
二进制 np序列
二进制 -> np序列
np序列 = cv2.imdecode(np.frombuffer(二进制, np.uint8), 1)
np序列 -> 二进制
二进制 = np序列.tobytes()
PIL rgb序列
np序列->PIL
PIL_image = Image.fromarray(np序列)
PIL -> np序列
np序列 = numpy.array(PIL_image)