File: test_dynafu.cpp

package info (click to toggle)
opencv 4.5.1%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 268,248 kB
  • sloc: cpp: 969,170; xml: 682,525; python: 36,732; lisp: 30,170; java: 25,155; ansic: 7,927; javascript: 5,643; objc: 2,041; sh: 935; cs: 601; perl: 494; makefile: 145
file content (129 lines) | stat: -rw-r--r-- 3,309 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html

// This code is also subject to the license terms in the LICENSE_KinectFusion.md file found in this module's directory

#include "test_precomp.hpp"

#ifdef HAVE_OPENGL
namespace opencv_test { namespace {

static std::vector<std::string> readDepth(std::string fileList)
{
    std::vector<std::string> v;

    std::fstream file(fileList);
    if(!file.is_open())
        throw std::runtime_error("Failed to read depth list");

    std::string dir;
    size_t slashIdx = fileList.rfind('/');
    slashIdx = slashIdx != std::string::npos ? slashIdx : fileList.rfind('\\');
    dir = fileList.substr(0, slashIdx);

    while(!file.eof())
    {
        std::string s, imgPath;
        std::getline(file, s);
        if(s.empty() || s[0] == '#') continue;
        std::stringstream ss;
        ss << s;
        double thumb;
        ss >> thumb >> imgPath;
        v.push_back(dir+'/'+imgPath);
    }

    return v;
}

static const bool display = false;

void flyTest(bool hiDense, bool inequal)
{
    Ptr<kinfu::Params> params;
    if(hiDense)
        params = kinfu::Params::defaultParams();
    else
        params = kinfu::Params::coarseParams();

    if(inequal)
    {
        params->volumeDims[0] += 32;
        params->volumeDims[1] -= 32;
    }

    std::vector<String> depths = readDepth(cvtest::TS::ptr()->get_data_path() + "dynafu/depth.txt");
    CV_Assert(!depths.empty());

    Ptr<dynafu::DynaFu> df = dynafu::DynaFu::create(params);

    // Check for first 10 frames
    CV_Assert(depths.size() >= 10);
    Mat currentDepth, prevDepth;
    for(size_t i = 0; i < 10; i++)
    {
        currentDepth = cv::imread(depths[i], IMREAD_ANYDEPTH);

        ASSERT_TRUE(df->update(currentDepth));

        Mat renderedDepth;
        df->renderSurface(renderedDepth, noArray(), noArray());

        if(i > 0)
        {
            // Check if estimated depth aligns with actual depth in the previous frame
            Mat depthCvt8, renderCvt8;
            convertScaleAbs(prevDepth, depthCvt8, 0.25*256. / params->depthFactor);
            convertScaleAbs(renderedDepth, renderCvt8, 0.33*255, -0.5*0.33*255);

            Mat diff;
            absdiff(depthCvt8, renderCvt8, diff);

            Scalar_<float> mu, sigma;
            meanStdDev(diff, mu, sigma);
            std::cout << "Mean: " << mu[0] << ", Std dev: " << sigma[0] << std::endl;
        }

        if(display)
        {
            imshow("depth", currentDepth*(1.f/params->depthFactor/4.f));
            Mat rendered;
            df->render(rendered);
            imshow("render", rendered);
            waitKey(10);
        }

        currentDepth.copyTo(prevDepth);
    }
}

/*
#ifdef OPENCV_ENABLE_NONFREE
TEST( DynamicFusion, lowDense )
#else
TEST(DynamicFusion, DISABLED_lowDense)
#endif
{
    flyTest(false, false);
}

#ifdef OPENCV_ENABLE_NONFREE
TEST( DynamicFusion, inequal )
#else
TEST(DynamicFusion, DISABLED_inequal)
#endif
{
    flyTest(false, true);
}
*/

// To enable DynamicFusion tests, uncomment the above lines and delete the following lines
TEST(DynamicFusion, DISABLED)
{
    CV_UNUSED(flyTest);
}

}} // namespace

#endif