Code Monkey home page Code Monkey logo

Comments (3)

moratom avatar moratom commented on August 30, 2024

@LuoQuestionmark as the sensors are not HW synced, the better approach is to use the newly added Sync node which syncs them based on timestamps.

See https://github.com/luxonis/depthai-python/blob/main/examples/Sync/depth_video_synced.py for an example.

from depthai-core.

diablodale avatar diablodale commented on August 30, 2024

So I am wondering if there is a "hidden buffer" somewhere within the program that save the outdated frame?

#366 and its PRs allow the host-side queue to be zero. Then nothing is stored or buffered...incoming data only goes to callbacks.

from depthai-core.

LuoQuestionmark avatar LuoQuestionmark commented on August 30, 2024

@moratom
@diablodale

Thanks for your comments, I actually forgot that the issue was still open. So here is my update on the subject.

The answer to the question "if there is a 'hidden buffer'" is no. That said, there are actually two co-existing buffers, which I consider as sort of a bad design of api.

The following code

mono_xout1->input.setQueueSize(1);
mono_xout1->input.setBlocking(false);

was working as expected, to make the xout work as a non-blocking queue.

Meanwhile, there is a second buffer configured while using the following code:

auto depth_queue = device.getOutputQueue("DEPTH");

.

The source code (version 2.24)

///////////////// Device.hpp
/**
 * Gets an output queue corresponding to stream name. If it doesn't exist it throws
 *
 * @param name Queue/stream name, created by XLinkOut node
 * @returns Smart pointer to DataOutputQueue
 */
std::shared_ptr<DataOutputQueue> getOutputQueue(const std::string& name);

/**
 * Gets a queue corresponding to stream name, if it exists, otherwise it throws. Also sets queue options
 *
 * @param name Queue/stream name, set in XLinkOut node
 * @param maxSize Maximum number of messages in queue
 * @param blocking Queue behavior once full. True specifies blocking and false overwriting of oldest messages. Default: true
 * @returns Smart pointer to DataOutputQueue
 */
std::shared_ptr<DataOutputQueue> getOutputQueue(const std::string& name, unsigned int maxSize, bool blocking = true);

//////////////// Device.cpp

std::shared_ptr<DataOutputQueue> Device::getOutputQueue(const std::string& name) {
    // Throw if queue not created
    // all queues for xlink streams are created upfront
    if(outputQueueMap.count(name) == 0) {
        throw std::runtime_error(fmt::format("Queue for stream name '{}' doesn't exist", name));
    }
    // Return pointer to this DataQueue
    return outputQueueMap.at(name);
}

std::shared_ptr<DataOutputQueue> Device::getOutputQueue(const std::string& name, unsigned int maxSize, bool blocking) {
    // Throw if queue not created
    // all queues for xlink streams are created upfront
    if(outputQueueMap.count(name) == 0) {
        throw std::runtime_error(fmt::format("Queue for stream name '{}' doesn't exist", name));
    }

    // Modify max size and blocking
    outputQueueMap.at(name)->setMaxSize(maxSize);
    outputQueueMap.at(name)->setBlocking(blocking);

    // Return pointer to this DataQueue
    return outputQueueMap.at(name);
}

Now, the thing is, if this function is called without specifying maxSize and blocking, it will use the default setting from DataQueue.hpp, which is the following:

DataOutputQueue(const std::shared_ptr<XLinkConnection> conn, const std::string& streamName, unsigned int maxSize = 16, bool blocking = true);

which means a second buffer is created as a blocking=True and maxSize=16.

So at the end of day we got a blocking=false maxSize=1 buffer, and a blocking=true maxSize=16 buffer. The combination is, alas, blocking=true maxSize=16. Along side with the issue mentioned as frame drifting, the frame drifting is slowly but steady.

So after specifying the configuration of the second buffer, the problem has been solved. We have had our program running for 17 days without any observable delay after the changes.

aDevice.getOutputQueue("RGB", 1, false); // after the first config for xlink

from depthai-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.