我有一个绿色背景的图像,例如:我的目的是展示所有不是绿色的东西有代码突出显示绿色import cv2import numpy as nplow_green = np.array([25, 52, 72])high_green = np.array([102, 255, 255])while True: img = cv2.imread('someimage.jpg') img = cv2.resize(img, (900, 650), interpolation=cv2.INTER_CUBIC) # convert BGR to HSV imgHSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # create the Mask mask = cv2.inRange(imgHSV, low_green, high_green) cv2.imshow("mask", mask) cv2.imshow("cam", img) cv2.waitKey(10)和蒙版图像如何在蒙版图像上显示黑色的所有内容?
2 回答
浮云间
TA贡献1829条经验 获得超4个赞
这是代码:
import cv2
import numpy as np
low_green = np.array([25, 52, 72])
high_green = np.array([102, 255, 255])
while True:
img = cv2.imread('someimage.JPG')
img = cv2.resize(img, (900, 650), interpolation=cv2.INTER_CUBIC)
# convert BGR to HSV
imgHSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# create the Mask
mask = cv2.inRange(imgHSV, low_green, high_green)
# inverse mask
mask = 255-mask
res = cv2.bitwise_and(img, img, mask=mask)
cv2.imshow("mask", mask)
cv2.imshow("cam", img)
cv2.imshow('res', res)
cv2.waitKey(10)
和结果
添加回答
举报
0/150
提交
取消