[Solved] GDAL+OPENCV often reports errors when processing remote sensing impacts

I found that every time I use the opencv package to process remote sensing images, it often reports an error, even though it has become uint format.
This time I found out that some of them only support three channels, my binary image is one channel, the error of storing the result is because I need to save the result of 1 channel, mine is three channels
so it is necessary to convert 1 channel to 3 channels back and forth ` img1 = np.array(b1)

# img2 = np.dtype(img1, np.uint8)
img = np.expand_dims(img1, axis=2)
img = np.concatenate((img, img, img), axis=-1)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

ret, binary = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)

contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# contours = cv2.findContours(img)
dilate = cv2.fillPoly(img, [contours[1]],(255,15,15))
cv2.imshow("filled binary", dilate)`


Read More: