问题描述
以前用的888转P888函数
def trans_888_P888(img_888):
# 将 img_888 转换为 NumPy 数组
img_888_np = img_888.to_numpy_ref()
# 获取 HWC 格式的形状
shape = img_888_np.shape # shape[0] 是 H, shape[1] 是 W, shape[2] 是 C
# print("in shape:", shape)
# 步骤1:将 HWC 格式转换为 CHW 格式
np_temp = img_888_np.reshape((shape[0] * shape[1], shape[2])) # 变为 (H*W, C)
np_temp_trans = np_temp.transpose() # 转置为 (C, H*W)
# 步骤2:将数据转换回 (C, H, W) 格式
np_chw = np_temp_trans.copy().reshape((shape[2], shape[0], shape[1])) # 变为 (C, H, W)
# 创建 img_P888
img_P888 = image.Image(shape[1], shape[0], image.RGBP888, data=np_chw) # 假设 image.CHW888 是 CHW 格式的图像类型
return img_P888
加载jpg图片,并转换为P888格式用于算法识别,该图为庐山派直接采集且能识别的某一帧图片的565通道图片,直接保存而来
img_p888 = m_img.trans_888_P888(image.Image("/data/file_ch/ocr_display.jpg").to_rgb888())
# 由于一直识别不到,想转回565显示看看什么原因
img_565 = img_p888.to_rgb565()
display_img = img_565.copy()
Display.show_image(display_img)
结果图像很不对劲
硬件板卡
庐山派