Skip to content

Instantly share code, notes, and snippets.

@theSekyi
Created June 11, 2019 18:12
Show Gist options
  • Select an option

  • Save theSekyi/8e35049160fd3691297adbf2c21d77b1 to your computer and use it in GitHub Desktop.

Select an option

Save theSekyi/8e35049160fd3691297adbf2c21d77b1 to your computer and use it in GitHub Desktop.
'''
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 timeloop import Timeloop
from utilities import create_folder_for_dataset
import cv2 as cv
import os
import imutils
import numpy as np
import time
tl = Timeloop()
#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()
current_time = int(time.time()*1000)
user_hash = args.user_hash
print('Loading model..')
cam = cv.VideoCapture(0)
create_folder_for_dataset(user_hash,today)
confidence_d = 0.5
total = 0
@tl.job(interval=timedelta(seconds=2))
def take_pic_every_2_secs(frame):
time.sleep(2)
cv.imwrite(f'data/{user_hash}/{today}/{current_time}.png',frame)
while True:
#capture each frame
ret, frame = cam.read()
#resize frame
frame = imutils.resize(frame,width=1000, height=1000)
take_pic_every_2_secs(frame)
#release video capture object
cam.release()
#closes all the frames
cv.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment