管道
源代码
Python
PythonGitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5import argparse
6from pathlib import Path
7
8parser = argparse.ArgumentParser()
9parser.add_argument("-o", "--output", default="recordings", help="Output path")
10parser.add_argument("-fps", "--fps", default=30, type=int, help="FPS for recording")
11args = parser.parse_args()
12
13# Create output directory if it doesn't exist
14Path(args.output).mkdir(parents=True, exist_ok=True)
15
16# Create pipeline
17with dai.Pipeline(True) as pipeline:
18 config = dai.RecordConfig()
19 config.outputDir = args.output
20 # config.videoEncoding.enabled = True
21 # config.videoEncoding.bitrate = 0 # Automatic
22 # config.videoEncoding.profile = dai.VideoEncoderProperties.Profile.H264_MAIN
23
24 pipeline.enableHolisticRecord(config)
25
26 # Define source and output
27 camA = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
28 camAOut = camA.requestFullResolutionOutput(fps=args.fps)
29 camB = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
30 camBOut = camB.requestFullResolutionOutput(fps=args.fps)
31 camC = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
32 camCOut = camC.requestFullResolutionOutput(fps=args.fps)
33
34 viewFinderOut = camA.requestOutput((640, 480), fps=args.fps)
35
36 imu = pipeline.create(dai.node.IMU)
37 imu.enableIMUSensor(dai.IMUSensor.ACCELEROMETER_RAW, 400)
38 imu.enableIMUSensor(dai.IMUSensor.GYROSCOPE_RAW, 400)
39 imu.setBatchReportThreshold(100)
40
41 sync = pipeline.create(dai.node.Sync)
42 sync.setSyncAttempts(0)
43 camAOut.link(sync.inputs["camA"])
44 camBOut.link(sync.inputs["camB"])
45 camCOut.link(sync.inputs["camC"])
46
47 viewFinderQueue = viewFinderOut.createOutputQueue()
48
49 # Connect to device and start pipeline
50 pipeline.start()
51 try:
52 while pipeline.isRunning():
53 frame = viewFinderQueue.get()
54 cv2.imshow("video", frame.getCvFrame())
55 if cv2.waitKey(1) == ord('q'):
56 break
57 except KeyboardInterrupt:
58 pass
59
60 pipeline.stop()需要帮助?
请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。