31#include "vpTutoSegmentation.h"
33#include <visp3/core/vpGaussRand.h>
34#include <visp3/core/vpHSV.h>
36#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
37#ifndef DOXYGEN_SHOULD_SKIP_THIS
40#ifdef ENABLE_VISP_NAMESPACE
41using namespace VISP_NAMESPACE_NAME;
44void performSegmentationHSV(vpTutoCommonData &data)
46 vpImage<vpHSV<unsigned char, true>> Ihsv;
55std::vector< VISP_NAMESPACE_ADDRESSING vpImagePoint > extractSkeleton(vpTutoCommonData &data)
59 data.m_Iskeleton.resize(height, width, 0);
60 std::vector<vpImagePoint> points;
64 for (
int x = 0;
x <
width - 1; ++
x) {
65 if ((
data.m_mask[y][x] > 0) && (
data.m_mask[y][x + 1] > 0)) {
70 else if (
data.m_mask[y][x] > 0) {
74 cx =
static_cast<int>(((left +
x) - 1) * 0.5f);
76 vpImagePoint pt(y, cx);
78 data.m_Iskeleton[
y][cx] = 255;
85 for (
int x = 0;
x <
width; ++
x) {
87 for (
int y = 0;
y <
height - 1; ++
y) {
88 if ((
data.m_mask[y][x] > 0) && (
data.m_mask[y + 1][x] > 0)) {
93 else if (
data.m_mask[y][x] > 0) {
96 cy =
static_cast<int>(((top +
y) - 1) * 0.5f);
98 if (
data.m_Iskeleton[cy][x] == 0) {
99 vpImagePoint pt(cy, x);
100 points.push_back(pt);
101 data.m_Iskeleton[cy][
x] = 255;
110std::vector< vpImagePoint > addSaltAndPepperNoise(
const std::vector< vpImagePoint > &noisefreePts, vpTutoCommonData &data)
112 const unsigned int nbNoiseFreePts =
static_cast<unsigned int>(noisefreePts.size());
113 const unsigned int nbPtsToAdd =
static_cast<unsigned int>(
data.m_ratioSaltPepperNoise * nbNoiseFreePts);
114 const double width =
data.m_Iskeleton.getWidth();
115 const double height =
data.m_Iskeleton.getHeight();
116 data.m_IskeletonNoisy =
data.m_Iskeleton;
119 std::vector<vpImagePoint> noisyPts = noisefreePts;
120 for (
unsigned int i = 0;
i < nbPtsToAdd + 1; ++
i) {
121 double uNormalized = rngX();
122 double vNormalized = rngY();
124 uNormalized = std::max(uNormalized, 0.);
125 uNormalized = std::min(uNormalized, 0.99999);
126 vNormalized = std::max(vNormalized, 0.);
127 vNormalized = std::min(vNormalized, 0.99999);
129 double u = uNormalized *
width;
130 double v = vNormalized *
height;
132 vpImagePoint pt(v, u);
133 noisyPts.push_back(pt);
134 data.m_IskeletonNoisy[
static_cast<int>(
v)][
static_cast<int>(u)] = 255;
141void dummy_vpTutoSegmentation() { }
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
VISP_EXPORT double measureTimeMicros()