HsvImageSegmentation.h
Go to the documentation of this file.
1 #ifndef HSVIMAGESEGMENTATION_H
2 #define HSVIMAGESEGMENTATION_H
3 
4 
5 // ivt
7 
8 #include <Image/ImageProcessor.h>
9 
10 namespace armarx
11 {
12 
13  /**
14  * @brief The HsvImageSegmentation class
15  *
16  * Allows for HSV color segmentation of images (e.g. in an image processor).
17  *
18  * Pointer ownership: All memory for images is allocated and freed by this class.
19  * You may not and need not to allocate or delete memory for images.
20  *
21  * All color images are of CByteImage::eRGB24 type.
22  * All grey images are of CByteImage::eGrayScale type.
23  */
25  {
26  public:
27  /**
28  * @brief No-initialization constructor.
29  * Does not allocate any space. Overwrite an initialized object
30  * by overwriting it with a non-initalized object.
31  */
33 
34  /**
35  * @brief Construct from the given image parameters.
36  * Allocates space for the given number of images of given width and height.
37  *
38  * @param numImages number of images
39  * @param width image width
40  * @param height image height
41  *
42  * @throws std::invalid_argument if numImages <= 0
43  */
44  HsvImageSegmentation(int numImages, int width, int height, CByteImage::ImageType colorType);
45  /**
46  * @brief Shortcut constructor for usage from an image processor.
47  * @param imageProviderInfo the image provider info
48  *
49  * @throws std::invalid_argument if imageProviderInfo.numberImages <= 0
50  */
51  HsvImageSegmentation(const visionx::ImageProviderInfo& imageProviderInfo);
52 
53  /**
54  * Frees all allocated memory.
55  */
57 
58 
59  /// move constructor
61 
63 
64 
65  /**
66  * @brief Get the input images (RGB) (buffer).
67  * Write into this buffer to set new input images.
68  * @return input images RGB (buffer)
69  */
70  CByteImage** getInputImagesRgb() const;
71  /**
72  * @brief Get the input images in HSV.
73  * Only valid after calling processInputImages().
74  * @return the input images in HSV
75  */
76  CByteImage** getInputImagesHsv() const;
77  /**
78  * @brief Get input visualization images.
79  * Only valid after calling processInputImages().
80  * These are the same as input images, but may be modified
81  * for visualization without affecting the input images.
82  * @return modifiable input images for visualization
83  */
84  CByteImage** getInputVisuImages() const;
85  /**
86  * @brief Get the output images in gray scale.
87  * Only valid after calling processInputImages().
88  * @return the output images (Gray)
89  */
90  CByteImage** getOutputImagesGray() const;
91  /**
92  * @brief Get the output images in RGB (from gray scale).
93  * Only valid after calling processInputImages().
94  * @return the output images RGB
95  */
96  CByteImage** getOutputImagesRgb() const;
97 
98  /**
99  * @return the number of images
100  */
101  int getNumImages() const;
102 
103  /**
104  * @brief Processes the current input images.
105  * Copies input RGB images to input visu images.
106  * Converts input RGB images to input HSV images.
107  * Performs segmentation on HSV image.
108  * Converts output grey image to output RGB image.
109  */
110  void
111  processInputImages(int hue, int hueTol, int satMin, int satMax, int valMin, int valMax);
112 
113 
114  private:
115  /// Allocates image buffers from the given image provider info.
116  void allocate(const visionx::ImageProviderInfo& imageProviderInfo);
117  /// If allocated, frees the image buffers.
118  void deallocate();
119  /// Steals state and image buffers from other and resets other.
120  void moveFrom(HsvImageSegmentation& other);
121 
122 
123  /// Number of images.
124  int numImages = 0;
125  /// Width of each image.
126  int width = 0;
127  /// Height of each image.
128  int height = 0;
129 
130  /// Input images (RGB24)
131  CByteImage** inputImagesRgb = nullptr;
132  /// Input images with stuff drawn on them (RGB24)
133  CByteImage** inputVisuImages = nullptr;
134 
135  /// Input images in HSV space (RGB24, but HSV values)
136  CByteImage** inputImagesHsv = nullptr;
137 
138  /// Output images (GrayScale)
139  CByteImage** outputImagesGray = nullptr;
140  /// Output images for visualization (RGB24)
141  CByteImage** outputImagesRgb = nullptr;
142  };
143 
144 } // namespace armarx
145 
146 #endif // HSVIMAGESEGMENTATION_H
armarx::HsvImageSegmentation::processInputImages
void processInputImages(int hue, int hueTol, int satMin, int satMax, int valMin, int valMax)
Processes the current input images.
Definition: HsvImageSegmentation.cpp:86
armarx::HsvImageSegmentation::getInputImagesHsv
CByteImage ** getInputImagesHsv() const
Get the input images in HSV.
Definition: HsvImageSegmentation.cpp:56
armarx::HsvImageSegmentation::HsvImageSegmentation
HsvImageSegmentation()
No-initialization constructor.
Definition: HsvImageSegmentation.cpp:8
armarx::HsvImageSegmentation
The HsvImageSegmentation class.
Definition: HsvImageSegmentation.h:24
visionx::ImageProviderInfo
Definition: ImageProcessor.h:479
ImageProcessor.h
armarx::HsvImageSegmentation::getNumImages
int getNumImages() const
Definition: HsvImageSegmentation.cpp:80
armarx::HsvImageSegmentation::getOutputImagesRgb
CByteImage ** getOutputImagesRgb() const
Get the output images in RGB (from gray scale).
Definition: HsvImageSegmentation.cpp:74
armarx::HsvImageSegmentation::getInputVisuImages
CByteImage ** getInputVisuImages() const
Get input visualization images.
Definition: HsvImageSegmentation.cpp:62
armarx::HsvImageSegmentation::getInputImagesRgb
CByteImage ** getInputImagesRgb() const
Get the input images (RGB) (buffer).
Definition: HsvImageSegmentation.cpp:50
armarx::HsvImageSegmentation::operator=
HsvImageSegmentation & operator=(HsvImageSegmentation &&other)
Definition: HsvImageSegmentation.cpp:39
armarx::HsvImageSegmentation::~HsvImageSegmentation
~HsvImageSegmentation()
Frees all allocated memory.
Definition: HsvImageSegmentation.cpp:28
armarx::HsvImageSegmentation::getOutputImagesGray
CByteImage ** getOutputImagesGray() const
Get the output images in gray scale.
Definition: HsvImageSegmentation.cpp:68
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27