-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-data.py
More file actions
78 lines (61 loc) · 1.77 KB
/
create-data.py
File metadata and controls
78 lines (61 loc) · 1.77 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import cv2
import os
import time
#####################################################
myPath = (
"retainer-images-training/images" # Rasbperry Pi: '/home/pi/Desktop/data/images'
)
cameraNo = 0
cameraBrightness = 100
moduleVal = 10 # SAVE EVERY ITH FRAME TO AVOID REPETITION
minBlur = 500 # SMALLER VALUE MEANS MORE BLURRINESS PRESENT
grayImage = False # IMAGES SAVED COLORED OR GRAY
saveData = True # SAVE DATA FLAG
showImage = True # IMAGE DISPLAY FLAG
imgWidth = 180
imgHeight = 120
#####################################################
global countFolder
cap = cv2.VideoCapture(cameraNo)
cap.set(3, 640)
cap.set(4, 480)
cap.set(10, cameraBrightness)
count = 0
countSave = 0
def saveDataFunc():
global countFolder
countFolder = 0
while os.path.exists(myPath + str(countFolder)):
countFolder += 1
os.makedirs(myPath + str(countFolder))
if saveData:
saveDataFunc()
while True:
success, img = cap.read()
img = cv2.resize(img, (imgWidth, imgHeight))
if grayImage:
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
if saveData:
blur = cv2.Laplacian(img, cv2.CV_64F).var()
if count % moduleVal == 0 and blur > minBlur:
nowTime = time.time()
cv2.imwrite(
myPath
+ str(countFolder)
+ "/"
+ str(countSave)
+ "_"
+ str(int(blur))
+ "_"
+ str(nowTime)
+ ".png",
img,
)
countSave += 1
count += 1
if showImage:
cv2.imshow("Image", img)
if cv2.waitKey(1) & 0xFF == ord("0"):
break
cap.release()
cv2.destroyAllWindows()