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
47 changes: 47 additions & 0 deletions CaptureImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import sys
import cv2
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order imports alphabetically.



def main() :

Copy link
Copy Markdown

@RJ722 RJ722 Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line.

gestureClass = input("Enter the type of gesture")
imageName = input("Enter the image name")

cap = cv2.VideoCapture(0)
rootName = 'HandGestures/' + gestureClass
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use os.path.join. Joining using / is always a bad idea.


try:
if(not os.path.exists(rootName)):
os.makedirs(rootName)
except OSError:
print('Directory Exists')
sys.exit(0)

currentFrame = 0

while(True):

if(not cap.isOpened()):
cap.open()

ret, frame = cap.read()
frame = cv2.resize(frame, (128, 128))
cv2.imshow('frame', frame)

path = os.path.join("./", rootName)
print(path)

cv2.imwrite(path+"/{}{}.jpg".format(imageName, currentFrame), frame)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment, use os.path.join

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, remove unnecessary new lines. What editor do you use? You can generally find these exceptions using a linter like flake8/pep8 while writing code. Try installing one of those.


if(cv2.waitKey(0) & 0xFF == ord('q')):
break
currentFrame+=1

cap.release()
cv2.destroyAllWindows()


if __name__ == '__main__':
main()