From 9911effb38ffd14c618b0b34efd905d8cf445392 Mon Sep 17 00:00:00 2001 From: Lion Chan Date: Sun, 28 Jan 2018 20:12:02 +0800 Subject: [PATCH] =?UTF-8?q?Class=202=20=E9=A2=9C=E8=89=B2=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=EF=BC=8C=E5=8F=AA=E4=BF=9D=E7=95=99=E8=93=9D=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Class002/pcvc002.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 Class002/pcvc002.py diff --git a/Class002/pcvc002.py b/Class002/pcvc002.py new file mode 100755 index 0000000..6acfc1e --- /dev/null +++ b/Class002/pcvc002.py @@ -0,0 +1,38 @@ +#!/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()