MIRA
|
This document acts as a manual. For requirements of the module see Image (Implementation Requirements).
The image classes provide structures for typed and untyped images. The classes wrap an OpenCV cv::Mat structure and provide additional functions for convenience. When the type of the image is known at compile time, the typed image classes Img<Type,Channel> should be preferred, because it provides type-safety. If the type is unknown at compile time, you can use the untyped image class.
The implemented concept basically consists of two different classes that realize the desired functionality.
There is also a small hierarchy of base classes that provide shared functionality for the aforementioned classes and therefore prevent code duplication. Normally, you should not explicitly create any instance of the base classes.
Example image/ImgTutorial.C shows the basic functionality of the Img class:
Gray images We start off by creating an empty unsigned 8-bit integer, single channel image:
You can easily access the image directly and set pixels by:
Getting access to a whole scanline is also easy:
Now we can show our image using OpenCV:
Color images Creating color images is quite similar to gray images:
The Pixel class provides access to the image pixels. If we want to set Pixel(10,20) to blue, we just write:
You can also use the Color class for different color spaces. The next example shows how to set some pixels directly or by using the scanline interface.
Untyped images can be used when the image type and/or channels are not known at compile time. Therefore you can write:
The image classes provide efficient assignment and copy constructors by using only shallow copies. If you want a deep copy, use method clone().
Conversion into different types is done via function convertFrom()
Any Img class can be casted into cv::Mat matrices without performance penalty or creating temporary copies:
Therefore, we can use OpenCV functions to directly manipulate images. The following example draws some figures into our color image from
:
Since the image class provides STL-conforming iterators, you can easily iterate through an image:
You can also iterate through just a ROI (region of interest) of the image:
Example image/ColorPaletteExample.C shows how to use different color palettes. This code example should give you a brief look how to create and use discrete and continuous color palettes.
Question: How do I store meta info (e.g. image origin, or camera parameters) of an image? Answer: You should write them to an extra channel before you write the actual image data. Then, a subscriber can read the additional info data before reading the image.
Question: ...
Answer: ...