G
g04356

  • Jan 18, 2024
  • Joined Dec 31, 2021
  • 0 best answers
  • I am trying to acquire depth images at 200fps using the following FW.

    luxonis/depthai-core926

    When I tried it with the source code below, depth image acquisition hangs when Ips3aFps is set low.

    The camera uses OAK-D.

    Please tell me how to solve the problem.

    #include <iostream>

    // Includes common necessary includes for development using depthai library

    #include "depthai/depthai.hpp"

    double get_sec()

    {

    struct timespec ts;
    
    timespec_get(&ts, TIME_UTC);
    
    return ((double)(ts.tv_sec));

    }

    // Closer-in minimum depth, disparity range is doubled (from 95 to 190):

    static std::atomic<bool> extended_disparity{false};

    // Better accuracy for longer distance, fractional disparity 32-levels:

    static std::atomic<bool> subpixel{false};

    // Better handling for occlusions:

    static std::atomic<bool> lr_check{true};

    int main() {

    // Create pipeline
    
    dai::Pipeline pipeline;
    
    // Define sources and outputs
    
    auto monoLeft = pipeline.create<dai::node::MonoCamera>();
    
    auto monoRight = pipeline.create<dai::node::MonoCamera>();
    
    auto depth = pipeline.create<dai::node::StereoDepth>();
    
    auto xout = pipeline.create<dai::node::XLinkOut>();
    
    xout->setStreamName("disparity");
    
    std::shared_ptr<dai::node::XLinkIn> controlIn_mono;
    
    std::shared_ptr<dai::DataInputQueue> controlQueue_mono;
    
    controlIn_mono = pipeline.create<dai::node::XLinkIn>();
    
    dai::CameraControl ctrl_mono;
    
    // Properties
    
    monoLeft->setResolution(dai::MonoCameraProperties::SensorResolution::THE_400_P);
    
    monoLeft->setCamera("left");
    
    monoRight->setResolution(dai::MonoCameraProperties::SensorResolution::THE_400_P);
    
    monoRight->setCamera("right");
    
    monoLeft->setIsp3aFps(10);
    
    monoRight->setIsp3aFps(10);
    
    monoLeft->setFps(200);
    
    monoRight->setFps(200);
    
    controlIn_mono->setStreamName("control_mono");
    
    // Create a node that will produce the depth map (using disparity output as it's easier to visualize depth this way)
    
    depth->setDefaultProfilePreset(dai::node::StereoDepth::PresetMode::HIGH_DENSITY);
    
    // Options: MEDIAN_OFF, KERNEL_3x3, KERNEL_5x5, KERNEL_7x7 (default)
    
    depth->initialConfig.setMedianFilter(dai::MedianFilter::KERNEL_7x7);
    
    depth->setLeftRightCheck(lr_check);
    
    depth->setExtendedDisparity(extended_disparity);
    
    depth->setSubpixel(subpixel);
    
    // Linking
    
    monoLeft->out.link(depth->left);
    
    monoRight->out.link(depth->right);
    
    depth->disparity.link(xout->input);
    
    controlIn_mono->out.link(monoRight->inputControl);
    
    controlIn_mono->out.link(monoLeft->inputControl);
    
    // Connect to device and start pipeline
    
    dai::Device device(pipeline);
    
    controlQueue_mono = device.getInputQueue(controlIn_mono->getStreamName());
    
    ctrl_mono.setAutoExposureLock(true);
    
    controlQueue_mono->send(ctrl_mono);
    
    // Output queue will be used to get the disparity frames from the outputs defined above
    
    auto q = device.getOutputQueue("disparity", 4, false);
    
    double cnt_t;
    
    int fps_cnt = 0, fps_cnt_fix = 0;
    
    double time_cnt = get_sec();
    
    while(true) {
    
        auto inDepth = q->get<dai::ImgFrame>();
    
        auto frame = inDepth->getFrame();
    
        // Normalization for better visualization
    
        frame.convertTo(frame, CV_8UC1, 255 / depth->initialConfig.getMaxDisparity());
    
        cnt_t = get_sec();
    
        if(time_cnt != cnt_t)
    
        {
    
            fps_cnt_fix = (float)fps_cnt / (int)(cnt_t - time_cnt);
    
            printf("fps:%d\\n", fps_cnt_fix);
    
            time_cnt = cnt_t;
    
            fps_cnt = 0;
    
        }
    
        fps_cnt++;
    
        cv::imshow("disparity", frame);
    
        // Available color maps: https://docs.opencv.org/3.4/d3/d50/group__imgproc__colormap.html
    
        // cv::applyColorMap(frame, frame, cv::COLORMAP_JET);
    
        // cv::imshow("disparity_color", frame);
    
        
    
        int key = cv::waitKey(1);
    
        if(key == 'q' || key == 'Q') {
    
            return 0;
    
        }
    
        
    
    }
    
    return 0;

    }

    • Thank you Erik. I followed the advice and tried. Erik's advice seems to make it possible for me to do what I was looking for. May I ask another question about this?
      I want to throw a trigger message from the outside to a script node. If possible, I would be grateful if there was sample code etc.

      • erik replied to this.
      • I need to change the FPS of the color camera depending on the scene.
        Hawever,It seems that FPS does not change even if I execute-> setFps after OAK-D running.
        How can I change the FPS after OAK-D is up and running?

        • erik replied to this.