Created
March 2, 2018 18:34
-
-
Save ardamavi/af57bed01624009083d9fd50820bb441 to your computer and use it in GitHub Desktop.
Create Dataset Process for ours Sign Language Digits Dataset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Arda Mavi | |
# For https://github.com/ardamavi/Sign-Language-Digits-Dataset | |
import os | |
import cv2 | |
import platform | |
import numpy as np | |
from scipy.misc import imresize, imsave | |
img_size = 100 | |
channel_size = 3 | |
def main(): | |
if not os.path.exists('Created_Data/'): | |
os.makedirs('Created_Data/') | |
for i in range(0,11): | |
if not os.path.exists('Created_Data/{0}'.format(i)): | |
os.makedirs('Created_Data/{0}'.format(i)) | |
print('Press "ESC" button for exit.') | |
cap = cv2.VideoCapture(0) | |
while 1: | |
ret, img = cap.read() | |
# Cropping image: | |
img_height, img_width = img.shape[:2] | |
side_width = int((img_width-img_height)/2) | |
img = img[0:img_height, side_width:side_width+img_height] | |
# Show window: | |
cv2.imshow('Sesgoritma - Create Data', img) | |
inpt = cv2.waitKey(200) | |
if inpt == 27: # Decimal 27 = Esc | |
break | |
elif 47 < inpt and inpt < 58: | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | |
img = imresize(img, (img_size, img_size, channel_size)) | |
while 1: | |
file_name = np.random.randint(10000, size=1)[0] | |
if not os.path.exists('Created_Data/{0}/IMG_{1}.JPG'.format(inpt-48, file_name)): | |
imsave('Created_Data/{0}/IMG_{1}.JPG'.format(inpt-48, file_name), img) | |
break | |
cap.release() | |
cv2.destroyAllWindows() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment