- Edited
I'm trying to get the depth values in C++ without opencv. This is the function:
inline auto CalcSpatials(const std::shared_ptr<dai::ImgFrame> &frame)
-> uint16_t {
const uint32_t BLOCK_SIZE = 10;
const auto centerX = frame->getWidth() / 2;
const auto centerY = frame->getHeight() / 2;
const auto startX = centerX - BLOCK_SIZE / 2;
const auto endX = centerX + BLOCK_SIZE / 2;
const auto startY = centerY - BLOCK_SIZE / 2;
const auto endY = centerY + BLOCK_SIZE / 2;
uint16_t sum = 0;
// Convert ImgFrame's uint8_t raw buffer to a uint16_t buffer
std::vector<uint16_t> data;
data.resize(frame->getData().size() / sizeof(uint16_t));
std::memcpy(data.data(), frame->getData().data(), frame->getData().size());
// Loop through ROI and sum values
for (auto y = startY; y < endY; ++y) {
for (auto x = startX; x < endX; ++x) {
const auto index = x + frame->getWidth() * y;
sum += data[index];
}
}
return sum / (BLOCK_SIZE * BLOCK_SIZE);
}
The pipeline is setup following this experiment in Python