Point Cloud Library (PCL)
1.15.1
Toggle main menu visibility
Loading...
Searching...
No Matches
segmentation
include
pcl
cuda
segmentation
mssegmentation.h
1
// this file is extracted from OpenCV/modules/gpu/src/mssegmentation.cpp
2
// to get access to the intermediate results of meanShiftSegmentation()
3
// minor changes to compile correctly with pcl::cuda and namespace reorganization
4
5
/*M///////////////////////////////////////////////////////////////////////////////////////
6
//
7
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
8
//
9
// By downloading, copying, installing or using the software you agree to this license.
10
// If you do not agree to this license, do not download, install,
11
// copy or use the software.
12
//
13
//
14
// License Agreement
15
// For Open Source Computer Vision Library
16
//
17
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
18
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
19
// Third party copyrights are property of their respective owners.
20
//
21
// Redistribution and use in source and binary forms, with or without modification,
22
// are permitted provided that the following conditions are met:
23
//
24
// * Redistribution's of source code must retain the above copyright notice,
25
// this list of conditions and the following disclaimer.
26
//
27
// * Redistribution's in binary form must reproduce the above copyright notice,
28
// this list of conditions and the following disclaimer in the documentation
29
// and/or other materials provided with the distribution.
30
//
31
// * The name of the copyright holders may not be used to endorse or promote products
32
// derived from this software without specific prior written permission.
33
//
34
// This software is provided by the copyright holders and contributors "as is" and
35
// any express or implied warranties, including, but not limited to, the implied
36
// warranties of merchantability and fitness for a particular purpose are disclaimed.
37
// In no event shall the Intel Corporation or contributors be liable for any direct,
38
// indirect, incidental, special, exemplary, or consequential damages
39
// (including, but not limited to, procurement of substitute goods or services;
40
// loss of use, data, or profits; or business interruption) however caused
41
// and on any theory of liability, whether in contract, strict liability,
42
// or tort (including negligence or otherwise) arising in any way out of
43
// the use of this software, even if advised of the possibility of such damage.
44
//
45
//M*/
46
47
#pragma once
48
49
#include <pcl/pcl_exports.h>
50
51
#include <vector>
52
#include <opencv2/core/core.hpp>
53
#include <opencv2/gpu/gpu.hpp>
54
55
namespace
pcl
56
{
57
namespace
cuda
58
{
59
namespace
detail
60
{
61
62
//
63
// Declarations
64
//
65
66
class
DjSets
67
{
68
public
:
69
DjSets
(
int
n);
70
int
find
(
int
elem);
71
int
merge
(
int
set1,
int
set2);
72
73
void
init
(
int
n);
74
75
std::vector<int>
parent
;
76
std::vector<int>
rank
;
77
std::vector<int>
size
;
78
private
:
79
DjSets
(
const
DjSets
&);
80
void
operator =(
const
DjSets
&);
81
};
82
83
84
template
<
typename
T>
85
struct
GraphEdge
86
{
87
GraphEdge
() {}
88
GraphEdge
(
int
to
,
int
next
,
const
T&
val
) :
to
(
to
),
next
(
next
),
val
(
val
) {}
89
int
to
;
90
int
next
;
91
T
val
;
92
};
93
94
95
template
<
typename
T>
96
class
Graph
97
{
98
public
:
99
using
Edge
=
GraphEdge<T>
;
100
101
Graph
(
int
numv
,
int
nume_max
);
102
103
void
addEdge
(
int
from,
int
to,
const
T& val=T());
104
105
std::vector<int>
start
;
106
std::vector<Edge>
edges
;
107
108
int
numv
;
109
int
nume_max
;
110
int
nume
;
111
private
:
112
Graph
(
const
Graph
&);
113
void
operator =(
const
Graph
&);
114
};
115
116
117
struct
SegmLinkVal
118
{
119
SegmLinkVal
() {}
120
SegmLinkVal
(
int
dr
,
int
dsp
) :
dr
(
dr
),
dsp
(
dsp
) {}
121
bool
operator <
(
const
SegmLinkVal
& other)
const
122
{
123
return
dr
+
dsp
< other.
dr
+ other.
dsp
;
124
}
125
int
dr
;
126
int
dsp
;
127
};
128
129
130
struct
SegmLink
131
{
132
SegmLink
() {}
133
SegmLink
(
int
from
,
int
to
,
const
SegmLinkVal
&
val
)
134
:
from
(
from
),
to
(
to
),
val
(
val
) {}
135
bool
operator <
(
const
SegmLink
& other)
const
136
{
137
return
val
< other.
val
;
138
}
139
int
from
;
140
int
to
;
141
SegmLinkVal
val
;
142
};
143
144
//
145
// Implementation
146
//
147
148
DjSets::DjSets
(
int
n)
149
{
150
init
(n);
151
}
152
153
154
inline
int
DjSets::find
(
int
elem)
155
{
156
int
set = elem;
157
while
(set !=
parent
[set])
158
set =
parent
[set];
159
while
(elem !=
parent
[elem])
160
{
161
int
next =
parent
[elem];
162
parent
[elem] = set;
163
elem = next;
164
}
165
return
set;
166
}
167
168
inline
void
DjSets::init
(
int
n)
169
{
170
parent
.resize(n);
171
rank
.resize(n, 0);
172
size
.resize(n, 1);
173
for
(
int
i = 0; i < n; ++i)
174
parent
[i] = i;
175
}
176
177
inline
int
DjSets::merge
(
int
set1,
int
set2)
178
{
179
if
(
rank
[set1] <
rank
[set2])
180
{
181
parent
[set1] = set2;
182
size
[set2] +=
size
[set1];
183
return
set2;
184
}
185
if
(
rank
[set2] <
rank
[set1])
186
{
187
parent
[set2] = set1;
188
size
[set1] +=
size
[set2];
189
return
set1;
190
}
191
parent
[set1] = set2;
192
rank
[set2]++;
193
size
[set2] +=
size
[set1];
194
return
set2;
195
}
196
197
198
template
<
typename
T>
199
Graph<T>::Graph
(
int
numv
,
int
nume_max
) :
start
(
numv
, -1),
edges
(
nume_max
)
200
{
201
this->numv =
numv
;
202
this->nume_max =
nume_max
;
203
nume
= 0;
204
}
205
206
207
template
<
typename
T>
208
inline
void
Graph<T>::addEdge
(
int
from,
int
to,
const
T& val)
209
{
210
edges
[
nume
] =
Edge
(to,
start
[from], val);
211
start
[from] =
nume
;
212
nume
++;
213
}
214
215
216
inline
int
pix
(
int
y,
int
x,
int
ncols)
217
{
218
return
y * ncols + x;
219
}
220
221
222
inline
int
sqr
(
int
x)
223
{
224
return
x * x;
225
}
226
227
228
inline
int
dist2
(
const
cv::Vec4b& lhs,
const
cv::Vec4b& rhs)
229
{
230
return
sqr
(lhs[0] - rhs[0]) +
sqr
(lhs[1] - rhs[1]) +
sqr
(lhs[2] - rhs[2]);
231
}
232
233
234
inline
int
dist2
(
const
cv::Vec2s& lhs,
const
cv::Vec2s& rhs)
235
{
236
return
sqr
(lhs[0] - rhs[0]) +
sqr
(lhs[1] - rhs[1]);
237
}
238
239
}
// namespace
240
241
PCL_EXPORTS
void
meanShiftSegmentation
(
const
cv::gpu::GpuMat& src, cv::Mat& dst,
int
sp,
int
sr,
int
minsize,
detail::DjSets
&comps, cv::TermCriteria criteria = cv::TermCriteria(cv::TermCriteria::MAX_ITER + cv::TermCriteria::EPS, 5, 1) );
242
243
}
// namespace
244
}
// namespace
pcl::cuda::detail::DjSets
Definition
mssegmentation.h:67
pcl::cuda::detail::DjSets::DjSets
DjSets(int n)
Definition
mssegmentation.h:148
pcl::cuda::detail::DjSets::find
int find(int elem)
Definition
mssegmentation.h:154
pcl::cuda::detail::DjSets::init
void init(int n)
Definition
mssegmentation.h:168
pcl::cuda::detail::DjSets::rank
std::vector< int > rank
Definition
mssegmentation.h:76
pcl::cuda::detail::DjSets::parent
std::vector< int > parent
Definition
mssegmentation.h:75
pcl::cuda::detail::DjSets::size
std::vector< int > size
Definition
mssegmentation.h:77
pcl::cuda::detail::DjSets::merge
int merge(int set1, int set2)
Definition
mssegmentation.h:177
pcl::cuda::detail::Graph::Graph
Graph(int numv, int nume_max)
Definition
mssegmentation.h:199
pcl::cuda::detail::Graph::addEdge
void addEdge(int from, int to, const T &val=T())
Definition
mssegmentation.h:208
pcl::cuda::detail::Graph::start
std::vector< int > start
Definition
mssegmentation.h:105
pcl::cuda::detail::Graph::nume_max
int nume_max
Definition
mssegmentation.h:109
pcl::cuda::detail::Graph::nume
int nume
Definition
mssegmentation.h:110
pcl::cuda::detail::Graph::numv
int numv
Definition
mssegmentation.h:108
pcl::cuda::detail::Graph::Edge
GraphEdge< T > Edge
Definition
mssegmentation.h:99
pcl::cuda::detail::Graph::edges
std::vector< Edge > edges
Definition
mssegmentation.h:106
pcl::cuda::detail
Definition
mssegmentation.h:60
pcl::cuda::detail::sqr
int sqr(int x)
Definition
mssegmentation.h:222
pcl::cuda::detail::pix
int pix(int y, int x, int ncols)
Definition
mssegmentation.h:216
pcl::cuda::detail::dist2
int dist2(const cv::Vec4b &lhs, const cv::Vec4b &rhs)
Definition
mssegmentation.h:228
pcl::cuda
Definition
eigen.h:100
pcl::cuda::meanShiftSegmentation
PCL_EXPORTS void meanShiftSegmentation(const cv::gpu::GpuMat &src, cv::Mat &dst, int sp, int sr, int minsize, detail::DjSets &comps, cv::TermCriteria criteria=cv::TermCriteria(cv::TermCriteria::MAX_ITER+cv::TermCriteria::EPS, 5, 1))
pcl
Definition
convolution.h:46
pcl::cuda::detail::GraphEdge
Definition
mssegmentation.h:86
pcl::cuda::detail::GraphEdge::to
int to
Definition
mssegmentation.h:89
pcl::cuda::detail::GraphEdge::next
int next
Definition
mssegmentation.h:90
pcl::cuda::detail::GraphEdge::GraphEdge
GraphEdge(int to, int next, const T &val)
Definition
mssegmentation.h:88
pcl::cuda::detail::GraphEdge::val
T val
Definition
mssegmentation.h:91
pcl::cuda::detail::GraphEdge::GraphEdge
GraphEdge()
Definition
mssegmentation.h:87
pcl::cuda::detail::SegmLink::operator<
bool operator<(const SegmLink &other) const
Definition
mssegmentation.h:135
pcl::cuda::detail::SegmLink::val
SegmLinkVal val
Definition
mssegmentation.h:141
pcl::cuda::detail::SegmLink::SegmLink
SegmLink()
Definition
mssegmentation.h:132
pcl::cuda::detail::SegmLink::to
int to
Definition
mssegmentation.h:140
pcl::cuda::detail::SegmLink::from
int from
Definition
mssegmentation.h:139
pcl::cuda::detail::SegmLink::SegmLink
SegmLink(int from, int to, const SegmLinkVal &val)
Definition
mssegmentation.h:133
pcl::cuda::detail::SegmLinkVal
Definition
mssegmentation.h:118
pcl::cuda::detail::SegmLinkVal::dr
int dr
Definition
mssegmentation.h:125
pcl::cuda::detail::SegmLinkVal::dsp
int dsp
Definition
mssegmentation.h:126
pcl::cuda::detail::SegmLinkVal::SegmLinkVal
SegmLinkVal(int dr, int dsp)
Definition
mssegmentation.h:120
pcl::cuda::detail::SegmLinkVal::SegmLinkVal
SegmLinkVal()
Definition
mssegmentation.h:119
pcl::cuda::detail::SegmLinkVal::operator<
bool operator<(const SegmLinkVal &other) const
Definition
mssegmentation.h:121