Error in using CV2. Applycolormap()

CV ::ColorMap only supports source images of type CV_8UC1 or CV_8UC3 in function cv2.applycolormap () error

recently used cv2.cv2.applycolormap () to convert a 2-d ndarray into a pseudo-color image. It is found that an error message “CV ::ColorMap only supports source images of type CV_8UC1 or CV_8UC3 in function” is frequently popped. It is found that the 2-d nDARray element data type must be converted to NP. uint8 type.

import numpy as np
import cv2
a = np.ones((2,3))
b = a.astype(np.uint8)
img1 = cv2.applyColorMap(a, cv2.COLORMAP_JET)  # 报错
img2 = cv2.applyColorMap(b, cv2.COLORMAP_JET)  # 正常

Read More: