This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPeriodicImageTaker.py
65 lines (48 loc) · 1.62 KB
/
PeriodicImageTaker.py
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
#!/usr/bin/env python3
import cv2
import depthai as dai
import os
import time
#delay between captures
delay = 0.5
# Create pipeline
pipeline = dai.Pipeline()
# Define source and output
camRgb = pipeline.create(dai.node.ColorCamera)
xoutRgb = pipeline.create(dai.node.XLinkOut)
xoutRgb.setStreamName("rgb")
# Properties
camRgb.setPreviewSize(640,640)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
camRgb.setInterleaved(False)
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB)
camRgb.setFps(60)
# Linking
camRgb.video.link(xoutRgb.input)
# Connect to device and start pipeline
with dai.Device(pipeline) as device:
print('Connected cameras: ', device.getConnectedCameras())
# Print out usb speed
print('Usb speed: ', device.getUsbSpeed().name)
# Output queue will be used to get the rgb frames from the output defined above
qRgb = device.getOutputQueue(name="rgb", maxSize=4, blocking=False)
# Set up folders to store images
path = "./"
path += input("Enter Folder Name Here: ")
print("Creating ...")
os.mkdir(path)
print("Folder Created")
count = 0
ctime = time.time() - delay
while True:
inRgb = qRgb.get() # blocking call, will wait until a new data has arrived
# Retrieve 'bgr' (opencv format) frame
frame = inRgb.getCvFrame()
if time.time() - ctime >= delay:
ctime = time.time()
cv2.imwrite(path+'/'+str(count)+'.png', frame)
print("Saved Image " + str(count))
count += 1
cv2.imshow("rgb", frame)
if cv2.waitKey(1) == ord('q'):
break