[2] | 1 | // %flair:license{
|
---|
[13] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 4 | // %flair:license}
|
---|
| 5 | /*!
|
---|
| 6 | * \file cvimage.h
|
---|
| 7 | * \brief Class defining an image of kind IplImage
|
---|
| 8 | * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 9 | * \date 2012/03/20
|
---|
| 10 | * \version 4.0
|
---|
| 11 | */
|
---|
| 12 |
|
---|
| 13 | #ifndef CVIMAGE_H
|
---|
| 14 | #define CVIMAGE_H
|
---|
| 15 |
|
---|
| 16 | #include <cxcore.h>
|
---|
| 17 | #include <io_data.h>
|
---|
| 18 | #include <stdint.h>
|
---|
| 19 |
|
---|
[13] | 20 | namespace flair {
|
---|
| 21 | namespace core {
|
---|
| 22 | /*! \class cvimage
|
---|
| 23 | *
|
---|
| 24 | * \brief Class defining an image of kind IplImage
|
---|
| 25 | *
|
---|
| 26 | * IplImage is an image struct defined in OpenCV.
|
---|
| 27 | *
|
---|
| 28 | */
|
---|
| 29 | class cvimage : public io_data {
|
---|
| 30 | public:
|
---|
| 31 | class Type : public DataType {
|
---|
| 32 | public:
|
---|
| 33 | /*!
|
---|
| 34 | \enum Format_t
|
---|
| 35 | \brief Picture formats
|
---|
[2] | 36 | */
|
---|
[13] | 37 | enum class Format {
|
---|
| 38 | YUYV, /*!< YUYV 16 bits */
|
---|
| 39 | UYVY, /*!< UYVY 16 bits */
|
---|
| 40 | BGR, /*!< BGR 24 bits */
|
---|
[47] | 41 | Gray, /*!< gray 8 bits */
|
---|
[13] | 42 | };
|
---|
| 43 | Type(uint16_t _width, uint16_t _height, Format _format)
|
---|
| 44 | : width(_width), height(_height), format(_format) {}
|
---|
[2] | 45 |
|
---|
[13] | 46 | size_t GetSize() const {
|
---|
| 47 | size_t pixelSize;
|
---|
| 48 | switch (format) {
|
---|
[47] | 49 | case Format::Gray:
|
---|
[13] | 50 | pixelSize = 1;
|
---|
| 51 | break;
|
---|
| 52 | case Format::YUYV:
|
---|
| 53 | case Format::UYVY:
|
---|
| 54 | pixelSize = 2;
|
---|
| 55 | break;
|
---|
| 56 | case Format::BGR:
|
---|
| 57 | pixelSize = 3;
|
---|
| 58 | break;
|
---|
| 59 | default:
|
---|
| 60 | pixelSize = 0; // TODO should throw an exception instead
|
---|
| 61 | }
|
---|
| 62 | return pixelSize * width * height;
|
---|
| 63 | }
|
---|
| 64 | std::string GetDescription() const { return "cv image"; };
|
---|
[2] | 65 |
|
---|
[13] | 66 | Format GetFormat() const { return format; };
|
---|
| 67 | uint16_t GetWidth() const { return width; };
|
---|
| 68 | uint16_t GetHeight() const { return height; };
|
---|
[2] | 69 |
|
---|
[13] | 70 | private:
|
---|
| 71 | uint16_t width;
|
---|
| 72 | uint16_t height;
|
---|
| 73 | Format format;
|
---|
| 74 | };
|
---|
[2] | 75 |
|
---|
[13] | 76 | /*!
|
---|
| 77 | * \brief Constructor
|
---|
| 78 | *
|
---|
| 79 | * Construct an io_data representing an IplImage.
|
---|
| 80 | *
|
---|
| 81 | * \param parent parent
|
---|
| 82 | * \param width image width
|
---|
| 83 | * \param height image height
|
---|
| 84 | * \param name name
|
---|
| 85 | * \param allocate_data if true, IplImage image data is allocated; otherwise
|
---|
| 86 | *img->imagedata must be changed
|
---|
| 87 | * \param n number of samples
|
---|
| 88 | */
|
---|
| 89 | cvimage(const Object *parent, uint16_t width, uint16_t height,
|
---|
| 90 | Type::Format format, std::string name = "", bool allocate_data = true,
|
---|
| 91 | int n = 1);
|
---|
[2] | 92 |
|
---|
[13] | 93 | /*!
|
---|
| 94 | * \brief Destructor
|
---|
| 95 | *
|
---|
| 96 | */
|
---|
| 97 | ~cvimage();
|
---|
[2] | 98 |
|
---|
[13] | 99 | /*!
|
---|
| 100 | * \brief IplImage
|
---|
| 101 | *
|
---|
| 102 | * \return IplImage
|
---|
| 103 | */
|
---|
| 104 | IplImage *img;
|
---|
[2] | 105 |
|
---|
[13] | 106 | Type const &GetDataType() const { return dataType; };
|
---|
[2] | 107 |
|
---|
[13] | 108 | private:
|
---|
| 109 | /*!
|
---|
| 110 | * \brief Copy datas
|
---|
| 111 | *
|
---|
| 112 | * Reimplemented from io_data. \n
|
---|
| 113 | * See io_data::CopyDatas.
|
---|
| 114 | *
|
---|
| 115 | * \param dst destination buffer
|
---|
| 116 | */
|
---|
| 117 | void CopyDatas(char *dst) const;
|
---|
[2] | 118 |
|
---|
[13] | 119 | bool allocate_data;
|
---|
| 120 | Type dataType;
|
---|
| 121 | };
|
---|
[2] | 122 |
|
---|
| 123 | } // end namespace core
|
---|
| 124 | } // end namespace flair
|
---|
| 125 |
|
---|
| 126 | #endif // CVIMAGE_H
|
---|