• 大小: 17.77MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-26
  • 语言: 其他
  • 标签: 手势识别  

资源简介

手势识别源码,用的算法是CNN,实施识别,运行系统包括windows和ubuntu

资源截图

代码片段和文件信息

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
“““
Created on Thu Apr  6 01:01:43 2017

@author: abhisheksingh
“““

from keras.models import Sequential
from keras.layers import Dense Dropout Activation Flatten
from keras.layers import Conv2D MaxPooling2D ZeroPadding2D
from keras.optimizers import SGDRMSpropadam
from keras.utils import np_utils

# We require this for Theano lib ONLY. Remove it for TensorFlow usage
from keras import backend as K
K.set_image_dim_ordering(‘th‘)

import numpy as np
#import matplotlib.pyplot as plt
import os
import theano
from PIL import Image
# SKLEARN
from sklearn.utils import shuffle
from sklearn.model_selection import train_test_split
import json

import cv2
import matplotlib
#matplotlib.use(“TkAgg“)
from matplotlib import pyplot as plt


# input image dimensions
img_rows img_cols = 200 200

# number of channels
# For grayscale use 1 value and for color images use 3 (RGB channels)
img_channels = 1


# Batch_size to train
batch_size = 32

## Number of output classes (change it accordingly)
## eg: In my case I wanted to predict 4 types of gestures (Ok Peace Punch Stop)
## NOTE: If you change this then dont forget to change Labels accordingly
nb_classes = 5

# Number of epochs to train (change it accordingly)
nb_epoch = 15  #25

# Total number of convolutional filters to use
nb_filters = 32
# Max pooling
nb_pool = 2
# Size of convolution kernel
nb_conv = 3

#%%
#  data
path = “./“
path1 = “./gestures“    #path of folder of images

## Path2 is the folder which is fed in to training model
path2 = ‘./imgfolder_b‘

WeightFileName = [“ori_4015imgs_weights.hdf5““bw_4015imgs_weights.hdf5““bw_2510imgs_weights.hdf5““./bw_weight.hdf5““./final_c_weights.hdf5““./semiVgg_1_weights.hdf5““/new_wt_dropout20.hdf5““./weights-CNN-gesture_skinmask.hdf5“]

# outputs
output = [“OK“ “NOTHING““PEACE“ “PUNCH“ “STOP“]
#output = [“PEACE“ “STOP“ “THUMBSDOWN“ “THUMBSUP“]



#%%
# This function can be used for converting colored img to Grayscale img
# while copying images from path1 to path2
def convertToGrayImg(path1 path2):
    listing = os.listdir(path1)
    for file in listing:
        if file.startswith(‘.‘):
            continue
        img = Image.open(path1 +‘/‘ + file)
        #img = img.resize((img_rowsimg_cols))
        grayimg = img.convert(‘L‘)
        grayimg.save(path2 + ‘/‘ +  file “PNG“)

#%%
def modlistdir(path):
    listing = os.listdir(path)
    retlist = []
    for name in listing:
        #This check is to ignore any hidden files/folders
        if name.startswith(‘.‘):
            continue
        retlist.append(name)
    return retlist


# Load CNN model
def loadCNN(wf_index):
    global get_output
    model = Sequential()
    
    
    model.add(Conv2D(nb_filters (nb_conv nb_conv)
                        padding=‘valid‘
                        input_shape=(img_channels img_rows img_cols)))
    convout1 = Activation(‘relu‘)
    model.add(convout1)
    model.add(Conv2D(nb_filters (nb_con

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-10-10 04:54  CNNGestureRecognizer-master\
     文件          43  2017-10-10 04:54  CNNGestureRecognizer-master\.gitattributes
     文件        1045  2017-10-10 04:54  CNNGestureRecognizer-master\.gitignore
     文件        1071  2017-10-10 04:54  CNNGestureRecognizer-master\LICENSE
     文件       10839  2017-10-10 04:54  CNNGestureRecognizer-master\README.md
     文件       12816  2017-10-10 04:54  CNNGestureRecognizer-master\gestureCNN.py
     文件      186106  2017-10-10 04:54  CNNGestureRecognizer-master\img_4_layer4_MaxPooling2D.png
     文件      357669  2017-10-10 04:54  CNNGestureRecognizer-master\img_7_layer2_Conv2D.png
     目录           0  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\
     文件        2399  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok1.png
     文件        2243  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok10.png
     文件        2056  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok100.png
     文件        2004  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok101.png
     文件        2311  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok102.png
     文件        2492  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok103.png
     文件        2605  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok104.png
     文件        2603  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok105.png
     文件        2541  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok106.png
     文件        2615  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok107.png
     文件        2703  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok108.png
     文件        2572  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok109.png
     文件        2304  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok11.png
     文件        2645  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok110.png
     文件        2698  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok111.png
     文件        2704  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok112.png
     文件        2699  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok113.png
     文件        2618  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok114.png
     文件        2655  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok115.png
     文件        2600  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok116.png
     文件        2594  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok117.png
     文件        2601  2017-10-10 04:54  CNNGestureRecognizer-master\imgfolder_b\iiiok118.png
............此处省略4003个文件信息

评论

共有 条评论