@@ -604,6 +604,49 @@ TEST_CASE("Segmentation passthrough can be toggled") {
604604 }
605605}
606606
607+ TEST_CASE (" Segmentation passthrough preserves mask when detections are empty" ) {
608+ constexpr unsigned width = 320 ;
609+ constexpr unsigned height = 240 ;
610+ const std::array<std::array<float , 3 >, 3 > intrinsics = {{
611+ {{5 .0F , 0 .0F , 1 .0F }},
612+ {{0 .0F , 5 .0F , 1 .0F }},
613+ {{0 .0F , 0 .0F , 1 .0F }},
614+ }};
615+
616+ cv::Mat depthMat (height, width, CV_16UC1 , cv::Scalar (2000 ));
617+ auto depthFrame = createDepthFrame (depthMat, intrinsics);
618+
619+ std::vector<std::uint8_t > mask (width * height, 255 );
620+ for (int y = 20 ; y < 60 ; ++y) {
621+ for (int x = 30 ; x < 90 ; ++x) {
622+ mask.at (y * static_cast <int >(width) + x) = 0 ;
623+ }
624+ }
625+
626+ dai::SpatialLocationCalculatorConfig initialConfig;
627+ initialConfig.setCalculationAlgorithm (dai::SpatialLocationCalculatorAlgorithm::AVERAGE );
628+ initialConfig.setDepthThresholds (0 , 10000 );
629+ initialConfig.setUseSegmentation (true );
630+ initialConfig.setSegmentationPassthrough (true );
631+ initialConfig.setCalculateSpatialKeypoints (false );
632+
633+ auto detectionMsg = std::make_shared<dai::ImgDetections>();
634+ detectionMsg->setSegmentationMask (mask, width, height);
635+ detectionMsg->transformation = depthFrame->transformation ;
636+ detectionMsg->setTimestamp (depthFrame->getTimestamp ());
637+ detectionMsg->setSequenceNum (depthFrame->getSequenceNum ());
638+ auto [unusedLegacy, unusedPassthrough, spatialDetections] = processDepthFrame (initialConfig, depthFrame, std::nullopt , detectionMsg);
639+ static_cast <void >(unusedLegacy);
640+ static_cast <void >(unusedPassthrough);
641+
642+ CHECK (spatialDetections.detections .empty ());
643+ const auto outMask = spatialDetections.getMaskData ();
644+ REQUIRE (outMask.has_value ());
645+ CHECK (*outMask == mask);
646+ CHECK (spatialDetections.getSegmentationMaskWidth () == width);
647+ CHECK (spatialDetections.getSegmentationMaskHeight () == height);
648+ }
649+
607650TEST_CASE (" Spatial detections remap depth to detection transformations" ) {
608651 using std::chrono::steady_clock;
609652 const auto RESET_REMOTE_TIMEOUT_MS = std::chrono::milliseconds (2000 );
0 commit comments