1 Star 0 Fork 3

mazaiting/人机交互期末项目

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
EXTRACT_DATA.py 2.32 KB
一键复制 编辑 原始数据 按行查看 历史
XCZJust 提交于 2022-12-22 11:57 . update
import cv2
import mediapipe as mp
import pandas as pd
import os
import numpy as np
def image_processed(file_path):
# reading the static image
hand_img = cv2.imread(file_path)
# Image processing
# 1. Convert BGR to RGB
img_rgb = cv2.cvtColor(hand_img, cv2.COLOR_BGR2RGB)
# 2. Flip the img in Y-axis
img_flip = cv2.flip(img_rgb, 1)
# accessing MediaPipe solutions
mp_hands = mp.solutions.hands
# Initialize Hands
hands = mp_hands.Hands(static_image_mode=True,
max_num_hands=2, min_detection_confidence=0.7)
# Results
output = hands.process(img_flip)
hands.close()
try:
data = output.multi_hand_landmarks[0]
data = str(data)
data = data.strip().split('\n')
garbage = ['landmark {', ' visibility: 0.0', ' presence: 0.0', '}']
without_garbage = []
for i in data:
if i not in garbage:
without_garbage.append(i)
clean = []
for i in without_garbage:
i = i.strip()
clean.append(i[2:])
for i in range(0, len(clean)):
clean[i] = float(clean[i])
return([clean])
except:
return(np.zeros([1,63], dtype=int)[0])
def make_csv():
mypath = 'RESIZED_DATASET'
file_name = open('dataSet/final_datasetBSL.csv', 'a')
for each_folder in os.listdir(mypath):
if '._' in each_folder:
pass
else:
for each_number in os.listdir(mypath + '/' + each_folder):
if '._' in each_number:
pass
else:
label = each_folder
file_loc = mypath + '/' + each_folder + '/' + each_number
data = image_processed(file_loc)
try:
for i in data[0]:
file_name.write(str(i))
file_name.write(',')
file_name.write(label)
file_name.write('\n')
except:
file_name.write('-1')
file_name.write(',')
file_name.write('None')
file_name.write('\n')
file_name.close()
print('Data Created !!!')
if __name__ == "__main__":
make_csv()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mazaiting/hand-gesture-recognition.git
git@gitee.com:mazaiting/hand-gesture-recognition.git
mazaiting
hand-gesture-recognition
人机交互期末项目
master

搜索帮助