Skip to content

Commit b802646

Browse files
authored
Add --gray_preview option to sai-cli record oak (#76)
* Add --gray_preview option to sai-cli record oak * Fix typo
1 parent 7c90fde commit b802646

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

python/cli/record/oak.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def define_args(p):
3838
p.add_argument("--no_rgb", help="Disable recording RGB video feed", action="store_true")
3939
p.add_argument("--no_inputs", help="Disable recording JSONL and depth", action="store_true")
4040
p.add_argument("--gray", help="Record (rectified) gray video data", action="store_true")
41+
p.add_argument("--gray_preview", help="Show live preview of (rectified) gray video", action="store_true")
4142
p.add_argument("--no_convert", help="Skip converting h265 video file", action="store_true")
4243
p.add_argument('--no_preview', help='Do not show a live preview', action="store_true")
4344
p.add_argument('--preview3d', help='Use more advanced visualizer instead of matplotlib', action="store_true")
@@ -220,6 +221,15 @@ def create_gray_encoder(node, name):
220221
create_gray_encoder(vio_pipeline.stereo.rectifiedLeft, 'left')
221222
create_gray_encoder(vio_pipeline.stereo.rectifiedRight, 'right')
222223

224+
if args.gray_preview:
225+
def create_gray_preview(node, name):
226+
xout_preview = pipeline.create(depthai.node.XLinkOut)
227+
xout_preview.setStreamName("gray-preview-" + name)
228+
node.link(xout_preview.input)
229+
230+
create_gray_preview(vio_pipeline.stereo.rectifiedLeft, 'left')
231+
create_gray_preview(vio_pipeline.stereo.rectifiedRight, 'right')
232+
223233
cameraControlQueueNames = []
224234
if args.white_balance or args.exposure or args.sensitivity:
225235
def create_rgb_camera_control(colorCameraNode):
@@ -249,18 +259,29 @@ def createDevice():
249259
if args.ir_dot_brightness > 0:
250260
device.setIrLaserDotProjectorBrightness(args.ir_dot_brightness)
251261

252-
def open_gray_video(name):
253-
grayVideoFile = open(outputFolder + '/rectified_' + name + '.h264', 'wb')
254-
queue = device.getOutputQueue(name='h264-' + name, maxSize=10, blocking=False)
255-
return (queue, grayVideoFile)
256-
257262
grayVideos = []
258263
if args.gray:
264+
def open_gray_video(name):
265+
grayVideoFile = open(outputFolder + '/rectified_' + name + '.h264', 'wb')
266+
queue = device.getOutputQueue(name='h264-' + name, maxSize=10, blocking=False)
267+
return (queue, grayVideoFile)
268+
259269
grayVideos = [
260270
open_gray_video('left'),
261271
open_gray_video('right')
262272
]
263273

274+
grayPreviews = []
275+
if args.gray_preview:
276+
def open_gray_preview(name):
277+
queue = device.getOutputQueue(name='gray-preview-' + name, maxSize=10, blocking=False)
278+
return (queue, name)
279+
280+
grayPreviews = [
281+
open_gray_preview('left'),
282+
open_gray_preview('right')
283+
]
284+
264285
if rgb_as_video:
265286
videoFile = open(outputFolder + "/rgb_video.h265", "wb")
266287
rgbQueue = device.getOutputQueue(name="h265-rgb", maxSize=30, blocking=False)
@@ -297,6 +318,14 @@ def open_gray_video(name):
297318
grayQueue.get().getData().tofile(grayVideoFile)
298319
progress = True
299320

321+
for (grayPreviewQueue, name) in grayPreviews:
322+
if grayPreviewQueue.has():
323+
import cv2
324+
frame = grayPreviewQueue.get().getCvFrame()
325+
cv2.imshow(name, frame)
326+
cv2.waitKey(1)
327+
progress = True
328+
300329
if vio_session.hasOutput():
301330
out = vio_session.getOutput()
302331
progress = True
@@ -320,6 +349,10 @@ def open_gray_video(name):
320349
videoFileNames.append(grayVideoFile.name)
321350
grayVideoFile.close()
322351

352+
if len(grayPreviews) > 0:
353+
import cv2
354+
cv2.destroyAllWindows()
355+
323356
for fn in videoFileNames:
324357
if not args.no_convert:
325358
withoutExt = fn.rpartition('.')[0]

0 commit comments

Comments
 (0)