简体   繁体   English

cv2 python 颜色无法正常工作(绘图)

[英]cv2 python color not working properly (drawing)

I have some code that is supposed to draw a blue line coming out of a blue circle.我有一些代码应该从蓝色圆圈中画出一条蓝线。

        cv2.circle(image, (x, y), 10, (255, 0, 0), -1)
        cv2.line(image, (x, y), (x, y+60), (255, 0, 0), 5)

the code above generates a white circle and a white line, so I thought maybe it's only taking the (255) out of the (255, 0, 0), and turns out I was right.上面的代码生成了一个白色圆圈和一条白线,所以我想也许它只是将 (255) 从 (255, 0, 0) 中取出,结果证明我是对的。 For some reason, the color parameter takes an integer and not a color tuple like in the docs.出于某种原因,颜色参数采用 integer 而不是文档中的颜色元组。 I tried putting in (0, 255, 255) and it drew a black line as expected if it only took the first value (0).我尝试输入 (0, 255, 255),如果它只取第一个值 (0),它会按预期画一条黑线。 I tried also just putting a 0 not in a tuple, which gave the same results.我也尝试只将 0 放在元组中,这给出了相同的结果。 Any help getting it to produce color?有什么帮助让它产生颜色吗?

When making/loading the image make sure you're not loading it in grayscale mode, or制作/加载图像时,请确保您没有以灰度模式加载它,或者

image = np.zeros([1024, 1024, 1], dtype=np.uint8)
                              ^ change to 3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM