still 图像。默认情况下,相机将以 (1333x1000) 帧流式传输到主机计算机,当用户按下 c 键时,它将以最高分辨率(对于 OAK4 相机为 48MP)捕获 still 图像,并将其保存到当前目录的 .png 文件中。OAK4 操作系统版本
如果您使用的是 OAK4 相机,请确保使用最新版本的 Luxonis OS(1.6 或更高版本)以获得 完整的 48MP 分辨率。
Pipeline
Source code
Python
PythonGitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5import numpy as np
6
7# Create pipeline
8with dai.Pipeline() as pipeline:
9 # Define source and output
10 cam = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
11 cam_q_in = cam.inputControl.createInputQueue()
12
13 cam_input_q = cam.inputControl.createInputQueue()
14 # In some cases (IMX586), this requires an 8k screen to be able to see the full resolution at once
15 stream_highest_res = cam.requestFullResolutionOutput(useHighestResolution=True)
16
17 script = pipeline.create(dai.node.Script)
18 stream_highest_res.link(script.inputs["in"])
19 # Current workaround for OAK4 cameras, as Camera node doesn't yet support "still" frame capture
20 script.setScript(
21 """
22 while True:
23 message = node.inputs["in"].get()
24 trigger = node.inputs["trigger"].tryGet()
25 if trigger is not None:
26 node.warn("Trigger received!")
27 node.io["highest_res"].send(message)
28 """)
29
30 # If 8k, we can only have 1 output stream, so we need to use ImageManip to downscale
31 imgManip = pipeline.create(dai.node.ImageManip)
32 stream_highest_res.link(imgManip.inputImage)
33 imgManip.initialConfig.setOutputSize(1333, 1000)
34 imgManip.setMaxOutputFrameSize(1333*1000*3)
35 downscaled_res_q = imgManip.out.createOutputQueue()
36
37 highest_res_q = script.outputs["highest_res"].createOutputQueue()
38 q_trigger = script.inputs["trigger"].createInputQueue()
39
40 # Connect to device and start pipeline
41 ctrl = dai.CameraControl()
42 pipeline.start()
43 print("To capture an image, press 'c'")
44 while pipeline.isRunning():
45 img_hd: dai.ImgFrame = downscaled_res_q.get()
46 frame = img_hd.getCvFrame()
47 cv2.imshow("video", frame)
48
49 key = cv2.waitKey(1)
50 if key == ord("q"):
51 break
52 if key == ord('c'):
53 # Send a trigger message to the Script node
54 q_trigger.send(dai.Buffer())
55
56 if highest_res_q.has():
57 highres_img = highest_res_q.get()
58 frame = highres_img.getCvFrame()
59 # Save the full image
60 cv2.imwrite("full_image.png", frame)需要帮助?
请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。