From 38bbaf299649d1addcaec105417af0aeca4c2051 Mon Sep 17 00:00:00 2001 From: Emilian Peev Date: Fri, 10 May 2019 12:58:18 -0700 Subject: [PATCH] Camera: Prune depth samples with low confidence Depth samples with low confidence can skew the near/far values and impact the range inverse coding. Avoid using such samples when searching for the near and far points and clamp their values if necessary. Bug: 132248813 Test: Camera CTS Change-Id: I7dc134b50e46c664f9fc8750b9b9b37c416c9afe --- .../common/DepthPhotoProcessor.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/services/camera/libcameraservice/common/DepthPhotoProcessor.cpp b/services/camera/libcameraservice/common/DepthPhotoProcessor.cpp index 6d96163b42..fc79150351 100644 --- a/services/camera/libcameraservice/common/DepthPhotoProcessor.cpp +++ b/services/camera/libcameraservice/common/DepthPhotoProcessor.cpp @@ -64,6 +64,10 @@ using dynamic_depth::Profiles; namespace android { namespace camera3 { +// Depth samples with low confidence can skew the +// near/far values and impact the range inverse coding. +static const float CONFIDENCE_THRESHOLD = .15f; + ExifOrientation getExifOrientation(const unsigned char *jpegBuffer, size_t jpegBufferSize) { if ((jpegBuffer == nullptr) || (jpegBufferSize == 0)) { return ExifOrientation::ORIENTATION_UNDEFINED; @@ -238,6 +242,9 @@ inline void unpackDepth16(uint16_t value, std::vector *points /*out*/, auto conf = (value >> 13) & 0x7; float normConfidence = (conf == 0) ? 1.f : (static_cast(conf) - 1) / 7.f; confidence->push_back(normConfidence); + if (normConfidence < CONFIDENCE_THRESHOLD) { + return; + } if (*near > point) { *near = point; @@ -358,8 +365,12 @@ std::unique_ptr processDepthMapFrame(DepthPhotoInputFra auto pointIt = points.begin(); auto confidenceIt = confidence.begin(); while ((pointIt != points.end()) && (confidenceIt != confidence.end())) { - pointsQuantized.push_back(floorf(((far * (*pointIt - near)) / - (*pointIt * (far - near))) * 255.0f)); + auto point = *pointIt; + if ((*confidenceIt) < CONFIDENCE_THRESHOLD) { + point = std::clamp(point, near, far); + } + pointsQuantized.push_back(floorf(((far * (point - near)) / + (point * (far - near))) * 255.0f)); confidenceQuantized.push_back(floorf(*confidenceIt * 255.0f)); confidenceIt++; pointIt++; }