#!/usr/bin/python
# -*- coding: utf-8 -*-
import cv2
import time
import numpy as np
from matplotlib import pyplot as plt
import cv2.cv as cv
capture = cv2.VideoCapture(0)
print capture.isOpened()
while True:
ret, image = capture.read()
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # 转HSV空间
# define range of blue color in HSV #定义取值的颜色空间
lower_blue = np.array([10, 50, 50])
upper_blue = np.array([40, 255, 255])
# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_blue, upper_blue)
# Bitwise-AND mask and original image
res = cv2.bitwise_and(image, image, mask=mask)
# 构造5×5的结构元素,分别为十字形、菱形、方形和X型
cross = cv2.getStructuringElement(cv2.MORPH_CROSS,(5, 5)) # 十字形
# 菱形结构元素的定义稍麻烦一些
diamond = cv2.getStructuringElement(cv2.MORPH_RECT,(5, 5)) # 菱形
diamond[0, 0] = 0
diamond[0, 1] = 0
diamond[1, 0] = 0
diamond[4, 4] = 0
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载
- 1
- 2
前往页