From 8cafc9b678391cadf4a28c9077502eb9cce9191f Mon Sep 17 00:00:00 2001 From: marzzelo Date: Fri, 26 Jan 2024 09:05:47 -0300 Subject: [PATCH] Add max_num_hands parameter to Hands class (set to 1). Skip non-directory files in dataset creation (like .gitignore). Display some status messages during serialization. --- .gitignore | 13 +++++++++++++ create_dataset.py | 9 +++++++-- data/.gitignore | 4 ++-- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..01cb87eb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +*.pickle + +# Byte-compiled / optimized / DLL files +__pycache__/ + +# Jupyter Notebook +.ipynb_checkpoints + +# Environments +.env +.venv +env/ +venv/ diff --git a/create_dataset.py b/create_dataset.py index cf3aebd9a..f69b47fec 100644 --- a/create_dataset.py +++ b/create_dataset.py @@ -3,21 +3,25 @@ import mediapipe as mp import cv2 -import matplotlib.pyplot as plt mp_hands = mp.solutions.hands mp_drawing = mp.solutions.drawing_utils mp_drawing_styles = mp.solutions.drawing_styles -hands = mp_hands.Hands(static_image_mode=True, min_detection_confidence=0.3) +hands = mp_hands.Hands(static_image_mode=True, min_detection_confidence=0.3, max_num_hands=1) DATA_DIR = './data' data = [] labels = [] for dir_ in os.listdir(DATA_DIR): + # skip files (like .gitignore) + if not os.path.isdir(os.path.join(DATA_DIR, dir_)): + continue + for img_path in os.listdir(os.path.join(DATA_DIR, dir_)): + print(f'Processing {dir_}/{img_path}...') data_aux = [] x_ = [] @@ -48,3 +52,4 @@ f = open('data.pickle', 'wb') pickle.dump({'data': data, 'labels': labels}, f) f.close() +print('Data saved to data.pickle') diff --git a/data/.gitignore b/data/.gitignore index ffb3cdb2c..593bcf0e8 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -1,2 +1,2 @@ -.gitignore - +!.gitignore +*