28 xoutDepth->setStreamName(
"depth");
34 monoLeft->setCamera(
"left");
39 stereo->setLeftRightCheck(
true);
40 stereo->setExtendedDisparity(
true);
44 for(
int i = 0; i < 10; i++) {
53 monoLeft->out.link(stereo->left);
54 monoRight->
out.
link(stereo->right);
56 spatialLocationCalculator->passthroughDepth.link(xoutDepth->input);
57 stereo->depth.link(spatialLocationCalculator->inputDepth);
59 spatialLocationCalculator->out.link(xoutSpatialData->
input);
60 xinSpatialCalcConfig->out.link(spatialLocationCalculator->
inputConfig);
68 auto spatialCalcQueue = device.
getOutputQueue(
"spatialData", 4,
false);
69 auto color = cv::Scalar(0, 200, 40);
70 auto fontType = cv::FONT_HERSHEY_TRIPLEX;
75 cv::Mat depthFrame = inDepth->
getFrame();
77 cv::Mat depthFrameColor;
78 cv::normalize(depthFrame, depthFrameColor, 255, 0, cv::NORM_INF, CV_8UC1);
79 cv::equalizeHist(depthFrameColor, depthFrameColor);
80 cv::applyColorMap(depthFrameColor, depthFrameColor, cv::COLORMAP_HOT);
83 for(
auto depthData : spatialData) {
84 auto roi = depthData.config.roi;
85 roi = roi.denormalize(depthFrameColor.cols, depthFrameColor.rows);
87 auto xmin =
static_cast<int>(roi.topLeft().x);
88 auto ymin =
static_cast<int>(roi.topLeft().y);
89 auto xmax =
static_cast<int>(roi.bottomRight().x);
90 auto ymax =
static_cast<int>(roi.bottomRight().y);
92 auto coords = depthData.spatialCoordinates;
93 auto distance = std::sqrt(coords.x * coords.x + coords.y * coords.y + coords.z * coords.z);
95 cv::rectangle(depthFrameColor, cv::Rect(cv::Point(xmin, ymin), cv::Point(xmax, ymax)), color);
96 std::stringstream depthDistance;
97 depthDistance.precision(2);
98 depthDistance << fixed << static_cast<float>(distance / 1000.0f) <<
"m";
99 cv::putText(depthFrameColor, depthDistance.str(), cv::Point(xmin + 10, ymin + 20), fontType, 0.5, color);
102 cv::imshow(
"depth", depthFrameColor);
104 if(cv::waitKey(1) ==
'q') {