Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b10af80 authored by Emilian Peev's avatar Emilian Peev Committed by android-build-merger
Browse files

Merge "Camera: Prune depth samples with low confidence" into qt-dev

am: eb99a27f

Change-Id: I9e18eccab45bd45b25d712eea7f8c9fe13a4ae0a
parents 5f5158fe eb99a27f
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -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<float> *points /*out*/,
    auto conf = (value >> 13) & 0x7;
    float normConfidence = (conf == 0) ? 1.f : (static_cast<float>(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<dynamic_depth::DepthMap> 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++;
    }