RGB 全分辨率保存器
RGB 全分辨率保存器
c 键时保存全分辨率 3840x2160 的 .jpeg 图像。 它作为记录高分辨率帧到磁盘的示例,用于生成高分辨率的地面真实数据。请注意,每帧会消耗 2MB 以上的存储空间,因此“滥用”捕获键可能会填满您的存储空间。类似示例:
演示
设置
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py源代码
Python
PythonGitHub
1#!/usr/bin/env python3
2
3import time
4from pathlib import Path
5import cv2
6import depthai as dai
7
8# Create pipeline
9pipeline = dai.Pipeline()
10
11camRgb = pipeline.create(dai.node.ColorCamera)
12camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
13camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K)
14
15xoutRgb = pipeline.create(dai.node.XLinkOut)
16xoutRgb.setStreamName("rgb")
17camRgb.video.link(xoutRgb.input)
18
19xin = pipeline.create(dai.node.XLinkIn)
20xin.setStreamName("control")
21xin.out.link(camRgb.inputControl)
22
23# Properties
24videoEnc = pipeline.create(dai.node.VideoEncoder)
25videoEnc.setDefaultProfilePreset(1, dai.VideoEncoderProperties.Profile.MJPEG)
26camRgb.still.link(videoEnc.input)
27
28# Linking
29xoutStill = pipeline.create(dai.node.XLinkOut)
30xoutStill.setStreamName("still")
31videoEnc.bitstream.link(xoutStill.input)
32
33# Connect to device and start pipeline
34with dai.Device(pipeline) as device:
35
36 # Output queue will be used to get the rgb frames from the output defined above
37 qRgb = device.getOutputQueue(name="rgb", maxSize=30, blocking=False)
38 qStill = device.getOutputQueue(name="still", maxSize=30, blocking=True)
39 qControl = device.getInputQueue(name="control")
40
41 # Make sure the destination path is present before starting to store the examples
42 dirName = "rgb_data"
43 Path(dirName).mkdir(parents=True, exist_ok=True)
44
45 while True:
46 inRgb = qRgb.tryGet() # Non-blocking call, will return a new data that has arrived or None otherwise
47 if inRgb is not None:
48 frame = inRgb.getCvFrame()
49 # 4k / 4
50 frame = cv2.pyrDown(frame)
51 frame = cv2.pyrDown(frame)
52 cv2.imshow("rgb", frame)
53
54 if qStill.has():
55 fName = f"{dirName}/{int(time.time() * 1000)}.jpeg"
56 with open(fName, "wb") as f:
57 f.write(qStill.get().getData())
58 print('Image saved to', fName)
59
60 key = cv2.waitKey(1)
61 if key == ord('q'):
62 break
63 elif key == ord('c'):
64 ctrl = dai.CameraControl()
65 ctrl.setCaptureStill(True)
66 qControl.send(ctrl)
67 print("Sent 'still' event to the camera!")管道
需要帮助?
请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。