# Camera isp output

This example shows how to use the isp output from the Camera node. Image Signal Processor (ISP) is a key camera component that
helps achieve the desired output quality in imaging systems. It is the ISP that converts raw images delivered by an image sensor
into a usable form, which can then be used by the embedded vision system for various tasks.

This example requires the DepthAI v3 API, see [installation instructions](https://docs.luxonis.com/software-v3/depthai.md).

## Pipeline

### examples/camera_isp.pipeline.json

```json
{
  "pipeline": {
    "connections": [
      {
        "node1Id": 0,
        "node1Output": "0",
        "node1OutputGroup": "dynamicOutputs",
        "node2Id": 3,
        "node2Input": "in",
        "node2InputGroup": ""
      },
      {
        "node1Id": 0,
        "node1Output": "1",
        "node1OutputGroup": "dynamicOutputs",
        "node2Id": 1,
        "node2Input": "in",
        "node2InputGroup": ""
      }
    ],
    "globalProperties": {
      "calibData": null,
      "cameraSocketTuningBlobSize": [],
      "cameraSocketTuningBlobUri": [],
      "cameraTuningBlobSize": null,
      "cameraTuningBlobUri": "",
      "eepromId": 0,
      "leonCssFrequencyHz": 700000000.0,
      "leonMssFrequencyHz": 700000000.0,
      "pipelineName": null,
      "pipelineVersion": null,
      "sippBufferSize": 18432,
      "sippDmaBufferSize": 16384,
      "xlinkChunkSize": -1
    },
    "nodes": [
      [
        3,
        {
          "alias": "",
          "deviceId": "1936701492",
          "deviceNode": true,
          "id": 3,
          "ioInfo": [
            [
              [
                "",
                "pipelineEventOutput"
              ],
              {
                "blocking": false,
                "group": "",
                "id": 11,
                "name": "pipelineEventOutput",
                "queueSize": 8,
                "type": 0,
                "waitForMessage": false
              }
            ],
            [
              [
                "",
                "in"
              ],
              {
                "blocking": true,
                "group": "",
                "id": 10,
                "name": "in",
                "queueSize": 3,
                "type": 3,
                "waitForMessage": false
              }
            ]
          ],
          "logLevel": 1,
          "name": "XLinkOut",
          "parentId": -1,
          "properties": [185, 5, 136, 0, 0, 128, 191, 189, 7, 95, 95, 120, 95, 48, 95, 48, 0, 255, 255]
        }
      ],
      [
        1,
        {
          "alias": "",
          "deviceId": "1936701492",
          "deviceNode": true,
          "id": 1,
          "ioInfo": [
            [
              [
                "",
                "pipelineEventOutput"
              ],
              {
                "blocking": false,
                "group": "",
                "id": 7,
                "name": "pipelineEventOutput",
                "queueSize": 8,
                "type": 0,
                "waitForMessage": false
              }
            ],
            [
              [
                "",
                "in"
              ],
              {
                "blocking": true,
                "group": "",
                "id": 6,
                "name": "in",
                "queueSize": 3,
                "type": 3,
                "waitForMessage": false
              }
            ]
          ],
          "logLevel": 1,
          "name": "XLinkOut",
          "parentId": -1,
          "properties": [185, 5, 136, 0, 0, 128, 191, 189, 7, 95, 95, 120, 95, 48, 95, 49, 0, 255, 255]
        }
      ],
      [
        0,
        {
          "alias": "",
          "deviceId": "1936701492",
          "deviceNode": true,
          "id": 0,
          "ioInfo": [
            [
              [
                "dynamicOutputs",
                "0"
              ],
              {
                "blocking": false,
                "group": "dynamicOutputs",
                "id": 5,
                "name": "0",
                "queueSize": 8,
                "type": 0,
                "waitForMessage": false
              }
            ],
            [
              [
                "",
                "raw"
              ],
              {
                "blocking": false,
                "group": "",
                "id": 3,
                "name": "raw",
                "queueSize": 8,
                "type": 0,
                "waitForMessage": false
              }
            ],
            [
              [
                "",
                "pipelineEventOutput"
              ],
              {
                "blocking": false,
                "group": "",
                "id": 2,
                "name": "pipelineEventOutput",
                "queueSize": 8,
                "type": 0,
                "waitForMessage": false
              }
            ],
            [
              [
                "dynamicOutputs",
                "1"
              ],
              {
                "blocking": false,
                "group": "dynamicOutputs",
                "id": 4,
                "name": "1",
                "queueSize": 8,
                "type": 0,
                "waitForMessage": false
              }
            ],
            [
              [
                "",
                "mockIsp"
              ],
              {
                "blocking": true,
                "group": "",
                "id": 1,
                "name": "mockIsp",
                "queueSize": 8,
                "type": 3,
                "waitForMessage": false
              }
            ],
            [
              [
                "",
                "inputControl"
              ],
              {
                "blocking": true,
                "group": "",
                "id": 0,
                "name": "inputControl",
                "queueSize": 3,
                "type": 3,
                "waitForMessage": false
              }
            ]
          ],
          "logLevel": 1,
          "name": "Camera",
          "parentId": -1,
          "properties": [185, 22, 185, 33, 0, 3, 0, 136, 0, 0, 0, 0, 128, 198, 128, 161, 185, 3, 130, 192, 148, 121, 94, 130, 109, 12, 41, 224, 130, 246, 224, 147, 240, 185, 5, 129, 43, 182, 129, 114, 142, 129, 162, 9, 129, 181, 152, 130, 172, 94, 196, 116, 185, 5, 129, 94, 132, 129, 232, 240, 129, 87, 109, 129, 225, 125, 130, 148, 23, 101, 0, 128, 163, 112, 128, 232, 0, 0, 128, 164, 128, 165, 79, 128, 218, 185, 3, 39, 128, 233, 132, 178, 185, 3, 134, 231, 88, 19, 96, 134, 233, 44, 98, 5, 130, 248, 33, 172, 30, 130, 3, 75, 254, 255, 92, 49, 132, 134, 86, 128, 224, 0, 0, 129, 202, 203, 128, 203, 111, 0, 186, 0, 1, 255, 189, 0, 255, 255, 255, 255, 255, 136, 0, 0, 128, 191, 136, 0, 0, 128, 191, 0, 3, 134, 0, 0, 160, 0, 3, 134, 0, 0, 160, 0, 4, 4, 4, 190, 190, 186, 2, 185, 6, 185, 1, 184, 0, 186, 2, 129, 32, 3, 129, 144, 1, 185, 1, 184, 0, 136, 0, 0, 240, 65, 190, 0, 190, 0, 185, 6, 185, 1, 190, 185, 1, 184, 0, 136, 0, 0, 0, 64, 190, 0, 0, 1]
        }
      ]
    ]
  }
}
```

## Source code

#### Python

```python
import cv2
import depthai as dai

# Create pipeline
with dai.Pipeline() as pipeline:
    # Define source and output
    cam = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
    videoQueue = cam.requestOutput((800,400), fps=30).createOutputQueue()
    videoIsp = cam.requestIspOutput(fps=2).createOutputQueue()
    # Connect to device and start pipeline
    pipeline.start()
    videoIn = videoQueue.get()
    videoInIsp = videoIsp.get()
    print(
        "Standard output resolution = "
        f"{ videoIn.getCvFrame().shape[1]} x { videoIn.getCvFrame().shape[0]}"
    )
    print(
        f"Isp output resolution = "
        f"{ videoInIsp.getCvFrame().shape[1]} x { videoInIsp.getCvFrame().shape[0]}"
    )
    while pipeline.isRunning():
        videoIn = videoQueue.tryGet()
        videoInIsp = videoIsp.tryGet() # Returns 640x400
        if videoIn:
            cv2.imshow("video", videoIn.getCvFrame())
        if videoInIsp:
            cv2.imshow("videoIsp", videoInIsp.getCvFrame())

        if cv2.waitKey(1) == ord("q"):
            break
```

#### C++

```cpp
#include <atomic>
#include <csignal>
#include <iostream>
#include <opencv2/opencv.hpp>

#include "depthai/depthai.hpp"

std::atomic<bool> quitEvent(false);

void signalHandler(int) {
    quitEvent = true;
}

int main() {
    using namespace dai;
    using namespace std;

    signal(SIGTERM, signalHandler);
    signal(SIGINT, signalHandler);

    dai::Pipeline pipeline;

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

    // Request outputs
    auto videoOut = cam->requestOutput(std::make_pair(800, 400), std::nullopt, ImgResizeMode::CROP, 30.0f, std::nullopt);
    auto ispOut = cam->requestIspOutput(2.0f);

    // Create output queues
    auto videoQueue = videoOut->createOutputQueue();
    auto ispQueue = ispOut->createOutputQueue();

    pipeline.start();

    // Get first frames and print resolutions
    auto videoIn = videoQueue->get<dai::ImgFrame>();
    auto videoInIsp = ispQueue->get<dai::ImgFrame>();

    cout << "Standard output resolution = " << videoIn->getCvFrame().cols << " x " << videoIn->getCvFrame().rows << endl;

    cout << "Isp output resolution = " << videoInIsp->getCvFrame().cols << " x " << videoInIsp->getCvFrame().rows << endl;

    // Main loop
    while(pipeline.isRunning() && !quitEvent) {
        auto videoIn = videoQueue->tryGet<dai::ImgFrame>();
        auto videoInIsp = ispQueue->tryGet<dai::ImgFrame>();

        if(videoIn) {
            cv::imshow("video", videoIn->getCvFrame());
        }
        if(videoInIsp) {
            cv::imshow("videoIsp", videoInIsp->getCvFrame());
        }

        if(cv::waitKey(1) == 'q') break;
    }

    pipeline.stop();
    pipeline.wait();

    return 0;
}
```

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
