# -*- coding: utf-8 -*-
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtSql import *
import os
import sys
import copy
from PIL import Image
import time
import cv2
import qimage2ndarray
import mmap
import numpy as np
import multiprocessing
import re
import random
sample_counts = 400
skinkernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
# 工具类(单例模式)
class UtilOperation(object):
_shared_state = {}
mGesture = None
mm = None
def __new__(cls, *args, **kwargs):
obj = super(UtilOperation, cls).__new__(cls, *args, **kwargs)
obj.__dict__ = cls._shared_state
print('__new__')
return obj
def gestureLoadNNByBtn(self, weight_index=0, weight_name='binmask_CnnModel.hdf5'):
# xunfengd
# from train_gesture_model import TrainGestureModeByCNN
from gesture_recognize import GestureRecognize
from keras import backend as K
K.clear_session() # clear session
# xunfengd get gesture object
self.mGesture = GestureRecognize(-1)
self.mGesture.loadCNN(weight_index, weight_name)
self.mGesture.static_image_recognize('train_set/eight/eight_24.png')
print('gestureLoadNN...' + weight_name)
return self.mGesture
def gestureLoadNN(self, weight_index=0, weight_name='binmask_CnnModel.hdf5'):
if self.mGesture is None:
from gesture_recognize import GestureRecognize
from keras import backend as K
K.clear_session() # clear session
self.mGesture = GestureRecognize()
self.mGesture.loadCNN(weight_index, weight_name)
# 手动预测一次,避免keras报错
self.mGesture.static_image_recognize('train_set/eight/eight_24.png')
print('gestureLoadNN...' + weight_name)
return self.mGesture
def getMmap(self):
if self.mm == None:
self.mm = mmap.mmap(fileno=-1, length=1024 * 1024, access=mmap.ACCESS_READ, tagname='share_mmap')
return self.mm
# 训练CNN网络线程
class TrainCNNThread(QThread):
sendlog = pyqtSignal(object)
def __init__(self, mUtil, parent=None):
super(TrainCNNThread, self).__init__(parent)
self.stoped = False
self.mUtil = mUtil
self.mutex = QMutex()
def close_keras_sesion(self):
print('close_keras_sesion...')
from keras import backend as K
K.clear_session()
self.exit(0)
pass
def run(self):
with QMutexLocker(self.mutex):
print('in run method,start to send signal!')
self.stoped = False
from train_gesture_model import TrainGestureModeByCNN
train_net_obj = TrainGestureModeByCNN()
train_net_obj.trainModel(train_set_path='train_set', weight_name='myNewCnnModel.hdf5')
self.sendlog.emit(' ')
# 静态图像采集线程
class StaticVideoCollectionThread(QThread):
sendlog = pyqtSignal(object)
sendlog_recog = pyqtSignal(object)
# 使用二值化模型
def binaryMask(self, frame, x0, y0, width, height):
# print('use binaryMask model ...')
minValue = 70
# 创建矩形框
cv2.rectangle(frame, (x0, y0), (x0 + width, y0 + height), (0, 255, 0), 1)
roi = frame[y0:y0 + height, x0:x0 + width]
# 获取灰度图像
gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
# 高斯模糊:高斯滤波器中像素的权重与其距中心像素的距离成比例
blur = cv2.GaussianBlur(gray, (5, 5), 2)
# 图像的二值化提取目标,动态自适应的调整属于自己像素点的阈值,而不是整幅图像都用一个阈值
th3 = cv2.adaptiveThreshold(blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2)
ret, res = cv2.threshold(th3, minValue, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
return res
# 使用肤色检测模型
def skinMask(self, frame, x0, y0, width, height):
print('use skin model ...')
# HSV values
low_range = np.array([0, 50, 80])
upper_range = np.array([30, 200, 255])
cv2.rectangle(frame, (x0, y0), (x0 + width, y0 + height), (0, 255, 0), 1)
roi = frame[y0:y0 + height, x0:x0 + width]
hsv = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
# 设阈值,去除背景部分,低于这个lower_red的值,图像值变为0,高于这个upper_red的值,图像值变为0
mask = cv2.inRange(hsv, low_range, upper_range)
#腐蚀操作,减少整幅图像的白色区域
mask = cv2.erode(mask, skinkernel, iterations=1)
#膨胀操作,增加图像中的白色区域
mask = cv2.dilate(mask, skinkernel, iterations=1)
# 用高斯分布权值矩阵与原始图像矩阵做卷积运算
mask = cv2.GaussianBlur(mask, (15, 15), 1)
# cv2.imshow("Blur", mask)
# 图像与运算
res = cv2.bitwise_and(roi, roi, mask=mask)
# color to grayscale
res = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
return res
def __init__(self, video_recongize_obj, parent=None):
super(StaticVideoCollectionThread, self).__init__(parent)
self.stoped = False
self.mutex = QMutex()
self.cap = None
self.mm = mmap.mmap(fileno=-1, length=1024 * 1024, access=mmap.ACCESS_WRITE, tagname='share_mmap')
self.video_recongize_obj = video_recongize_obj
def run(self):
with QMutexLocker(self.mutex):
print('in run method,start to send signal!')
self.stoped = False
# if self.cap == None :
self.cap = cv2.VideoCapture(0)
ret = self.cap.set(3, 640)
ret = self.cap.set(4, 480)
while True:
if self.stoped:
break
ret, frame = self.cap.read()
max_area = 0
frame = cv2.flip(frame, 3)
x0 = 400
y0 = 200
height = 200
width = 200
# 使用肤色检测模型
if self.video_recongize_obj.flag_enable_skin_extraction_model:
roi_frame = self.skinMask(frame, x0, y0, width, height)
else:
# 使用高斯二值化模型
roi_frame = self.binaryMask(frame, x0, y0, width, height)
fram_dict = {}
fram_dict['frame'] = frame
fram_dict['roi_frame'] = roi_frame
self.mm.seek(0)
frame_size = len(frame.tostring())
roi_frame_size = len(roi_frame.tostring())
self.mm.write(frame.tostring())
self.mm.write(roi_frame.tostring())
self.sendlog.emit(str(frame_size))
self.sendlog_recog.emit(str(roi_frame_size))
# print('start to send signal!')
time.sleep(0.3)
self.cap.release()
def stop(self):
with QMutexLocker(self.mutex):
self.stoped = True
def isStoped(self):
with QMutexLocker(self.mutex):
return self.stoped
# 批量处理静态图片识别线程
class BatchProcessImgsThread(QThread):
sendlog = pyqtSignal(object)
def __init__(self, pic_recog_obj, mUtil, parent=None):
super(BatchProcessImgsThread, self).__init__(parent)
self.stoped = False
self.mutex = QMutex()
self.pic_recog_obj = pic_recog_obj
self.mUtil = mUtil
def run(self):
with QMutexLocker(self.mutex):
print('in BatchProcessImgsThread run method,start to send signal!')
self.stoped = False
if self.mUtil.mGesture is None:
self.mUtil.gestureLoadNN()
self.pic_recog_obj.getImgListPath(set_path=self.pic
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于CNN的静态手势识别系统 (3363个子文件)
title.png 104KB
gesture.png 49KB
fail.png 6KB
ok.png 6KB
five_215.png 3KB
five_213.png 3KB
five_315.png 3KB
five_314.png 3KB
five_313.png 3KB
five_214.png 3KB
five_365.png 3KB
five_366.png 3KB
five_367.png 3KB
five_357.png 3KB
five_356.png 3KB
five_358.png 3KB
five_317.png 3KB
five_355.png 3KB
five_316.png 3KB
five_318.png 3KB
five_361.png 3KB
five_360.png 3KB
five_359.png 3KB
five_342.png 3KB
five_340.png 3KB
five_341.png 3KB
five_363.png 3KB
five_364.png 3KB
five_362.png 3KB
five_352.png 3KB
five_354.png 3KB
five_353.png 3KB
five_343.png 3KB
five_345.png 3KB
five_344.png 3KB
five_211.png 3KB
five_212.png 3KB
five_210.png 3KB
five_217.png 3KB
five_216.png 3KB
five_218.png 3KB
five_220.png 3KB
five_221.png 3KB
five_219.png 3KB
five_208.png 3KB
five_207.png 3KB
five_209.png 3KB
five_349.png 3KB
five_350.png 3KB
five_351.png 3KB
five_72.png 3KB
five_71.png 3KB
five_246.png 3KB
five_247.png 3KB
five_248.png 3KB
five_338.png 3KB
five_337.png 3KB
five_339.png 3KB
five_335.png 3KB
five_334.png 3KB
five_336.png 3KB
five_321.png 3KB
five_319.png 3KB
five_320.png 3KB
five_68.png 3KB
five_70.png 3KB
five_66.png 3KB
five_67.png 3KB
five_65.png 3KB
five_69.png 3KB
five_388.png 3KB
five_386.png 3KB
five_387.png 3KB
five_108.png 3KB
five_328.png 3KB
five_329.png 3KB
five_330.png 3KB
five_223.png 3KB
five_222.png 3KB
five_331.png 3KB
five_332.png 3KB
five_333.png 3KB
five_237.png 3KB
five_239.png 3KB
five_238.png 3KB
five_384.png 3KB
five_383.png 3KB
five_385.png 3KB
five_396.png 3KB
five_395.png 3KB
five_230.png 3KB
five_228.png 3KB
five_397.png 3KB
five_369.png 3KB
five_370.png 3KB
five_368.png 3KB
five_393.png 3KB
five_394.png 3KB
five_392.png 3KB
five_250.png 3KB
共 3363 条
- 1
- 2
- 3
- 4
- 5
- 6
- 34
xiaopangzi313
- 粉丝: 684
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Semantic Color Palette 语义调色板Unity游戏开发插件资源unitypackage
- Low Poly Nature:Lush and Diverse Environments低聚自然郁郁Unity低多边形模型资源
- voc数据集是什么-我们如何使用voc数据集
- Edgar Pro-Procedural Level Generator程序关卡生成器Unity开发插件unitypackage
- 宝藏软件m3u8下载器\m3u8DL-CLI
- 三次样条插值的介绍-什么是三次样条插值原理
- http的一些相关介绍-对于我们来说什么是http
- 全卷积网络基于voc2012数据集简单pytorch实现
- pycharm的一些介绍-用于更好的学习python
- 基于C++的程序设计大赛天梯赛L2答案(天梯赛)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页