#convert pixels's color from 0,255,255 to 0,0,0h = mask.shape[0] w = mask.shape[1]for py in range(0,h): for px in range(0,w): if mask[py][px][0] ==0 and mask[py][px][1] == 255 and mask[py][px][2] == 255: for i in range(3): mask[py][px][i] = 0# maskingmasked = mask.copy()for py in range(0,h): for px in range(0,w): if masked[py][px][0] != 0: masked[py][px] = im[py][px]masked = cv2.cvtColor(masked, cv2.COLOR_RGB2BGR)有没有什么奇特的方法可以将我的脏代码转换为带有 cv2 或 numpy 函数的简单代码?
1 回答
偶然的你
TA贡献1841条经验 获得超3个赞
你可以简单地做:
color_old = (0,255,255)
color_new = (0,0,0)
img[(img==color_old).all(-1)] = color_new
- 1 回答
- 0 关注
- 69 浏览
添加回答
举报
0/150
提交
取消