Loading...
Searching...
No Matches
internal.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2011, Willow Garage, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @authors: Cedric Cagniart, Koen Buys, Anatoly Baksheev
*/
#pragma once
#include <pcl/gpu/containers/device_array.h>
#include <pcl/gpu/utils/safe_call.hpp>
#include <pcl/gpu/people/label_common.h>
#include <pcl/gpu/people/tree.h>
using pcl::gpu::people::NUM_PARTS;
namespace pcl
{
namespace device
{
using Cloud = DeviceArray2D<float4>;
using Image = DeviceArray2D<uchar4>;
using Depth = DeviceArray2D<unsigned short>;
using Labels = DeviceArray2D<unsigned char>;
using HueImage = DeviceArray2D<float>;
using Mask = DeviceArray2D<unsigned char>;
using MultiLabels = DeviceArray2D<char4>;
/** \brief The intrinsic camera calibration **/
struct Intr
{
float fx, fy, cx, cy;
Intr () {}
Intr (float fx_, float fy_, float cx_, float cy_) : fx(fx_), fy(fy_), cx(cx_), cy(cy_) {}
void setDefaultPPIfIncorrect(int cols, int rows)
{
cx = cx > 0 ? cx : cols/2 - 0.5f;
cy = cy > 0 ? cy : rows/2 - 0.5f;
}
};
void smoothLabelImage(const Labels& src, const Depth& depth, Labels& dst, int num_parts, int patch_size, int depthThres);
void colorLMap(const Labels& labels, const DeviceArray<uchar4>& cmap, Image& rgb);
void mixedColorMap(const Labels& labels, const DeviceArray<uchar4>& map, const Image& rgba, Image& output);
////////////// connected components ///////////////////
struct ConnectedComponents
{
static void initEdges(int rows, int cols, DeviceArray2D<unsigned char>& edges);
//static void computeEdges(const Labels& labels, const Cloud& cloud, int num_parts, float sq_radius, DeviceArray2D<unsigned char>& edges);
static void computeEdges(const Labels& labels, const Depth& depth, int num_parts, float sq_radius, DeviceArray2D<unsigned char>& edges);
static void labelComponents(const DeviceArray2D<unsigned char>& edges, DeviceArray2D<int>& comps);
};
void computeCloud(const Depth& depth, const Intr& intr, Cloud& cloud);
void setZero(Mask& mask);
void prepareForeGroundDepth(const Depth& depth1, Mask& inverse_mask, Depth& depth2);
float computeHue(int rgba);
void computeHueWithNans(const Image& image, const Depth& depth, HueImage& hue);
//void shs(const DeviceArray2D<float4> &cloud, float tolerance, const std::vector<int>& indices_in, float delta_hue, Mask& indices_out);
struct Dilatation
{
using Kernel = DeviceArray<unsigned char>;
enum
{
KSIZE_X = 5,
KSIZE_Y = 5,
ANCH_X = KSIZE_X/2,
ANCH_Y = KSIZE_Y/2,
};
static void prepareRect5x5Kernel(Kernel& kernel);
static void invoke(const Mask& src, const Kernel& kernel, Mask& dst);
};
/** \brief Struct that holds a single RDF tree in GPU **/
struct CUDATree
{
using Node = pcl::gpu::people::trees::Node;
using Label = pcl::gpu::people::trees::Label;
int treeHeight;
int numNodes;
DeviceArray<Node> nodes_device;
DeviceArray<Label> leaves_device;
CUDATree (int treeHeight_, const std::vector<Node>& nodes, const std::vector<Label>& leaves);
};
/** \brief Processor using multiple trees */
class MultiTreeLiveProc
{
public:
/** \brief Constructor with default values, allocates multilmap device memory **/
MultiTreeLiveProc(int def_rows = 480, int def_cols = 640) : multilmap (def_rows, def_cols) {}
void
process (const Depth& dmap, Labels& lmap);
/** \brief same as process, but runs the trick of declaring as background any neighbor that is more than FGThresh away.**/
void
process (const Depth& dmap, Labels& lmap, int FGThresh);
/** \brief output a probability map from the RDF.**/
void
processProb (const Depth& dmap, Labels& lmap, LabelProbability& prob, int FGThresh);
std::vector<CUDATree> trees;
MultiLabels multilmap;
};
/** \brief Implementation Class to process probability histograms on GPU **/
class ProbabilityProc
{
public:
/** \brief Default constructor **/
ProbabilityProc()
{
std::cout << "[pcl::device::ProbabilityProc:ProbabilityProc] : (D) : Constructor called" << std::endl;
//PCL_DEBUG("[pcl::device::ProbabilityProc:ProbabilityProc] : (D) : Constructor called");
}
/** \brief This will merge the votes from the different trees into one final vote, including probabilistic's **/
void
CUDA_SelectLabel ( const Depth& depth, Labels& labels, LabelProbability& probabilities);
/** \brief This will combine two probabilities according their weight **/
void
CUDA_CombineProb ( const Depth& depth, LabelProbability& probIn1, float weight1,
LabelProbability& probIn2, float weight2, LabelProbability& probOut);
/** \brief This will sum a probability multiplied with it's weight **/
void
CUDA_WeightedSumProb ( const Depth& depth, LabelProbability& probIn, float weight, LabelProbability& probOut);
/** \brief This will blur the input labelprobability with the given kernel **/
int
CUDA_GaussianBlur( const Depth& depth,
LabelProbability& probIn,
DeviceArray<float>& kernel,
LabelProbability& probOut);
/** \brief This will blur the input labelprobability with the given kernel, this version avoids extended allocation **/
int
CUDA_GaussianBlur( const Depth& depth,
LabelProbability& probIn,
DeviceArray<float>& kernel,
LabelProbability& probTemp,
LabelProbability& probOut);
};
}
}
pcl::device::MultiTreeLiveProc::process
void process(const Depth &dmap, Labels &lmap, int FGThresh)
same as process, but runs the trick of declaring as background any neighbor that is more than FGThres...
pcl::device::MultiTreeLiveProc::multilmap
MultiLabels multilmap
Definition internal.h:149
pcl::device::MultiTreeLiveProc::processProb
void processProb(const Depth &dmap, Labels &lmap, LabelProbability &prob, int FGThresh)
output a probability map from the RDF.
pcl::device::MultiTreeLiveProc::process
void process(const Depth &dmap, Labels &lmap)
pcl::device::MultiTreeLiveProc::MultiTreeLiveProc
MultiTreeLiveProc(int def_rows=480, int def_cols=640)
Constructor with default values, allocates multilmap device memory.
Definition internal.h:135
pcl::device::MultiTreeLiveProc::trees
std::vector< CUDATree > trees
Definition internal.h:148
pcl::device::ProbabilityProc::CUDA_GaussianBlur
int CUDA_GaussianBlur(const Depth &depth, LabelProbability &probIn, DeviceArray< float > &kernel, LabelProbability &probTemp, LabelProbability &probOut)
This will blur the input labelprobability with the given kernel, this version avoids extended allocat...
pcl::device::ProbabilityProc::CUDA_GaussianBlur
int CUDA_GaussianBlur(const Depth &depth, LabelProbability &probIn, DeviceArray< float > &kernel, LabelProbability &probOut)
This will blur the input labelprobability with the given kernel.
pcl::device::ProbabilityProc::CUDA_WeightedSumProb
void CUDA_WeightedSumProb(const Depth &depth, LabelProbability &probIn, float weight, LabelProbability &probOut)
This will sum a probability multiplied with it's weight.
pcl::device::ProbabilityProc::ProbabilityProc
ProbabilityProc()
Default constructor.
Definition internal.h:157
pcl::device::ProbabilityProc::CUDA_CombineProb
void CUDA_CombineProb(const Depth &depth, LabelProbability &probIn1, float weight1, LabelProbability &probIn2, float weight2, LabelProbability &probOut)
This will combine two probabilities according their weight.
pcl::device::ProbabilityProc::CUDA_SelectLabel
void CUDA_SelectLabel(const Depth &depth, Labels &labels, LabelProbability &probabilities)
This will merge the votes from the different trees into one final vote, including probabilistic's.
pcl::gpu::DeviceArray2D
DeviceArray2D class
Definition device_array.h:188
pcl::gpu::DeviceArray
DeviceArray class
Definition device_array.h:54
pcl::kernel
Definition kernel.h:46
pcl::device
Definition device_array.h:315
pcl::device::Cloud
DeviceArray2D< float4 > Cloud
Definition internal.h:52
pcl::device::smoothLabelImage
void smoothLabelImage(const Labels &src, const Depth &depth, Labels &dst, int num_parts, int patch_size, int depthThres)
pcl::device::HueImage
DeviceArray2D< float > HueImage
Definition internal.h:57
pcl::device::computeCloud
void computeCloud(const Depth &depth, const Intr &intr, Cloud &cloud)
pcl::device::MultiLabels
DeviceArray2D< char4 > MultiLabels
Definition internal.h:60
pcl::device::Mask
DeviceArray2D< unsigned char > Mask
Definition internal.h:58
pcl::device::Depth
DeviceArray2D< unsigned short > Depth
Definition internal.h:55
pcl::device::Image
DeviceArray2D< uchar4 > Image
Definition internal.h:53
pcl::device::colorLMap
void colorLMap(const Labels &labels, const DeviceArray< uchar4 > &cmap, Image &rgb)
pcl::device::LabelProbability
DeviceArray2D< prob_histogram > LabelProbability
Definition label_common.h:264
pcl::device::mixedColorMap
void mixedColorMap(const Labels &labels, const DeviceArray< uchar4 > &map, const Image &rgba, Image &output)
pcl::device::computeHueWithNans
void computeHueWithNans(const Image &image, const Depth &depth, HueImage &hue)
pcl::device::setZero
void setZero(Mask &mask)
pcl::device::computeHue
float computeHue(int rgba)
pcl::device::Labels
DeviceArray2D< unsigned char > Labels
Definition internal.h:56
pcl::device::prepareForeGroundDepth
void prepareForeGroundDepth(const Depth &depth1, Mask &inverse_mask, Depth &depth2)
pcl::gpu::people::trees::Label
std::uint8_t Label
Definition tree.h:73
pcl::gpu::people::NUM_PARTS
@ NUM_PARTS
Definition label_common.h:60
pcl
Definition convolution.h:46
pcl::device::CUDATree::Label
pcl::gpu::people::trees::Label Label
Definition internal.h:119
pcl::device::CUDATree::Node
pcl::gpu::people::trees::Node Node
Definition internal.h:118
pcl::device::CUDATree::numNodes
int numNodes
Definition internal.h:122
pcl::device::CUDATree::leaves_device
DeviceArray< Label > leaves_device
Definition internal.h:125
pcl::device::CUDATree::nodes_device
DeviceArray< Node > nodes_device
Definition internal.h:124
pcl::device::CUDATree::treeHeight
int treeHeight
Definition internal.h:121
pcl::device::CUDATree::CUDATree
CUDATree(int treeHeight_, const std::vector< Node > &nodes, const std::vector< Label > &leaves)
pcl::device::ConnectedComponents
Definition internal.h:83
pcl::device::ConnectedComponents::computeEdges
static void computeEdges(const Labels &labels, const Depth &depth, int num_parts, float sq_radius, DeviceArray2D< unsigned char > &edges)
pcl::device::ConnectedComponents::labelComponents
static void labelComponents(const DeviceArray2D< unsigned char > &edges, DeviceArray2D< int > &comps)
pcl::device::ConnectedComponents::initEdges
static void initEdges(int rows, int cols, DeviceArray2D< unsigned char > &edges)
pcl::device::Dilatation
Definition internal.h:101
pcl::device::Dilatation::Kernel
DeviceArray< unsigned char > Kernel
Definition internal.h:102
pcl::device::Dilatation::prepareRect5x5Kernel
static void prepareRect5x5Kernel(Kernel &kernel)
pcl::device::Dilatation::invoke
static void invoke(const Mask &src, const Kernel &kernel, Mask &dst)
pcl::device::Dilatation::ANCH_X
@ ANCH_X
Definition internal.h:107
pcl::device::Dilatation::KSIZE_X
@ KSIZE_X
Definition internal.h:105
pcl::device::Dilatation::KSIZE_Y
@ KSIZE_Y
Definition internal.h:106
pcl::device::Dilatation::ANCH_Y
@ ANCH_Y
Definition internal.h:108
pcl::device::Intr
Camera intrinsics structure.
Definition internal.h:69
pcl::device::Intr::fy
float fy
Definition internal.h:70
pcl::device::Intr::fx
float fx
Definition internal.h:70
pcl::device::Intr::cy
float cy
Definition internal.h:70
pcl::device::Intr::setDefaultPPIfIncorrect
void setDefaultPPIfIncorrect(int cols, int rows)
Definition internal.h:69
pcl::device::Intr::cx
float cx
Definition internal.h:70
pcl::device::Intr::Intr
Intr()
Definition internal.h:66
pcl::device::Intr::Intr
Intr(float fx_, float fy_, float cx_, float cy_)
Definition internal.h:67
pcl::gpu::people::trees::Node
Definition tree.h:92