我的毕业设计有问题。我是这个网站的新用户。如果我会犯错,我很抱歉。 现在我的问题是,我在python / openCV中使用我的网络摄像头拍摄帧并用红色和蓝色阈值过滤它。我可以这一部分。但我想创建一个带有阈值图像的矩阵。可能吗?
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
# Take each frame
_, frame = cap.read()
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# define range of blue color in HSV
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])
lower_red = np.array([0, 100, 100])
upper_red = np.array([10, 255, 255])
red_mask = cv2.inRange(hsv, lower_red, upper_red) # I have the Red threshold image.
# Threshold the HSV image to get only blue colors
blue_mask = cv2.inRange(hsv, lower_blue, upper_blue)
mask = blue_mask + red_mask
# Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)
cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
这是阈值过滤器的代码。我将在下一部分为矩阵做什么? This is my threshold filter example请不要在我的平台之外看到:)
我想在矩阵中写出红色为'1',其他为'0',蓝色的最后一个是'2'或'X'。