numpy数组与python内建bytearray互相转换
import cv2
import numpy as np
img = cv2.imread("laugh.jpg", cv2.IMREAD_GRAYSCALE)
print(img.shape)
print(type(img)) # numpy.ndarray
byte_array = bytearray(img)
print(len(byte_array))
img2 = np.array(byte_array).reshape(720, 180)
cv2.imshow("reshaped", img2)
"""
(360, 360)
129600
"""
获取图像基本属性
print(img.shape)
print(img.size)
print(img.dtype)
"""
(360, 360)
129600
uint8
"""
图像信道的分解与合并
b,g,r = cv2.split(img)
img = cv2.merge((b,g,r))
由于图像处理过程中图像深度会变成32或者64,最后要变回uint8,使用下面这个方法
dst = cv2.convertScaleAbs(img)
# 该方法做了三件事 1.scaling 2.取绝对值 3. 映射到uint8