HsvImageSegmentation.cpp
Go to the documentation of this file.
2
4
5
6using namespace armarx;
7
11
13 numImages(imageProviderInfo.numberImages),
14 width(imageProviderInfo.imageFormat.dimension.width),
15 height(imageProviderInfo.imageFormat.dimension.height)
16{
17 if (numImages <= 0)
18 {
19 std::stringstream ss;
20 ss << "Tried to initialize HsvImageSegmentation with " << numImages
21 << " images, but need at least 1 image.";
22 throw std::invalid_argument(ss.str());
23 }
24
25 allocate(imageProviderInfo);
26}
27
32
37
40{
41 if (this != &other)
42 {
43 deallocate();
44 moveFrom(other);
45 }
46 return *this;
47}
48
49CByteImage**
51{
52 return inputImagesRgb;
53}
54
55CByteImage**
57{
58 return inputImagesHsv;
59}
60
61CByteImage**
63{
64 return inputVisuImages;
65}
66
67CByteImage**
69{
70 return outputImagesGray;
71}
72
73CByteImage**
75{
76 return outputImagesRgb;
77}
78
79int
81{
82 return numImages;
83}
84
85void
87 int hueTol,
88 int satMin,
89 int satMax,
90 int valMin,
91 int valMax)
92{
93 // segment all input images
94 // #pragma omp for // seems to get ignored
95 for (int i = 0; i < numImages; ++i)
96 {
97 ::ImageProcessor::CopyImage(inputImagesRgb[i], inputVisuImages[i]);
98
99 // convert to HSV
100 ::ImageProcessor::CalculateHSVImage(inputImagesRgb[i], inputImagesHsv[i]);
101
102 // filter HSV (-> gray scale image)
103 ::ImageProcessor::FilterHSV(
104 inputImagesHsv[i], outputImagesGray[i], hue, hueTol, satMin, satMax, valMin, valMax);
105
106 // convert gray scale to RGB
107 ::ImageProcessor::ConvertImage(outputImagesGray[i], outputImagesRgb[i], true);
108 }
109}
110
111void
112HsvImageSegmentation::allocate(const visionx::ImageProviderInfo& imageProviderInfo)
113{
114 inputImagesRgb = new CByteImage*[numImages];
115 inputVisuImages = new CByteImage*[numImages];
116 inputImagesHsv = new CByteImage*[numImages];
117 outputImagesGray = new CByteImage*[numImages];
118 outputImagesRgb = new CByteImage*[numImages];
119
120 for (int i = 0; i < numImages; ++i)
121 {
122 inputImagesRgb[i] = visionx::tools::createByteImage(imageProviderInfo);
123 inputVisuImages[i] = visionx::tools::createByteImage(imageProviderInfo);
124 inputImagesHsv[i] = visionx::tools::createByteImage(imageProviderInfo);
125 outputImagesGray[i] = new CByteImage(width, height, CByteImage::eGrayScale);
126 outputImagesRgb[i] = visionx::tools::createByteImage(imageProviderInfo);
127 }
128}
129
130void
131HsvImageSegmentation::deallocate()
132{
133 if (numImages != 0)
134 {
135 for (int i = 0; i < numImages; ++i)
136 {
137 delete inputImagesRgb[i];
138 delete inputVisuImages[i];
139 delete inputImagesHsv[i];
140 delete outputImagesGray[i];
141 delete outputImagesRgb[i];
142 }
143
144 delete[] inputImagesRgb;
145 delete[] inputVisuImages;
146 delete[] inputImagesHsv;
147 delete[] outputImagesGray;
148 delete[] outputImagesRgb;
149
150 inputImagesRgb = nullptr;
151 inputVisuImages = nullptr;
152 inputImagesHsv = nullptr;
153 outputImagesGray = nullptr;
154 outputImagesRgb = nullptr;
155 }
156}
157
158void
159HsvImageSegmentation::moveFrom(HsvImageSegmentation& other)
160{
161 this->numImages = other.numImages;
162 this->height = other.height;
163 this->width = other.width;
164
165 // steal image buffers
166 this->inputImagesRgb = other.inputImagesRgb;
167 this->inputVisuImages = other.inputVisuImages;
168 this->inputImagesHsv = other.inputImagesHsv;
169 this->outputImagesGray = other.outputImagesGray;
170 this->outputImagesRgb = other.outputImagesRgb;
171
172 // reset others state to default
173 other.numImages = other.height = other.width = 0;
174 other.inputImagesRgb = other.inputImagesHsv = other.inputVisuImages = nullptr;
175 other.outputImagesGray = other.outputImagesRgb = nullptr;
176}
The HsvImageSegmentation class.
HsvImageSegmentation()
No-initialization constructor.
CByteImage ** getOutputImagesRgb() const
Get the output images in RGB (from gray scale).
CByteImage ** getInputImagesHsv() const
Get the input images in HSV.
HsvImageSegmentation & operator=(HsvImageSegmentation &&other)
void processInputImages(int hue, int hueTol, int satMin, int satMax, int valMin, int valMax)
Processes the current input images.
CByteImage ** getOutputImagesGray() const
Get the output images in gray scale.
CByteImage ** getInputVisuImages() const
Get input visualization images.
~HsvImageSegmentation()
Frees all allocated memory.
CByteImage ** getInputImagesRgb() const
Get the input images (RGB) (buffer).
This file offers overloads of toIce() and fromIce() functions for STL container types.
CByteImage * createByteImage(const ImageFormatInfo &imageFormat, const ImageType imageType)
Creates a ByteImage for the destination type specified in the given imageProviderInfo.