OpenCV简易视频处理框架
OpenCV主要色彩空间
OpenCV的位操作方法
找出视频中红色物体
import cv2
import numpy as np
def filter_out_black(src_frame):
if src_frame is not None:
hsv = cv2.cvtColor(src_frame, cv2.COLOR_BGR2HSV)
lower_red = np.array([0, 0, 0])
upper_red = np.array([180, 255, 172])
# inRange()方法返回的矩阵只包含0,255 (CV_8U) 0表示不在区间内
mask = cv2.inRange(hsv, lower_red, upper_red)
return cv2.bitwise_and(src_frame, src_frame, mask=mask)
def filter_out_red(src_frame):
if src_frame is not None:
hsv = cv2.cvtColor(src_frame, cv2.COLOR_BGR2HSV)
lower_red = np.array([156, 43, 46])