#include #include #include #include namespace { int fail(const char* step) { std::fprintf(stderr, "%s failed: %s\n", step, openni::OpenNI::getExtendedError()); return 1; } } // namespace // Companion to fallback/linux-openni2/tools/openni2_depth_consumer.cpp: reads // the same live SynthKinect OpenNI2 stream and additionally reports the // in-band per-pixel MEAN depth per frame (plan todo 21 evidence: proves the // articulated body surface has a real depth distribution, not a single flat // value repeated across every body pixel). int main(int argc, char** argv) { const int frame_count = argc > 1 ? std::atoi(argv[1]) : 12; if (openni::OpenNI::initialize() != openni::STATUS_OK) { return fail("OpenNI::initialize"); } openni::Device device; if (device.open(openni::ANY_DEVICE) != openni::STATUS_OK) { openni::OpenNI::shutdown(); return fail("Device::open"); } openni::VideoStream depth; if (depth.create(device, openni::SENSOR_DEPTH) != openni::STATUS_OK || depth.start() != openni::STATUS_OK) { device.close(); openni::OpenNI::shutdown(); return fail("VideoStream::create/start"); } for (int i = 0; i < frame_count; ++i) { openni::VideoFrameRef frame; if (depth.readFrame(&frame) != openni::STATUS_OK || !frame.isValid()) { std::fprintf(stderr, "readFrame failed at index %d\n", i); depth.stop(); depth.destroy(); device.close(); openni::OpenNI::shutdown(); return 1; } const auto* pixels = static_cast(frame.getData()); const int width = frame.getWidth(); const int height = frame.getHeight(); uint16_t min_mm = 0xFFFF; uint16_t max_mm = 0; double sum_mm = 0.0; int count = 0; for (int index = 0; index < width * height; ++index) { const uint16_t value = pixels[index]; if (value == 0) { continue; } ++count; sum_mm += value; if (value < min_mm) { min_mm = value; } if (value > max_mm) { max_mm = value; } } const double mean_mm = count > 0 ? sum_mm / count : 0.0; std::printf( "depthstats[%02d] count=%d min_mm=%u max_mm=%u mean_mm=%.1f spread_mm=%d\n", i, count, count > 0 ? min_mm : 0, max_mm, mean_mm, count > 0 ? static_cast(max_mm) - static_cast(min_mm) : 0); frame.release(); } depth.stop(); depth.destroy(); device.close(); openni::OpenNI::shutdown(); return 0; }