libvisiontransfer  10.8.0
imageset.h
1 /*******************************************************************************
2  * Copyright (c) 2024 Allied Vision Technologies GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #ifndef VISIONTRANSFER_IMAGESET_H
16 #define VISIONTRANSFER_IMAGESET_H
17 
18 #include <cassert>
19 #include <cstddef>
20 #include "visiontransfer/common.h"
21 
22 namespace visiontransfer {
23 
38 class VT_EXPORT ImageSet {
39 
40 private:
41  // We follow the pimpl idiom
42  class Pimpl;
43  Pimpl* pimpl;
44 
45 public:
46  static const int MAX_SUPPORTED_IMAGES = 4;
50  enum ImageFormat {
52  FORMAT_8_BIT_MONO,
53 
55  FORMAT_8_BIT_RGB,
56 
59  FORMAT_12_BIT_MONO
60  };
61 
65  enum ImageFormat_Deprecated {
66  FORMAT_8_BIT = FORMAT_8_BIT_MONO,
67  FORMAT_12_BIT = FORMAT_12_BIT_MONO
68  };
69 
73  enum ImageType {
74  IMAGE_UNDEFINED,
75  IMAGE_LEFT,
76  IMAGE_DISPARITY,
77  IMAGE_RIGHT,
78 
80  IMAGE_COLOR
81  };
82 
86  ImageSet();
87 
91  ImageSet(const ImageSet& other);
92 
93  ~ImageSet();
94  ImageSet& operator= (ImageSet const& other);
95 
99  void setWidth(int w);
100 
104  void setHeight(int h);
105 
113  void setRowStride(int imageNumber, int stride);
114 
122  void setPixelFormat(int imageNumber, ImageFormat format);
123 
124 #ifndef DOXYGEN_SHOULD_SKIP_THIS
125  DEPRECATED("Use setPixelFormat(int, ImageFormat) instead") void setPixelFormat(int imageNumber, ImageFormat_Deprecated format) {
126  setPixelFormat(imageNumber, static_cast<ImageFormat>(format));
127  }
128 #endif
129 
137  void setPixelData(int imageNumber, unsigned char* pixelData);
138 
145  void setQMatrix(const float* q);
146 
150  void setSequenceNumber(unsigned int num);
151 
159  void setTimestamp(int seconds, int microsec);
160 
168  void setDisparityRange(int minimum, int maximum);
169 
173  void setSubpixelFactor(int subpixFact);
174 
175 #ifndef DOXYGEN_SHOULD_SKIP_THIS
176 
183  DEPRECATED("Only compatible with two-image sets: use setNumberOfImages() and setIndexOf() instead")
184  void setImageDisparityPair(bool dispPair);
185 #endif
186 
190  int getWidth() const;
191 
195  int getHeight() const;
196 
206  int getRowStride(int imageNumber) const;
207 
216  int getRowStride(ImageType what) const;
217 
227  ImageFormat getPixelFormat(int imageNumber) const;
228 
237  ImageFormat getPixelFormat(ImageType what) const;
238 
248  unsigned char* getPixelData(int imageNumber) const;
249 
258  unsigned char* getPixelData(ImageType what) const;
259 
263  const float* getQMatrix() const;
264 
268  unsigned int getSequenceNumber() const;
269 
277  void getTimestamp(int& seconds, int& microsec) const;
278 
287  void getDisparityRange(int& minimum, int& maximum) const;
288 
292  int getSubpixelFactor() const;
293 
300  void writePgmFile(int imageNumber, const char* fileName) const;
301 
302 #ifndef DOXYGEN_SHOULD_SKIP_THIS
303 
315  DEPRECATED("Only compatible with two-image sets: use hasImageType(ImageSet::IMAGE_DISPARITY) instead")
316  bool isImageDisparityPair() const {
317  return (getNumberOfImages()==2) && hasImageType(IMAGE_DISPARITY);
318  }
319 #endif
320 
324  void copyTo(ImageSet& dest);
325 
332  int getBytesPerPixel(int imageNumber) const;
333 
340  int getBitsPerPixel(int imageNumber) const;
341 
342  int getBitsPerPixel(ImageType what) const;
343 
344  static int getBitsPerPixel(ImageFormat format);
345 
350  static int getBytesPerPixel(ImageFormat format);
351 
355  int getNumberOfImages() const;
356 
360  void setNumberOfImages(int number);
361 
365  ImageType getImageType(int imageNumber) const;
366 
375  int getIndexOf(ImageType what, bool throwIfNotFound=false) const;
376 
380  bool hasImageType(ImageType what) const;
381 
389  void setIndexOf(ImageType what, int idx);
390 
391 
392 #ifdef CV_MAJOR_VERSION
393 
407  inline void toOpenCVImage(int imageNumber, cv::Mat& dest, bool convertRgbToBgr = true);
408 #endif
409 
415  void setExposureTime(int timeMicrosec);
416 
423  int getExposureTime() const;
424 
432  void setLastSyncPulse(int seconds, int microsec);
433 
441  void getLastSyncPulse(int& seconds, int& microsec) const;
442 
443 };
444 
445 #ifndef DOXYGEN_SHOULD_SKIP_THIS
446 // For source compatibility
447 class DEPRECATED("Use ImageSet instead.") ImagePair: public ImageSet {
448 };
449 #endif
450 
451 } // namespace
452 
453 #include "visiontransfer/imageset-opencv.h"
454 #endif
visiontransfer::ImageSet::ImageFormat_Deprecated
ImageFormat_Deprecated
Definition: imageset.h:89
visiontransfer::ImageSet
A set of one to three images, but usually two (the left camera image and the disparity map)....
Definition: imageset.h:50
visiontransfer::ImageSet::ImageFormat
ImageFormat
Image formats that can be transferred.
Definition: imageset.h:74
Allied Vision