Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpColorHistogramMask.h
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4
*
5
* This software is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
* See the file LICENSE.txt at the root directory of this source
10
* distribution for additional information about the GNU GPL.
11
*
12
* For using ViSP with software that can not be combined with the GNU
13
* GPL, please contact Inria about acquiring a ViSP Professional
14
* Edition License.
15
*
16
* See https://visp.inria.fr for more information.
17
*
18
* This software was developed at:
19
* Inria Rennes - Bretagne Atlantique
20
* Campus Universitaire de Beaulieu
21
* 35042 Rennes Cedex
22
* France
23
*
24
* If you have questions regarding the use of this file, please contact
25
* Inria at visp@inria.fr
26
*
27
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
*/
30
35
#ifndef VP_COLOR_HISTOGRAM_MASK_H
36
#define VP_COLOR_HISTOGRAM_MASK_H
37
38
#include <visp3/core/vpConfig.h>
39
#include <visp3/core/vpException.h>
40
#include <visp3/rbt/vpColorHistogram.h>
41
#include <visp3/rbt/vpObjectMask.h>
42
#include <visp3/core/vpDisplay.h>
43
#include <visp3/core/vpImage.h>
44
45
#ifdef VISP_HAVE_NLOHMANN_JSON
46
#include VISP_NLOHMANN_JSON(json_fwd.hpp)
47
#endif
48
49
BEGIN_VISP_NAMESPACE
50
51
class
vpRBFeatureTrackerInput
;
52
64
class
VISP_EXPORT
vpColorHistogramMask
:
public
vpObjectMask
65
{
66
public
:
67
vpColorHistogramMask
();
68
virtual
~vpColorHistogramMask
() =
default
;
69
70
void
updateMask
(
const
vpRBFeatureTrackerInput
&frame,
71
const
vpRBFeatureTrackerInput
&previousFrame,
72
vpImage<float>
&mask) VP_OVERRIDE;
73
78
void
setBinNumber
(
unsigned
int
N)
79
{
80
m_histBackground.setBinNumber(N);
81
m_histBackgroundFrame.setBinNumber(N);
82
m_histObject.setBinNumber(N);
83
m_histObjectFrame.setBinNumber(N);
84
}
85
86
float
getDepthErrorTolerance
()
const
{
return
m_depthErrorTolerance; }
87
void
setDepthErrorTolerance
(
float
errorMax)
88
{
89
if
(errorMax < 0.f) {
90
throw
vpException
(
vpException::badValue
,
"Depth error tolerance in histogram computation should be > 0"
);
91
}
92
m_depthErrorTolerance = errorMax;
93
}
94
95
float
getObjectUpdateRate
()
const
{
return
m_objectUpdateRate; }
96
void
setObjectUpdateRate
(
float
updateRate)
97
{
98
if
(updateRate < 0.f || updateRate > 1.f) {
99
throw
vpException
(
vpException::badValue
,
"Histogram update rate should be between 0 and 1 (included)"
);
100
}
101
m_objectUpdateRate = updateRate;
102
}
103
104
float
getBackgroundUpdateRate
()
const
{
return
m_backgroundUpdateRate; }
105
void
setBackgroundUpdateRate
(
float
updateRate)
106
{
107
if
(updateRate < 0.f || updateRate > 1.f) {
108
throw
vpException
(
vpException::badValue
,
"Histogram update rate should be between 0 and 1 (included)"
);
109
}
110
m_backgroundUpdateRate = updateRate;
111
}
112
113
bool
isComputedOnlyOnBoundingBox
()
const
{
return
m_computeOnBBOnly; }
114
void
setComputeOnlyOnBoundingBox
(
bool
bbOnly)
115
{
116
m_computeOnBBOnly = bbOnly;
117
}
118
121
122
void
display
(
const
vpImage<float>
&mask,
vpImage<unsigned char>
&Imask)
const
VP_OVERRIDE
123
{
124
vpObjectMask::display
(mask, Imask);
125
unsigned
int
numColor = 10;
126
unsigned
int
y = 50;
127
unsigned
int
pady = 20;
128
unsigned
int
pad = 5;
129
unsigned
int
radius = 5;
130
131
std::vector<vpRGBa> bestColors = m_histObject.mostLikelyColors(numColor);
132
std::vector<vpRGBa> bestColorsBg = m_histBackground.mostLikelyColors(numColor);
133
134
135
for
(
unsigned
int
i = 0; i < bestColors.size(); ++i) {
136
vpColor
c;
137
c.
R
= bestColors[i].R;
138
c.
G
= bestColors[i].G;
139
c.
B
= bestColors[i].B;
140
c.
A
= 255;
141
142
vpDisplay::displayText
(Imask, y, pad,
"Most likely object colors: "
,
vpColor::red
);
143
vpDisplay::displayCircle
(Imask, y + pady, pad * 2 + (i * radius * 2 + (i - 1) * pad), radius, c,
true
);
144
145
c.
R
= bestColorsBg[i].R;
146
c.
G
= bestColorsBg[i].G;
147
c.
B
= bestColorsBg[i].B;
148
c.
A
= 255;
149
150
vpDisplay::displayText
(Imask, y + pady * 2, pad,
"Most likely background colors: "
,
vpColor::red
);
151
vpDisplay::displayCircle
(Imask, y + pady * 3, pad * 2 + (i * radius * 2 + (i - 1) * pad), radius, c,
true
);
152
}
153
}
154
155
virtual
void
reset
() VP_OVERRIDE
156
{
157
setBinNumber
(m_histObject.getBinNumber());
158
}
159
160
#if defined(VISP_HAVE_NLOHMANN_JSON)
161
void
loadJsonConfiguration
(
const
nlohmann::json &json) VP_OVERRIDE;
162
#endif
163
164
private
:
165
vpColorHistogram
m_histObject, m_histBackground, m_histObjectFrame, m_histBackgroundFrame;
166
float
m_depthErrorTolerance;
167
float
m_objectUpdateRate, m_backgroundUpdateRate;
168
float
m_threshold;
169
170
vpImage<bool>
m_mask;
171
vpImage<float>
m_probaObject, m_probaBackground;
172
173
bool
m_computeOnBBOnly;
174
};
175
176
END_VISP_NAMESPACE
177
178
#endif
vpColorHistogramMask::getDepthErrorTolerance
float getDepthErrorTolerance() const
Definition
vpColorHistogramMask.h:86
vpColorHistogramMask::getObjectUpdateRate
float getObjectUpdateRate() const
Definition
vpColorHistogramMask.h:95
vpColorHistogramMask::reset
virtual void reset() VP_OVERRIDE
Definition
vpColorHistogramMask.h:155
vpColorHistogramMask::~vpColorHistogramMask
virtual ~vpColorHistogramMask()=default
vpColorHistogramMask::isComputedOnlyOnBoundingBox
bool isComputedOnlyOnBoundingBox() const
Definition
vpColorHistogramMask.h:113
vpColorHistogramMask::setComputeOnlyOnBoundingBox
void setComputeOnlyOnBoundingBox(bool bbOnly)
Definition
vpColorHistogramMask.h:114
vpColorHistogramMask::getBackgroundUpdateRate
float getBackgroundUpdateRate() const
Definition
vpColorHistogramMask.h:104
vpColorHistogramMask::setBinNumber
void setBinNumber(unsigned int N)
Definition
vpColorHistogramMask.h:78
vpColorHistogramMask::setDepthErrorTolerance
void setDepthErrorTolerance(float errorMax)
Definition
vpColorHistogramMask.h:87
vpColorHistogramMask::vpColorHistogramMask
vpColorHistogramMask()
Definition
vpColorHistogramMask.cpp:85
vpColorHistogramMask::display
void display(const vpImage< float > &mask, vpImage< unsigned char > &Imask) const VP_OVERRIDE
Definition
vpColorHistogramMask.h:122
vpColorHistogramMask::setObjectUpdateRate
void setObjectUpdateRate(float updateRate)
Definition
vpColorHistogramMask.h:96
vpColorHistogramMask::setBackgroundUpdateRate
void setBackgroundUpdateRate(float updateRate)
Definition
vpColorHistogramMask.h:105
vpColorHistogram
Histogram representation of an RGB color distribution In this representation, probabilities are store...
Definition
vpColorHistogram.h:57
vpColor
Class to define RGB colors available for display functionalities.
Definition
vpColor.h:157
vpColor::red
static const vpColor red
Definition
vpColor.h:198
vpDisplay::displayCircle
static void displayCircle(const vpImage< unsigned char > &I, const vpImageCircle &circle, const vpColor &color, bool fill=false, unsigned int thickness=1)
Definition
vpDisplay_uchar.cpp:154
vpDisplay::displayText
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Definition
vpDisplay_uchar.cpp:788
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpException::badValue
@ badValue
Used to indicate that a value is not in the allowed range.
Definition
vpException.h:73
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpObjectMask::loadJsonConfiguration
virtual void loadJsonConfiguration(const nlohmann::json &j)=0
vpObjectMask::display
virtual void display(const vpImage< float > &mask, vpImage< unsigned char > &Imask) const
Definition
vpObjectMask.cpp:37
vpObjectMask::updateMask
virtual void updateMask(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, vpImage< float > &mask)=0
vpObjectMask::vpObjectMask
vpObjectMask()
Definition
vpObjectMask.h:65
vpRBFeatureTrackerInput
All the data related to a single tracking frame. This contains both the input data (from a real camer...
Definition
vpRBFeatureTrackerInput.h:126
vpRGBa::B
unsigned char B
Blue component.
Definition
vpRGBa.h:327
vpRGBa::R
unsigned char R
Red component.
Definition
vpRGBa.h:325
vpRGBa::G
unsigned char G
Green component.
Definition
vpRGBa.h:326
vpRGBa::A
unsigned char A
Additional component.
Definition
vpRGBa.h:328
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
tracker
rbt
include
visp3
rbt
vpColorHistogramMask.h
Generated by
1.17.0