首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >旋转时得到黑白图像?

旋转时得到黑白图像?
EN

Stack Overflow用户
提问于 2019-06-03 23:29:10
回答 1查看 26关注 0票数 0

我想把我的图像旋转45度。我已经为此定义了一个函数。当我在我的RGB图像上运行它时,它被保存为灰度图像?

代码语言:javascript
运行
复制
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")
EN

回答 1

Stack Overflow用户

发布于 2019-06-04 13:20:51

这里的线索可能是

代码语言:javascript
运行
复制
row,col = image.shape

如果image是三维的(即,B、G和R具有单独通道的彩色),而不是二维(即,灰度),这将引发错误。除非你正在阅读的RGB图像的代码没有在这里显示,这表明你的图像已经是灰度的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56430413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档