资源简介
主要使用了OpenCV的视频采集, 图像色域转换, 颜色通道分割, 高斯滤波, OSTU自动阈值, 凸点检测, 边缘检测, 余弦定理计算手势等功能,实现手势识别与控制
代码片段和文件信息
# imports - standard imports
import io
import base64
# imports - third-party imports
import numpy as np
from PIL import Image
import cv2
class Config(object):
NAME = ‘pygr‘
VERSION = ‘0.1.0‘
PyGR_SIZE = (480 320)
class Keycode(object):
ESCAPE = 27
Q = ord(‘Q‘)
q = ord(‘q‘)
class Event(object):
‘‘‘
Event object
‘‘‘
NONE = None
ROCK = 0 # 石头
SCISSOR = 1 # 剪刀
SPOCK = 2
PAPER = 4 # 布
ZERO = 0
ONE = 1
TWO = 2
THREE = 3
FOUR = 4
FIVE = 5
def __init__(self type_=None):
self.type = type_
self.tip = (None None)
def setType(self type_):
self.type = type_
def setTip(self position):
self.tip = position
def get_tip(self):
return self.tip
class Util(object):
@staticmethod
def resize_image(image size maintain_aspect_ratio=False):
copy = image.copy()
copy.thumbnail(size Image.ANTIALIAS)
return copy
@staticmethod
def round_int(value):
result = int(np.rint(value))
return result
@staticmethod
def to_grayscale(array):
gray = cv2.cvtColor(array cv2.COLOR_BGR2GRAY)
return gray
@staticmethod
def get_opencv_version():
version = cv2.__version__
version = version.split(‘.‘)
major minor patch = int(version[0]) int(version[1]) int(version[2])
return (major minor patch)
@staticmethod
def mount_roi(array roi color=(0 255 0) thickness=1):
x y w h = roi
cv2.rectangle(array (x y) (x + w y + h)
color=color thickness=thickness)
return array
@staticmethod
def image_to_bytes(image format_=‘.jpg‘):
array = np.asarray(image)
_ jpeg = cv2.imencode(format_ array)
bytes_ = jpeg.tobytes()
return bytes_
@staticmethod
def base64_str_to_image(string):
decode = base64.b64decode(string)
bytes_ = io.BytesIO(decode)
image = Image.open(bytes_)
return image
class Capture(object):
‘‘‘
Capture object
:param deviceID: device ID of your capture device defaults to 0
:type deviceID: :obj:‘int‘
Example
>>> import pygr
>>> cap = pygr.Capture()
‘‘‘
def __init__(self deviceID=0):
self.deviceID = deviceID
self.capture = cv2.VideoCapture(self.deviceID)
def read(self):
‘‘‘
Reads the current input stream from a capture device and returns a ‘PIL.Image‘ object
>>> import pygr
>>> cap = pygr.Capture()
>>> image = cap.read()
>>> image.show()
‘‘‘
_ frame = self.capture.read()
frame = cv2.bilateralFilter(frame 5 50 100) # 双边滤波
image = Image.fromarray(frame)
return image
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2994 2018-04-25 11:03 ba
文件 5478 2018-04-25 15:42 gesture.py
文件 650 2018-04-25 11:34 main.py
文件 4494 2018-04-25 11:03 pygr.py
文件 97 2019-02-19 01:49 教程.txt
相关资源
- python+sqlite学生成绩管理
- Programming Python-Python编程第4版-上下册
- python3-bayes朴素贝叶斯
- 最近邻kNN-python3源码和数据
- 安装包feedparser-5.2.1
- python腾讯文字识别 OCR脚本
- python词云源码
- 多元线性回归预测房价算法pythons实现
- 笨方法学pythonLearn Python the Hard Way中文
- python编写2048小游戏
- 上交软院2017、2018年机试题目及代码
- 小猪佩奇学习代码
- 二元有限域矩阵的秩的计算 python语言
- month2day.py
- python-opencv 机器视觉 质心,形心 坐标
- keras上LSTM长短期记忆网络金融时序预
- Python代码gabor提取纹理特征
- 数塔问题界面实现
- python加django加websocket实现即时通讯
- RRT规划算法
- python qt5教程
- Lukas-Kanade光流法python代码
- django+python实现的web入门程序-注册登录
- Python编写组合导航数据采集程序
- python爬取豆瓣每个账户对电影的评分
- 基于python实现 淘宝购物车秒杀,自动
- Python-2.7.13-xcompile.patch
- pydelicious的__init__.py替换文件
- 使用python对淘宝商品信息数据进行爬
- python全套视频教程
评论
共有 条评论