Skip to content

Instantly share code, notes, and snippets.

@theSekyi
Last active June 12, 2019 18:42
Show Gist options
  • Select an option

  • Save theSekyi/286864bfe0fc5dd10bddcae99b68b7eb to your computer and use it in GitHub Desktop.

Select an option

Save theSekyi/286864bfe0fc5dd10bddcae99b68b7eb to your computer and use it in GitHub Desktop.
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)
time.sleep(20)
'''
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,take_pic_every_n_secs
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
print('Loading model..')
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)
t = threading.Thread
t = t(target=take_pic_every_n_secs,args=(frame,user_hash,today))
t.start()
#release video capture object
cam.release()
#closes all the frames
cv.destroyAllWindows()
t = threading.Thread
t = t(target=take_pic_every_n_secs,args=(frame,user_hash,today))
t.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment