LearningPythonOpenCV/Class002/pcvc002.py

39 lines
779 B
Python
Raw Permalink Normal View History

2018-01-28 20:12:02 +08:00
#!/usr/bin/python3
# coding=utf-8
"""
Python OpenCV Class 002
"""
import cv2
import numpy as np
CAP = cv2.VideoCapture(0)
# 设置蓝色阈值
LOWER_BLUE = np.array([78, 43, 46])
UPPER_BLUE = np.array([110, 255, 255])
while 1:
# 获取一帧图像并且显示
RET, FRAME = CAP.read()
cv2.imshow('Capture', FRAME)
FRAME = cv2.GaussianBlur(FRAME, (5, 5), 1.5)
cv2.imshow('Gaussian', FRAME)
# 切换到 HSV 模式
HSV = cv2.cvtColor(FRAME, cv2.COLOR_BGR2HSV)
# 获取 Mask
MASK = cv2.inRange(HSV, LOWER_BLUE, UPPER_BLUE)
cv2.imshow('Mask', MASK)
# Mask
RES = cv2.bitwise_and(FRAME, FRAME, mask=MASK)
cv2.imshow('Result', RES)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
CAP.release()
cv2.destroyAllWindows()