使用cv2.line(...)绘制一条线时,OpenCV会覆盖原始图像

时间:2017-09-14 01:02:48

标签: python opencv

我使用cv2.line(...)在现有图片上绘制线条。我把它分解成了这个简单的例子。我不明白为什么第一次拨打cv2.line(...)时原始图片丢失了,但第二次通话时似乎没有发生同样的情况。

# Show the original image (BGR color map)
misc.imshow(vis)

# Draw the first line display, the original image is lost
cv2.line(vis, (10, 10), (300, 300), color=(0, 255, 0), thickness=4)
misc.imshow(vis)

# Draw a second line, somehow the previous image wasn't lost this time
cv2.line(vis, (50, 100), (250, 200), color=(0, 255, 0), thickness=4)
misc.imshow(vis)

imshow的结果:

enter image description here

enter image description here

enter image description here

预期的结果是原始图像,两条线在其上绘制。

1 个答案:

答案 0 :(得分:0)

出现问题是因为我的图像被表示为一个float32图像,其像素值在[0,1]范围内,而颜色设置为(0,255,0),强制图像为整数表示,舍入所有我的[0,1]值为整数。

将我的颜色值更改为(0,1.0,0)可以解决问题。