我试图通过循环遍历像素来修改图像。代码是
for x in range(image.shape[0]):
for y in range(image.shape[1]):
if tuple(image[x, y]) in possible_colors_rgb:
image[x, y] = [255, 255, 255]
else:
image[x, y] = [0, 0, 0]在数组possible_colors_bg中,我有一个表示rgb值的3个元素的元组列表。问题是,if从不计算为true,即使我确信有一些像素应该满足相等。我怎么能明白出什么事了?
发布于 2022-07-08 02:49:04
cv2按BGR顺序保存像素值。如果possible_colors_rgb中的元组按RGB顺序排列,则它们将不匹配。
possible_colors_bgr = [(b,g,r) for r,g,b in possible_colors_rgb]如果颜色的数量很大,您可能会考虑使用set而不是tuple或list来实现可能的颜色,以提高效率。
https://stackoverflow.com/questions/72888609
复制相似问题