-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnegative_samples_creator.py
More file actions
47 lines (36 loc) · 941 Bytes
/
negative_samples_creator.py
File metadata and controls
47 lines (36 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""capture video stream frm camera and saves evry frame to .jpg file. It also creates file that contains list of every created image file.
"""
import sys
import cv2
import numpy as np
import time
if __name__ == "__main__":
try:
i = int(sys.argv[1])
except:
i = 0
print "Opening camera..."
camera = cv2.VideoCapture(0)
working = 0
cv2.namedWindow("Camera")
if camera.isOpened():
with open("training_data/bg.txt", "a") as f:
while True:
retval, image = camera.read()
if retval:
flipped = cv2.flip(image, 1)
cv2.imshow("Camera", flipped)
name = "bg_img/image" + str(i) + ".jpg"
i += 1
r = cv2.imwrite("training_data/" + name, flipped)
f.write(name + "\n")
print r
if not working:
print "Camera is working now..."
working = 1
#break on Escape
key = cv2.waitKey(20)
if key == 27:
break
else:
print "Camera is not opened"