資源簡介
手勢識別,從獲取樣本到訓練測試都有代碼
需要keras,opencv,tensorflow等庫
代碼片段和文件信息
#?coding:?utf-8
from?tensorflow.keras.models?import?load_model
import?numpy?as?np
import?cv2
import?pickle
import?time
#預測框初始化
x0?=?400
y0?=?200
height?=?200
width?=?200
#幀率相關參數
framecount?=?0
fps?=?““
i?=?0
#開始時間
start?=?time.time()
#手勢處理函數(二值掩模)
def?binaryMask(frame?x0?y0?width?height):
????#只處理識別框部分
????cv2.rectangle(frame?(x0y0)(x0+widthy0+height)(02550)1)
????roi?=?frame[y0:y0+height?x0:x0+width]
????return?roi
#模型和標簽名
MODEL_NAME?=?“ss_model.h5“
LABEL_NAME?=?“ss_labels.dat“
#加載標簽
with?open(LABEL_NAME?“rb“)?as?f:
????lb?=?pickle.load(f)
#加載神經網絡
model?=?load_model(MODEL_NAME)
#打開攝像頭
cap?=?cv2.VideoCapture(0)
videowriter?=?cv2.VideoWriter(“predict.avi“cv2.VideoWriter_fourcc(‘M‘‘J‘‘P‘‘G‘)30(200200))
while(True):
????ret?frame?=?cap.read()
????frame?=?cv2.flip(frame?3)
????frame?=?cv2.resize(frame?(640480))
????if?ret?==?True:
????????roi?=?binaryMask(frame?x0?y0?width?height)
????????roi1?=?roi
????????roi1?=?cv2.resize(roi(100100))
?????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2301??2020-03-14?15:23??get_samples.py
?????文件????????3428??2020-05-26?16:09??network.py
?????文件????????2311??2020-05-26?16:26??ges_test.py
評論
共有 條評論