Hi all,

I have a c++ project existing out of more than 6 header + code files. Initially the project was built around an Intel RealSense camera, but I am trying to convert it to use the OAK-D-PoE and depthai-core. For the project I need the Depth and Color camera.

Reading the pipeline, displaying both images and processing the data within the images works fine when running the code within main(). Yet when I use a std::shared_ptr<dai:: DataOutputQueue> (or other dai datatypes) as a method-argument for a method in another (.cpp) code file it returns a segmentation error, as shown below.

Stack trace (most recent call last):
#5      Object "./Malum", at 0x557f604067, in
#4      Object "/lib/aarch64-linux-gnu/libc.so.6" , at 0x7f813226df, in __libc_start_main
#3      Object "./Malum", at 0x557f603237, in
#2      Object "./Malum", at 0x557f61c64b, in
#1      Object "./Malum", at 0x557f61b8db, in
#0      Object "./Malum", at 0x557f61afc7c, in
Segmentation fault (Address not mapped to object [0xf8])
Segmentation fault (core dumped)

Is it possible to use dai datatypes as method-arguments for methods in another code file?

example:
main():

#include "depthai/depthai.hpp" 
#include "utility.hpp"

int main(){

    dai::Pipeline pipeline;
    auto monoLeft = pipeline.create<dai::node::MonoCamera>();
    auto monoRight = pipeline.create<dai::node::MonoCamera>();
    auto stereo = pipeline.create<dai::node::StereoDepth>();
    auto spatialDataCalculator = pipeline.create<dai::node::SpatialLocationCalculator>();
    
    //further setup for the camera

    dai::Device device(pipeline, dai::UsbSpeed::SUPER);
    auto depthQueue = device.getOutputQueue("depth", 8, false);
    auto spatialCalcQueue = device.getOutputQueue("spatialData", 8, false);


    while(true){

        auto inDepth = depthQueue->get<dai::imgFrame();
        cv::Mat depthFrame = inDepth->getFrame();

        Camera.measure(depthFrame, spatialCalcQueue);

        //Rest of code
    }

}

in Camera.cpp:

void Camera::measure (cv::Mat depthFrame, std::shared_ptr<dai::DataOutputQueue> spatialCalcQueue){

     //The following line causes segmentation fault
    std::vector<dai::SpatialLocations> spatialData = spatialCalcQueue->get<dai::SpatialLocationCalculatorData>()->getSpatialLocations(); 
    
    for(dai::SpatialLocations depthData : spatialData){

        //Code to extract data from depth frame

    }
//More code

}

    Hi Epsi

    Should be - I'll test this now on my end and get back to you...

    Also, try compiling the library in Debug mode and step into this crash using a debugger. Might tell you more about the issue.

    #include "depthai/depthai.hpp"
    #include "utility.hpp"
    #include <iostream>
    
    struct Camera {
        static void measure(std::shared_ptr<dai::DataOutputQueue>);
    };
    
    void Camera::measure (std::shared_ptr<dai::DataOutputQueue> depthQueue){
    
        //The following line causes segmentation fault
        auto depthFrame = depthQueue->get<dai::ImgFrame>();
    
        std::cout << "depth frame: " << depthFrame->getWidth() << ", " << depthFrame->getHeight() << std::endl;
    }
    
    int main(){
    
        dai::Pipeline pipeline;
        auto monoLeft = pipeline.create<dai::node::MonoCamera>();
        auto monoRight = pipeline.create<dai::node::MonoCamera>();
        auto stereo = pipeline.create<dai::node::StereoDepth>();
    
        auto xoutDepth = pipeline.create<dai::node::XLinkOut>();
        xoutDepth->setStreamName("depth");
    
        monoLeft->out.link(stereo->left);
        monoRight->out.link(stereo->right);
        stereo->depth.link(xoutDepth->input);
    
        //further setup for the camera
    
        dai::Device device(pipeline, dai::UsbSpeed::SUPER);
        auto depthQueue = device.getOutputQueue("depth", 8, false);
    
    
        while(true){
            Camera::measure(depthQueue);
    
            //Rest of code
        }
    
    }

    The above works for me - so not exactly sure on the differences between our cases.

    Please provide a minimum reproducible example, showcasing the issue. (https://stackoverflow.com/help/minimal-reproducible-example). Its going to be the easiest to debug.

    Thanks,
    Martin

    Hello Martin,

    Thank you for your reaction.
    The problem was a realsense camera that was connected, and only initialized, by the software.
    This caused troubles with the depthai sdk.