Python - 使用 opencv 时颜色不正确
Python - incorrect colors when using opencv
我正在尝试使用 opencv 在白框中随机生成彩色像素,但生成的像素颜色错误。有什么办法可以解决这个问题吗?
这是我的代码:
import random
import cv2
img = cv2.imread("anhnen.png")
i=1
while i <= 200:
i = i+1
x = random.randint(0,479)
y = random.randint(0,479)
img[x][y] = [255,0,0]
cv2.imwrite('anh2.png', img)
这是运行代码后的图片
image2
OpenCV 默认使用 BGR 颜色格式。将您的代码更改为 [0, 0, 255]
我正在尝试使用 opencv 在白框中随机生成彩色像素,但生成的像素颜色错误。有什么办法可以解决这个问题吗? 这是我的代码:
import random
import cv2
img = cv2.imread("anhnen.png")
i=1
while i <= 200:
i = i+1
x = random.randint(0,479)
y = random.randint(0,479)
img[x][y] = [255,0,0]
cv2.imwrite('anh2.png', img)
这是运行代码后的图片 image2
OpenCV 默认使用 BGR 颜色格式。将您的代码更改为 [0, 0, 255]