Point Cloud Library (PCL)
1.15.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
io
openni2
openni_shift_to_depth_conversion.h
1
/*
2
* Software License Agreement (BSD License)
3
*
4
* Point Cloud Library (PCL) - www.pointclouds.org
5
* Copyright (c) 2011 Willow Garage, Inc.
6
* Copyright (c) 2012-, Open Perception, Inc.
7
*
8
* All rights reserved.
9
*
10
* Redistribution and use in source and binary forms, with or without
11
* modification, are permitted provided that the following conditions
12
* are met:
13
*
14
* * Redistributions of source code must retain the above copyright
15
* notice, this list of conditions and the following disclaimer.
16
* * Redistributions in binary form must reproduce the above
17
* copyright notice, this list of conditions and the following
18
* disclaimer in the documentation and/or other materials provided
19
* with the distribution.
20
* * Neither the name of the copyright holder(s) nor the names of its
21
* contributors may be used to endorse or promote products derived
22
* from this software without specific prior written permission.
23
*
24
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
* POSSIBILITY OF SUCH DAMAGE.
36
*
37
*/
38
39
#pragma once
40
41
#include <pcl/pcl_config.h>
42
#ifdef HAVE_OPENNI2
43
44
#include <cassert>
// for assert
45
#include <vector>
46
#include <limits>
47
48
namespace
openni_wrapper
49
{
50
/** \brief This class provides conversion of the openni 11-bit shift data to depth;
51
*/
52
class
PCL_EXPORTS
ShiftToDepthConverter
53
{
54
public
:
55
/** \brief Constructor. */
56
ShiftToDepthConverter () =
default
;
57
58
/** \brief This method generates a look-up table to convert openni shift values to depth
59
*/
60
void
61
generateLookupTable ()
62
{
63
// lookup of 11 bit shift values
64
constexpr
std::size_t table_size = 1<<10;
65
66
lookupTable_.clear();
67
lookupTable_.resize(table_size);
68
69
// constants taken from openni driver
70
constexpr
std::int16_t nConstShift = 800;
71
constexpr
double
nParamCoeff = 4.000000;
72
constexpr
double
dPlanePixelSize = 0.104200;
73
constexpr
double
nShiftScale = 10.000000;
74
constexpr
double
dPlaneDsr = 120.000000;
75
constexpr
double
dPlaneDcl = 7.500000;
76
77
for
(std::size_t i=0; i<table_size; ++i)
78
{
79
// shift to depth calculation from opnni
80
double
dFixedRefX = (
static_cast<
double
>
(i - nConstShift) / nParamCoeff)-0.375;
81
double
dMetric = dFixedRefX * dPlanePixelSize;
82
lookupTable_[i] =
static_cast<
float
>
((nShiftScale * ((dMetric * dPlaneDsr / (dPlaneDcl - dMetric)) + dPlaneDsr) ) / 1000.0f);
83
}
84
85
init_ =
true
;
86
}
87
88
/** \brief Generate a look-up table for converting openni shift values to depth
89
*/
90
inline
float
91
shiftToDepth (std::uint16_t shift_val)
92
{
93
assert (init_);
94
95
static
const
float
bad_point = std::numeric_limits<float>::quiet_NaN ();
96
97
float
ret = bad_point;
98
99
// lookup depth value in shift lookup table
100
if
(shift_val<lookupTable_.size())
101
ret = lookupTable_[shift_val];
102
103
return
ret;
104
}
105
106
inline
bool
isInitialized()
const
107
{
108
return
init_;
109
}
110
111
protected
:
112
std::vector<float> lookupTable_;
113
bool
init_{
false
};
114
} ;
115
}
116
#endif
openni_wrapper::ShiftToDepthConverter
This class provides conversion of the openni 11-bit shift data to depth;.
Definition
openni_shift_to_depth_conversion.h:54
openni_wrapper
Definition
openni_depth_image.h:52
PCL_EXPORTS
#define PCL_EXPORTS
Definition
pcl_macros.h:324