forked from Baymax94/children-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_2.py
More file actions
29 lines (27 loc) · 743 Bytes
/
13_2.py
File metadata and controls
29 lines (27 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
# 获取每一帧
ret, frame = cap.read()
# 转换到HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# 设定蓝色的阈值
lower_blue = np.array([110, 50, 50])
upper_blue = np.array([130, 255, 255])
# 根据阈值构建掩模
mask = cv2.inRange(hsv, lower_blue, upper_blue)
# 对原图像和掩模进行位运算
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
# 关窗口
cv2.destroyAllWindows()
# 物体追踪