要从RGB图像中提取绿色通道,我已经完成了以下代码,但这不起作用
import cv2
green_image = cv2.imread('eye.jpg')
green_image[:,:,0] = 0
green_image[:,:,2] = 0
cv2.imshow('G-RGB', green)
cv2.waitKey(0)
代码已引发错误:
TypeError
1 import cv2
2 green_image = cv2.imread('eye.jpg')
-->3 green_image[:,:,0] = 0
4 green_image[:,:,2] = 0
5 cv2.imshow('G-RGB', green)
TypeError: 'NoneType' object does not support item assignment
答案 0 :(得分:0)
答案 1 :(得分:0)
您可以使用cv2.split
拆分蓝色,绿色和红色通道。
import cv2
img = cv2.imread('eye.jpg')
b, g, r = cv2.split(img)
cv2.imshow('green', g)
cv2.waitKey(0)