我想把我的图像旋转45度。我已经为此定义了一个函数。当我在我的RGB图像上运行它时,它被保存为灰度图像?
def rotateImage(image, angle):
row,col = image.shape
center=tuple(np.array([row,col])/2)
rot_mat = cv2.getRotationMatrix2D(center,angle,1.0)
new_image = cv2.warpAffine(image, rot_mat, (col,row))
return new_image
rotate_img_path = '../data/rotate_45_img'
rotate_mask_path = '../data/rotate_45_mask'
real_img_path = '../data/img'
real_mask_path = '../data/mask'
for img in os.listdir(real_img_path):
edge_img = cv2.imread(os.path.join(real_img_path,img))
edges = rotateImage(edge_img, 45)
cv2.imwrite(os.path.join(rotate_img_path, img), edges)
print("Finished Copying images")
for img in os.listdir(real_mask_path):
edge_img = cv2.imread(os.path.join(real_mask_path,img))
edges = rotateImage(edge_img, 45)
cv2.imwrite(os.path.join(rotate_mask_path, img), edges)
# cv2.imwrite('edge_' + '.jpg', edges)
print("Finished Copying masks")
发布于 2019-06-04 13:20:51
这里的线索可能是
row,col = image.shape
如果image
是三维的(即,B、G和R具有单独通道的彩色),而不是二维(即,灰度),这将引发错误。除非你正在阅读的RGB图像的代码没有在这里显示,这表明你的图像已经是灰度的。
https://stackoverflow.com/questions/56430413
复制相似问题