# 摄像头

Camera 是一个统一的单一源节点，取代了独立的 [ColorCamera](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/color_camera.md) 和
[MonoCamera](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/mono_camera.md) 节点。 它生成
[ImgFrame](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/img_frame.md) 消息，可用于图像处理和神经网络推理。

## 关键特性

 * 当你未指定传感器分辨率和FPS时，自动选择 — 无需手动记录。

 * requestOutput()

```py
cam.requestOutput(size=(640, 480), type=dai.ImgFrame.Type.NV12,
                resize_mode=dai.ImgResizeMode.CROP,
                enableUndistortion=True)
```

 * 通过 enableUndistortion（默认 = None）为每个输出选择是否启用去畸变。 它不会自动应用于任何流。
 * 去畸变保留原始帧内参，这意味着有效视场角（FOV）通常在角落处略有减小，尤其是广角镜头。
 * requestFullResolutionOutput() 带有安全保护（除非传递 useHighestResolution=True，否则保持在 ≤ 5 K×4 K 以内）。
 * setMockIsp() 用于合成或录制的输入（附加 ReplayVideo 节点以提供预捕获帧）。

从 ColorCamera 或 MonoCamera 升级？只需查找替换节点创建代码，并删除任何手动的 setIspScale() 逻辑。

## 放置节点

#### Python

```python
with dai.Pipeline() as pipeline:
    cam = pipeline.create(dai.node.Camera)
    cam.build(dai.CameraBoardSocket.CAM_A)  # 可选——否则自动检测
```

#### C++

```cpp
// C++
dai::Pipeline pipeline;
auto cam = pipeline.create<dai::node::Camera>();
cam->build(dai::CameraBoardSocket::CAM_A);
```

## 输入与输出

### 缩放模式

 * 裁剪(Crop)：NN精度无下降。缺点：画面被裁剪，无法获得完整视场角。
 * 信箱模式(Letterbox)：保留完整视场角。缺点：较小的“画面”可能导致特征减少，降低NN精度。
 * 拉伸(Stretch)：保留完整视场角。缺点：由于画面被拉伸，NN精度可能下降。

```python
cam.requestOutput(size=(640, 480), type=dai.ImgFrame.Type.NV12,
                resize_mode=dai.ImgResizeMode.CROP)
cam.requestOutput(size=(640, 480), type=dai.ImgFrame.Type.NV12,
                resize_mode=dai.ImgResizeMode.RESIZE)
cam.requestOutput(size=(640, 480), type=dai.ImgFrame.Type.NV12,
                resize_mode=dai.ImgResizeMode.LETTERBOX)
```

## 使用示例

#### Python

```python
pipeline = dai.Pipeline()

cam = pipeline.create(dai.node.Camera)
cam.build(boardSocket=dai.CameraBoardSocket.CAM_A)

# 1) 用于视频编码器的低延迟预览
nn_in = cam.requestOutput(size=(300,300), type=dai.ImgFrame.Type.NV12, fps=30)

# 2) 用于录制的HD流
hd_out = cam.requestOutput(size=(1280,720), type=dai.ImgFrame.Type.BGR888p, fps=30)

# 3) 每秒一张全分辨率静态图
full = cam.requestFullResolutionOutput(type=dai.ImgFrame.Type.BGR888p, fps=1)

# 链接到下游节点……
```

#### C++

```cpp
auto cam = pipeline.create<dai::node::Camera>();
cam->build(dai::CameraBoardSocket::CAM_A);

auto nnIn  = cam->requestOutput({300, 300}, dai::ImgFrame::Type::NV12,
                                dai::ImgResizeMode::CROP, 30);
auto hdOut = cam->requestOutput({1280,720}, dai::ImgFrame::Type::BGR888p,
                                dai::ImgResizeMode::STRETCH, 30);
auto full  = cam->requestFullResolutionOutput(dai::ImgFrame::Type::BGR888p, 1);
```

## 平台特定限制

#### RVC2

ISP 持续处理能力约 600 MP/s（约 4K @ 30 fps）——在运行重型NN和视频编码器时需据此预算。 3A 运行在嵌入式微DSP上，所有摄像头流合计最高约 250 fps。

#### RVC4

参见 [RVC4 ISP 规格](https://docs.luxonis.com/hardware/platform/rvc/rvc4.md)

## 更多示例

 * [摄像头输出](https://docs.luxonis.com/software-v3/depthai/examples/camera/camera_output.md)
 * [摄像头ISP输出](https://docs.luxonis.com/software-v3/depthai/examples/camera/camera_isp.md)
 * [多路输出](https://docs.luxonis.com/software-v3/depthai/examples/camera/camera_all.md)
 * [去畸变流](https://docs.luxonis.com/software-v3/depthai/examples/camera/camera_undistort.md)

## API 参考

### dai::node::Camera

Kind: class

#### CameraControl initialControl

Kind: variable

Initial control options to apply to sensor

#### Input inputControl

Kind: variable

Input for CameraControl message, which can modify camera parameters in runtime

#### Input mockIsp

Kind: variable

Input for mocking 'isp' functionality on RVC2. Default queue is blocking with size 8

#### Output raw

Kind: variable

Outputs ImgFrame message that carries RAW10-packed (MIPI CSI-2 format) frame data. Captured directly from the camera sensor, and
the source for the 'isp' output.

#### OutputMap dynamicOutputs

Kind: variable

#### Node::Output * requestOutput(const std::pair< uint32_t, uint32_t > & size, std::optional< ImgFrame::Type > type,
ImgResizeMode resizeMode, std::optional< float > fps, std::optional< bool > enableUndistortion)

Kind: function

Get video output with specified size.

#### Node::Output * requestOutput(const Capability & capability, bool onHost)

Kind: function

Request output with advanced controls. Mainly to be used by custom node writers.

#### Node::Output * requestFullResolutionOutput(std::optional< ImgFrame::Type > type, std::optional< float > fps, bool
useHighestResolution)

Kind: function

Get a high resolution output with full FOV on the sensor. By default the function will not use the resolutions higher than
5000x4000, as those often need a lot of resources, making them hard to use in combination with other nodes. parameters: type: Type
of the output (NV12, BGR, ...) - by default it's auto-selected for best performance; fps: FPS of the output - by default it's
auto-selected to highest possible that a sensor config support or 30, whichever is lower; useHighestResolution: If true, the
function will use the highest resolution available on the sensor, even if it's higher than 5000x4000

#### Node::Output * requestIspOutput(std::optional< float > fps)

Kind: function

Request output with isp resolution. The fps does not vote.

#### std::shared_ptr< Camera > build(dai::CameraBoardSocket boardSocket, const std::optional< std::pair< uint32_t, uint32_t >> &
sensorResolution, std::optional< float > sensorFps)

Kind: function

Build with a specific board socket parameters: boardSocket: Board socket to use; sensorResolution: Sensor resolution to use - by
default it's auto-detected from the requested outputs; sensorFps: Sensor FPS to use - by default it's auto-detected from the
requested outputs (maximum is used)

#### std::shared_ptr< Camera > setSensorType(CameraSensorType sensorType)

Kind: function

Set the sensor type to use parameters: sensorType: Sensor type to use

#### CameraSensorType getSensorType()

Kind: function

Get the sensor type return: Sensor type

#### std::shared_ptr< Camera > setImageOrientation(CameraImageOrientation imageOrientation)

Kind: function

Set camera image orientation parameters: imageOrientation: Image orientation to set return: Shared pointer to the camera node

#### CameraImageOrientation getImageOrientation()

Kind: function

Get camera image orientation return: Image orientation

#### std::shared_ptr< Camera > build(dai::CameraBoardSocket boardSocket, ReplayVideo & replay)

Kind: function

Build with a specific board socket and mock input

#### std::shared_ptr< Camera > build(ReplayVideo & replay)

Kind: function

Build with mock input

#### uint32_t getMaxWidth()

Kind: function

Get max width of the camera (can only be called after build)

#### uint32_t getMaxHeight()

Kind: function

Get max height of the camera (can only be called after build)

#### CameraBoardSocket getBoardSocket()

Kind: function

Retrieves which board socket to use return: Board socket to use

#### std::shared_ptr< Camera > setRawNumFramesPool(int num)

Kind: function

Set number of frames in raw pool (will be automatically reduced if the maximum pool memory size is exceeded) parameters: num:
Number of frames return: Shared pointer to the camera node

#### std::shared_ptr< Camera > setMaxSizePoolRaw(int size)

Kind: function

Set maximum size of raw pool parameters: size: Maximum size in bytes of raw pool return: Shared pointer to the camera node

#### std::shared_ptr< Camera > setIspNumFramesPool(int num)

Kind: function

Set number of frames in isp pool (will be automatically reduced if the maximum pool memory size is exceeded) parameters: num:
Number of frames return: Shared pointer to the camera node

#### std::shared_ptr< Camera > setMaxSizePoolIsp(int size)

Kind: function

Set maximum size of isp pool parameters: size: Maximum size in bytes of isp pool return: Shared pointer to the camera node

#### std::shared_ptr< Camera > setNumFramesPools(int raw, int isp, int outputs)

Kind: function

Set number of frames in all pools (will be automatically reduced if the maximum pool memory size is exceeded) parameters: raw:
Number of frames in raw pool; isp: Number of frames in isp pool; outputs: Number of frames in outputs pools return: Shared pointer
to the camera node

#### std::shared_ptr< Camera > setMaxSizePools(int raw, int isp, int outputs)

Kind: function

Set maximum memory size of all pools parameters: raw: Maximum size in bytes of raw pool; isp: Maximum size in bytes of isp pool;
outputs: Maximum size in bytes of outputs pools return: Shared pointer to the camera node

#### std::shared_ptr< Camera > setOutputsNumFramesPool(int num)

Kind: function

Set number of frames in pools for all outputs parameters: num: Number of frames in pools for all outputs return: Shared pointer to
the camera node

#### std::shared_ptr< Camera > setOutputsMaxSizePool(int size)

Kind: function

Set maximum size of pools for all outputs parameters: size: Maximum size in bytes of pools for all outputs return: Shared pointer
to the camera node

#### int getRawNumFramesPool()

Kind: function

Get number of frames in raw pool return: Number of frames

#### int getMaxSizePoolRaw()

Kind: function

Get maximum size of raw pool return: Maximum size in bytes of raw pool

#### int getIspNumFramesPool()

Kind: function

Get number of frames in isp pool return: Number of frames

#### int getMaxSizePoolIsp()

Kind: function

Get maximum size of isp pool return: Maximum size in bytes of isp pool

#### std::optional< int > getOutputsNumFramesPool()

Kind: function

Get number of frames in outputs pool for all outputs return: Number of frames

#### std::optional< size_t > getOutputsMaxSizePool()

Kind: function

Get maximum size of outputs pool for all outputs return: Maximum size in bytes of image manip pool

#### Camera & setMockIsp(ReplayVideo & replay)

Kind: function

Set mock ISP for Camera node. Automatically sets mockIsp size. parameters: replay: ReplayVideo node to use as mock ISP

#### Camera()

Kind: function

#### Camera(std::shared_ptr< Device > & defaultDevice)

Kind: function

#### Camera(std::unique_ptr< Properties > props)

Kind: function

#### void buildStage1()

Kind: function

Build stages;.

#### float getMaxRequestedFps()

Kind: function

#### uint32_t getMaxRequestedWidth()

Kind: function

#### uint32_t getMaxRequestedHeight()

Kind: function

#### DeviceNodeCRTP()

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

Kind: function

### 需要帮助？

请前往 [OAKChina 官网](https://www.oakchina.cn/) 获取技术支持或解答您的任何疑问。
