Go to the documentation of this file.
7 static constexpr
auto FPS = 30;
22 left->setCamera(
"left");
27 right->setCamera(
"right");
36 left->out.link(stereo->left);
37 right->out.link(stereo->right);
43 stereo->disparity.link(script->inputs[
"disp_in"]);
44 camRgb->video.link(script->inputs[
"rgb_in"]);
49 from datetime import timedelta
52 # Timestamp threshold (in miliseconds) under which frames will be considered synced.
53 # Lower number means frames will have less delay between them, which can potentially
54 # lead to dropped frames.
55 MS_THRESHOL=math.ceil(500 / FPS)
57 def check_sync(queues, timestamp):
59 for name, list in queues.items(): # Go through each available stream
60 # node.warn(f"List {name}, len {str(len(list))}")
61 for i, msg in enumerate(list): # Go through each frame of this stream
62 time_diff = abs(msg.getTimestamp() - timestamp)
63 if time_diff <= timedelta(milliseconds=MS_THRESHOL): # If time diff is below threshold, this frame is considered in-sync
64 matching_frames.append(i) # Append the position of the synced frame, so we can later remove all older frames
67 if len(matching_frames) == len(queues):
68 # We have all frames synced. Remove the excess ones
70 for name, list in queues.items():
71 queues[name] = queues[name][matching_frames[i]:] # Remove older (excess) frames
75 return False # We don't have synced frames yet
77 names = ['disp', 'rgb']
78 frames = dict() # Dict where we store all received frames
84 f = node.io[name+"_in"].tryGet()
86 frames[name].append(f) # Save received frame
88 if check_sync(frames, f.getTimestamp()): # Check if we have any synced frames
90 node.info(f"Synced frame!")
91 for name, list in frames.items():
92 syncedF = list.pop(0) # We have removed older (excess) frames, so at positions 0 in dict we have synced frames
93 node.info(f"{name}, ts: {str(syncedF.getTimestamp())}, seq {str(syncedF.getSequenceNum())}")
94 node.io[name+'_out'].send(syncedF) # Send synced frames to the host
97 time.sleep(0.001) # Avoid lazy looping
100 std::vector<std::string> scriptOut{"disp",
"rgb"};
102 for(
auto& name : scriptOut) {
105 script->outputs[name +
"_out"].link(xout->input);
112 std::vector<std::string> names{
"rgb",
"disp"};
113 std::map<std::string, std::shared_ptr<dai::DataOutputQueue>> streams;
114 for(
auto& name : names) {
118 for(
auto& iter : streams) {
119 auto name = iter.first;
120 auto queue = iter.second;
123 std::cout <<
"Stream " << name <<
", timestamp: " << img->
getTimestamp().time_since_epoch().count()
124 <<
", sequence number: " << img->getSequenceNum() << std::endl;
XLinkOut node. Sends messages over XLink.
Represents the pipeline, set of nodes and connections between them.
StereoDepthConfig initialConfig
StereoDepth node. Compute stereo disparity and depth from left-right image pair.
MonoCamera node. For use with grayscale sensors.
ColorCamera node. For use with color sensors.
StereoDepthConfig & setExtendedDisparity(bool enable)
void setLogLevel(LogLevel level)
StereoDepthConfig & setDepthAlign(AlgorithmControl::DepthAlign align)
void setLogOutputLevel(LogLevel level)
std::chrono::time_point< std::chrono::steady_clock, std::chrono::steady_clock::duration > getTimestamp(CameraExposureOffset offset) const
StereoDepthConfig & setLeftRightCheck(bool enable)
std::shared_ptr< DataOutputQueue > getOutputQueue(const std::string &name)
StereoDepthConfig & setSubpixel(bool enable)
void setScript(const std::string &script, const std::string &name="")
std::shared_ptr< N > create()
void setResolution(Properties::SensorResolution resolution)
Set sensor resolution.
static constexpr auto FPS
StereoDepthConfig & setMedianFilter(MedianFilter median)
void setVideoNumFramesPool(int num)
Set number of frames in preview pool.
void setStreamName(const std::string &name)
depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19