Last active
June 13, 2019 15:42
-
-
Save theSekyi/2cb35ae5bd3335b020e39bc28cefeb90 to your computer and use it in GitHub Desktop.
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
| ''' | |
| STEPS | |
| 1. Take user_hash from command line | |
| 2. Set timer so it records after every 5 minutes | |
| 3. Store image in dataset/user_hash/date/store_by_timestamp | |
| ''' | |
| from argparse import ArgumentParser | |
| from datetime import date,datetime,timedelta | |
| from utilities import create_folder_for_dataset | |
| import cv2 as cv | |
| import os | |
| import imutils | |
| import numpy as np | |
| import time | |
| import threading | |
| #passing arguments from the terminal | |
| parser = ArgumentParser() | |
| parser.add_argument("-u","--user_hash") | |
| parser.add_argument("-q", "--quiet", | |
| action="store_false", dest="verbose", default=True, | |
| help="don't print status messages to stdout") | |
| args = parser.parse_args() | |
| today = date.today() | |
| user_hash = args.user_hash | |
| total = 0 | |
| cam = cv.VideoCapture(0) | |
| create_folder_for_dataset(user_hash,today) | |
| while True: | |
| #capture each frame | |
| ret, frame = cam.read() | |
| #resize frame | |
| frame = imutils.resize(frame,width=1000, height=1000) | |
| current_time = int(time.time()*1000) | |
| #save image | |
| cv.imwrite(f'data/{user_hash}/{today}/{current_time}.png',frame) | |
| print(f'Picture {total} saved') | |
| #counting number of images saved | |
| total += 1 | |
| #wait time before next image is saved | |
| time.sleep(300) | |
| #release video capture object | |
| cam.release() | |
| #closes all the frames | |
| cv.destroyAllWindows() | |
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
| import os | |
| def create_folder_for_dataset(user_hash,today): | |
| ''' | |
| Function to create folder and subfolder using the user_hash and | |
| current date | |
| ''' | |
| if not os.path.exists(f'data/{user_hash}'): | |
| os.makedirs(f'data/{user_hash}',exist_ok=True) | |
| print(f'{user_hash} directory created') | |
| os.makedirs(f'data/{user_hash}/{today}',exist_ok=True) | |
| else: | |
| os.makedirs(f'data/{user_hash}/{today}',exist_ok=True) | |
| # @tl.job(interval=timedelta(seconds=3000)) | |
| # def take_pic_every_n_secs(frame,user_hash,today): | |
| # current_time = int(time.time()*1000) | |
| # cv.imwrite(f'data/{user_hash}/{today}/{current_time}.png',frame) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment