Hand detection adn cropping
38
crop_hand.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import os
|
||||||
|
from cvzone.HandTrackingModule import HandDetector
|
||||||
|
import cv2
|
||||||
|
|
||||||
|
|
||||||
|
def crop_hand(img, detector, offset=30):
|
||||||
|
hands, det_img = detector.findHands(img.copy())
|
||||||
|
if hands:
|
||||||
|
hand = hands[0]
|
||||||
|
x, y, w, h = hand['bbox']
|
||||||
|
img_crop = img[y - offset:y + h + offset, x - offset:x + w + offset]
|
||||||
|
return img_crop
|
||||||
|
return img
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
input_path = "test_data"
|
||||||
|
output_path = "test_data_cropped"
|
||||||
|
dir_list = os.listdir(input_path)
|
||||||
|
detector = HandDetector(maxHands=1)
|
||||||
|
|
||||||
|
for sign in dir_list:
|
||||||
|
if not os.path.exists(output_path + '/' + sign):
|
||||||
|
os.mkdir(output_path + '/' + sign)
|
||||||
|
for img_name in os.listdir(input_path + '/' + sign):
|
||||||
|
file_path = input_path + '/' + sign + '/' + img_name
|
||||||
|
output_file_path = output_path + '/' + sign + '/cropped_' + img_name
|
||||||
|
|
||||||
|
img = cv2.imread(file_path)
|
||||||
|
img_crop = crop_hand(img, detector)
|
||||||
|
try:
|
||||||
|
cv2.imwrite(output_file_path, img_crop)
|
||||||
|
except:
|
||||||
|
cv2.imwrite(output_file_path, img)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@ -1,4 +1,6 @@
|
|||||||
streamlit
|
streamlit
|
||||||
pandas
|
pandas
|
||||||
tensorflow
|
tensorflow
|
||||||
numpy
|
numpy
|
||||||
|
cvzone
|
||||||
|
mediapipe
|
BIN
test_data_cropped/A/cropped_A0 (2).jpg
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
test_data_cropped/A/cropped_A0 (3).jpg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
test_data_cropped/A/cropped_A0 (4).jpg
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
test_data_cropped/A/cropped_A0 (5).jpg
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
test_data_cropped/A/cropped_A0.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
test_data_cropped/A/cropped_IMG_9011 Mały.jpeg
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
test_data_cropped/A/cropped_a12.jpg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
test_data_cropped/B/cropped_B0 (2).jpg
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
test_data_cropped/B/cropped_B0 (3).jpg
Normal file
After Width: | Height: | Size: 7.2 KiB |
BIN
test_data_cropped/B/cropped_B0 (4).jpg
Normal file
After Width: | Height: | Size: 7.3 KiB |
BIN
test_data_cropped/B/cropped_B0.jpg
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
test_data_cropped/B/cropped_IMG_9012 Mały.jpeg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
test_data_cropped/B/cropped_b1 (8).jpg
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
test_data_cropped/C/cropped_C1 (3).jpg
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
test_data_cropped/C/cropped_C1 (4).jpg
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
test_data_cropped/C/cropped_C1 (5).jpg
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
test_data_cropped/C/cropped_C1 (6).jpg
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
test_data_cropped/C/cropped_C1 (7).jpg
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
test_data_cropped/C/cropped_C1 - Copy.jpg
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
test_data_cropped/C/cropped_IMG_9013 Mały.jpeg
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
test_data_cropped/D/cropped_IMG_9014 Mały.jpeg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
test_data_cropped/D/cropped_bfritzd1.png
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
test_data_cropped/D/cropped_bfritzd2.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
test_data_cropped/D/cropped_bfritzd3.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
test_data_cropped/D/cropped_ckaised1.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
test_data_cropped/D/cropped_ckaised2.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
test_data_cropped/D/cropped_ckaised3.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
test_data_cropped/D/cropped_color_3_0002.png
Normal file
After Width: | Height: | Size: 311 B |
BIN
test_data_cropped/E/cropped_IMG_9015 Mały.jpeg
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
test_data_cropped/E/cropped_color_4_0002 (2).png
Normal file
After Width: | Height: | Size: 336 B |
BIN
test_data_cropped/E/cropped_color_4_0002 (3).png
Normal file
After Width: | Height: | Size: 443 B |
BIN
test_data_cropped/E/cropped_color_4_0002 (4).png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
test_data_cropped/E/cropped_color_4_0002 (5).png
Normal file
After Width: | Height: | Size: 365 B |
BIN
test_data_cropped/E/cropped_color_4_0002.png
Normal file
After Width: | Height: | Size: 266 B |
BIN
test_data_cropped/E/cropped_color_4_0003 (2).png
Normal file
After Width: | Height: | Size: 130 B |
BIN
test_data_cropped/E/cropped_color_4_0003 (3).png
Normal file
After Width: | Height: | Size: 658 B |
BIN
test_data_cropped/E/cropped_color_4_0003 (4).png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
test_data_cropped/E/cropped_color_4_0003.png
Normal file
After Width: | Height: | Size: 416 B |
BIN
test_data_cropped/F/cropped_IMG_9016 Mały.jpeg
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
test_data_cropped/F/cropped_color_5_0002 (2).png
Normal file
After Width: | Height: | Size: 259 B |
BIN
test_data_cropped/F/cropped_color_5_0002 (3).png
Normal file
After Width: | Height: | Size: 471 B |
BIN
test_data_cropped/F/cropped_color_5_0002 (4).png
Normal file
After Width: | Height: | Size: 127 B |
BIN
test_data_cropped/F/cropped_color_5_0002 (5).png
Normal file
After Width: | Height: | Size: 154 B |
BIN
test_data_cropped/F/cropped_color_5_0002.png
Normal file
After Width: | Height: | Size: 397 B |
BIN
test_data_cropped/F/cropped_color_5_0003 (2).png
Normal file
After Width: | Height: | Size: 212 B |
BIN
test_data_cropped/F/cropped_color_5_0003.png
Normal file
After Width: | Height: | Size: 399 B |
BIN
test_data_cropped/G/cropped_IMG_9017 Mały.jpeg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
test_data_cropped/G/cropped_bfritzg1.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
test_data_cropped/G/cropped_bfritzg2.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
test_data_cropped/G/cropped_bfritzg3.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
test_data_cropped/G/cropped_ckaiseg1.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
test_data_cropped/G/cropped_ckaiseg2.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
test_data_cropped/G/cropped_ckaiseg3.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
test_data_cropped/G/cropped_color_6_0002 (2).png
Normal file
After Width: | Height: | Size: 986 B |
BIN
test_data_cropped/G/cropped_color_6_0002 (3).png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
test_data_cropped/G/cropped_color_6_0002 (4).png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
test_data_cropped/G/cropped_color_6_0002.png
Normal file
After Width: | Height: | Size: 404 B |
BIN
test_data_cropped/H/cropped_IMG_9018 Mały.jpeg
Normal file
After Width: | Height: | Size: 9.9 KiB |
BIN
test_data_cropped/H/cropped_color_7_0003 (3).png
Normal file
After Width: | Height: | Size: 115 B |
BIN
test_data_cropped/H/cropped_color_7_0003 (4).png
Normal file
After Width: | Height: | Size: 56 KiB |
BIN
test_data_cropped/H/cropped_color_7_0003 (5).png
Normal file
After Width: | Height: | Size: 53 KiB |
BIN
test_data_cropped/H/cropped_color_7_0004 (2).png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
test_data_cropped/H/cropped_color_7_0004.png
Normal file
After Width: | Height: | Size: 181 B |
BIN
test_data_cropped/I/cropped_IMG_9022 Mały.jpeg
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
test_data_cropped/I/cropped_color_8_0003 (3).png
Normal file
After Width: | Height: | Size: 296 B |
BIN
test_data_cropped/I/cropped_color_8_0003 (4).png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
test_data_cropped/I/cropped_color_8_0003 (5).png
Normal file
After Width: | Height: | Size: 266 B |
BIN
test_data_cropped/I/cropped_color_8_0004 (2).png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
test_data_cropped/I/cropped_color_8_0004 (3).png
Normal file
After Width: | Height: | Size: 103 B |
BIN
test_data_cropped/I/cropped_color_8_0004 (4).png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
test_data_cropped/I/cropped_color_8_0004.png
Normal file
After Width: | Height: | Size: 236 B |
BIN
test_data_cropped/J/cropped_1.jpg
Normal file
After Width: | Height: | Size: 9.0 KiB |
BIN
test_data_cropped/J/cropped_2.jpg
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
test_data_cropped/J/cropped_3.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
test_data_cropped/J/cropped_4.jpg
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
test_data_cropped/J/cropped_5.jpg
Normal file
After Width: | Height: | Size: 8.8 KiB |
BIN
test_data_cropped/J/cropped_6.JPG
Normal file
After Width: | Height: | Size: 147 KiB |
BIN
test_data_cropped/J/cropped_IMG_9024 Mały.jpeg
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
test_data_cropped/K/cropped_IMG_9025 Mały.jpeg
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
test_data_cropped/K/cropped_color_10_0002 (2).png
Normal file
After Width: | Height: | Size: 189 B |
BIN
test_data_cropped/K/cropped_color_10_0002 (3).png
Normal file
After Width: | Height: | Size: 319 B |
BIN
test_data_cropped/K/cropped_color_10_0002 (4).png
Normal file
After Width: | Height: | Size: 415 B |
BIN
test_data_cropped/K/cropped_color_10_0002 (5).png
Normal file
After Width: | Height: | Size: 636 B |
BIN
test_data_cropped/K/cropped_color_10_0002.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
test_data_cropped/K/cropped_color_10_0003 (2).png
Normal file
After Width: | Height: | Size: 190 B |
BIN
test_data_cropped/K/cropped_color_10_0003 (3).png
Normal file
After Width: | Height: | Size: 244 B |
BIN
test_data_cropped/K/cropped_color_10_0003.png
Normal file
After Width: | Height: | Size: 736 B |
BIN
test_data_cropped/L/cropped_IMG_9026 Mały.jpeg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
test_data_cropped/L/cropped_color_11_0003 (3).png
Normal file
After Width: | Height: | Size: 438 B |
BIN
test_data_cropped/L/cropped_color_11_0003 (4).png
Normal file
After Width: | Height: | Size: 201 B |
BIN
test_data_cropped/L/cropped_color_11_0003 (5).png
Normal file
After Width: | Height: | Size: 45 KiB |
BIN
test_data_cropped/L/cropped_color_11_0004 (2).png
Normal file
After Width: | Height: | Size: 52 KiB |
BIN
test_data_cropped/L/cropped_color_11_0004.png
Normal file
After Width: | Height: | Size: 206 B |
BIN
test_data_cropped/M/cropped_IMG_9027 Mały.jpeg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
test_data_cropped/M/cropped_color_12_0004 (4).png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
test_data_cropped/M/cropped_color_12_0004 (5).png
Normal file
After Width: | Height: | Size: 280 B |
BIN
test_data_cropped/M/cropped_color_12_0005 (2).png
Normal file
After Width: | Height: | Size: 365 B |
BIN
test_data_cropped/M/cropped_color_12_0005 (3).png
Normal file
After Width: | Height: | Size: 444 B |