Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions PictureTaker/PictureTaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Date: 8/8/21
# Description:
# This program takes pictures (in .jpg format) from a connected webcam and saves
# them in the specified directory. The default directory is 'Pics' and the
# them in the specified directory. The default directory is 'image' and the
# default resolution is 1280x720.
#
# Example usage to save images in a directory named Sparrow at 1920x1080 resolution:
Expand All @@ -18,9 +18,9 @@
# Define and parse input arguments
parser = argparse.ArgumentParser()
parser.add_argument('--imgdir', help='Folder to save images in (will be created if it doesn\'t exist already',
default='Pics')
default='image')
parser.add_argument('--resolution', help='Desired camera resolution in WxH.',
default='1280x720')
default='1920x1080')

args = parser.parse_args()
dirname = args.imgdir
Expand All @@ -37,7 +37,7 @@
os.makedirs(dirpath)

# If images already exist in directory, increment image number so existing images aren't overwritten
# Example: if 'Pics-0.jpg' through 'Pics-10.jpg' already exist, imnum will be incremented to 11
# Example: if 'image-0.jpg' through 'image-10.jpg' already exist, imnum will be incremented to 11
basename = dirname
imnum = 1
img_exists = True
Expand All @@ -56,15 +56,18 @@
ret = cap.set(4, imH)

# Initialize display window
winname = 'Press \"p\" to take a picture!'
cv2.namedWindow(winname)
cv2.moveWindow(winname,50,30)
winname = 'Press \"p\" to take a picture and Press \"q\" to exit!'
cv2.namedWindow(winname, cv2.WINDOW_NORMAL)
cv2.moveWindow(winname, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

print('Press p to take a picture. Pictures will automatically be saved in the %s folder.' % dirname)
print('Press q to quit.')

while True:
hasFrame, frame = cap.read()
cv2.putText(frame, f'Images Taken: {imnum - 1}', (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)

cv2.imshow(winname,frame)

key = cv2.waitKey(1)
Expand Down