libvisiontransfer  10.6.0
imageset.h
1 /*******************************************************************************
2  * Copyright (c) 2023 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 public:
40  static const int MAX_SUPPORTED_IMAGES = 4;
44  enum ImageFormat {
46  FORMAT_8_BIT_MONO,
47 
49  FORMAT_8_BIT_RGB,
50 
53  FORMAT_12_BIT_MONO
54  };
55 
59  enum ImageFormat_Deprecated {
60  FORMAT_8_BIT = FORMAT_8_BIT_MONO,
61  FORMAT_12_BIT = FORMAT_12_BIT_MONO
62  };
63 
67  enum ImageType {
68  IMAGE_UNDEFINED,
69  IMAGE_LEFT,
70  IMAGE_DISPARITY,
71  IMAGE_RIGHT,
72 
74  IMAGE_COLOR
75  };
76 
80  ImageSet();
81 
85  ImageSet(const ImageSet& other);
86 
87  ~ImageSet();
88  ImageSet& operator= (ImageSet const& other);
89 
93  void setWidth(int w) {width = w;}
94 
98  void setHeight(int h) {height = h;}
99 
107  void setRowStride(int imageNumber, int stride) {
108  assert(imageNumber >= 0 && imageNumber < getNumberOfImages());
109  rowStride[imageNumber] = stride;
110  }
111 
119  void setPixelFormat(int imageNumber, ImageFormat format) {
120  assert(imageNumber >= 0 && imageNumber < getNumberOfImages());
121  formats[imageNumber] = format;
122  }
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  assert(imageNumber >= 0 && imageNumber < getNumberOfImages());
139  data[imageNumber] = pixelData;
140  }
141 
148  void setQMatrix(const float* q) {
149  qMatrix = q;
150  }
151 
155  void setSequenceNumber(unsigned int num) {
156  seqNum = num;
157  }
158 
166  void setTimestamp(int seconds, int microsec) {
167  timeSec = seconds;
168  timeMicrosec = microsec;
169  }
170 
178  void setDisparityRange(int minimum, int maximum) {
179  minDisparity = minimum;
180  maxDisparity = maximum;
181  }
182 
186  void setSubpixelFactor(int subpixFact) {
187  subpixelFactor = subpixFact;
188  }
189 
190 #ifndef DOXYGEN_SHOULD_SKIP_THIS
191 
198  DEPRECATED("Only compatible with two-image sets: use setNumberOfImages() and setIndexOf() instead")
199  void setImageDisparityPair(bool dispPair);
200 #endif
201 
205  int getWidth() const {return width;}
206 
210  int getHeight() const {return height;}
211 
221  int getRowStride(int imageNumber) const {
222  assert(imageNumber >= 0 && imageNumber < getNumberOfImages());
223  return rowStride[imageNumber];
224  }
225 
234  int getRowStride(ImageType what) const {
235  int idx = getIndexOf(what, true);
236  return getRowStride(idx);
237  }
238 
248  ImageFormat getPixelFormat(int imageNumber) const {
249  assert(imageNumber >= 0 && imageNumber < getNumberOfImages());
250  return formats[imageNumber];
251  }
252 
261  ImageFormat getPixelFormat(ImageType what) const {
262  int idx = getIndexOf(what, true);
263  return getPixelFormat(idx);
264  }
265 
275  unsigned char* getPixelData(int imageNumber) const {
276  assert(imageNumber >= 0 && imageNumber < getNumberOfImages());
277  return data[imageNumber];
278  }
279 
288  unsigned char* getPixelData(ImageType what) const {
289  int idx = getIndexOf(what, true);
290  return getPixelData(idx);
291  }
292 
296  const float* getQMatrix() const {
297  return qMatrix;
298  }
299 
303  unsigned int getSequenceNumber() const {return seqNum;}
304 
312  void getTimestamp(int& seconds, int& microsec) const {
313  seconds = timeSec;
314  microsec = timeMicrosec;
315  }
316 
325  void getDisparityRange(int& minimum, int& maximum) const {
326  minimum = minDisparity;
327  maximum = maxDisparity;
328  }
329 
333  int getSubpixelFactor() const {
334  return subpixelFactor;
335  }
336 
343  void writePgmFile(int imageNumber, const char* fileName) const;
344 
345 #ifndef DOXYGEN_SHOULD_SKIP_THIS
346 
358  DEPRECATED("Only compatible with two-image sets: use hasImageType(ImageSet::IMAGE_DISPARITY) instead")
359  bool isImageDisparityPair() const {
360  return (getNumberOfImages()==2) && hasImageType(IMAGE_DISPARITY);
361  }
362 #endif
363 
367  void copyTo(ImageSet& dest);
368 
375  int getBytesPerPixel(int imageNumber) const {
376  assert(imageNumber >= 0 && imageNumber < getNumberOfImages());
377  return getBytesPerPixel(formats[imageNumber]);
378  }
379 
386  int getBitsPerPixel(int imageNumber) const {
387  assert(imageNumber >= 0 && imageNumber < getNumberOfImages());
388  return getBitsPerPixel(formats[imageNumber]);
389  }
390 
391  int getBitsPerPixel(ImageType what) const {
392  int idx = getIndexOf(what, true);
393  return getBitsPerPixel(idx);
394  }
395 
396  static int getBitsPerPixel(ImageFormat format);
397 
402  static int getBytesPerPixel(ImageFormat format);
403 
407  int getNumberOfImages() const {
408  return numberOfImages;
409  }
410 
414  void setNumberOfImages(int number) {
415  assert(number >= 1 && number <= MAX_SUPPORTED_IMAGES);
416  numberOfImages = number;
417  }
418 
422  ImageType getImageType(int imageNumber) const;
423 
432  int getIndexOf(ImageType what, bool throwIfNotFound=false) const;
433 
437  bool hasImageType(ImageType what) const {
438  return getIndexOf(what) >= 0;
439  }
440 
441 
449  void setIndexOf(ImageType what, int idx);
450 
451 
452 #ifdef CV_MAJOR_VERSION
453 
467  inline void toOpenCVImage(int imageNumber, cv::Mat& dest, bool convertRgbToBgr = true);
468 #endif
469 
475  void setExposureTime(int timeMicrosec) {
476  exposureTime = timeMicrosec;
477  }
478 
485  int getExposureTime() const {
486  return exposureTime;
487  }
488 
496  void setLastSyncPulse(int seconds, int microsec) {
497  lastSyncPulseSec = seconds;
498  lastSyncPulseMicrosec = microsec;
499  }
500 
508  void getLastSyncPulse(int& seconds, int& microsec) const {
509  seconds = lastSyncPulseSec;
510  microsec = lastSyncPulseMicrosec;
511  }
512 
513 private:
514  // No pimpl idiom here as almost everything is inlined.
515  int width;
516  int height;
517  int rowStride[MAX_SUPPORTED_IMAGES];
518  ImageFormat formats[MAX_SUPPORTED_IMAGES];
519  unsigned char* data[MAX_SUPPORTED_IMAGES];
520  const float* qMatrix;
521  int timeSec;
522  int timeMicrosec;
523  unsigned int seqNum;
524  int minDisparity;
525  int maxDisparity;
526  int subpixelFactor;
527  int* referenceCounter;
528  int numberOfImages;
529 
530  int indexLeftImage;
531  int indexRightImage;
532  int indexDisparityImage;
533  int indexColorImage;
534 
535  int exposureTime;
536  int lastSyncPulseSec;
537  int lastSyncPulseMicrosec;
538 
539  void copyData(ImageSet& dest, const ImageSet& src, bool countRef);
540  void decrementReference();
541 };
542 
543 #ifndef DOXYGEN_SHOULD_SKIP_THIS
544 // For source compatibility
545 class DEPRECATED("Use ImageSet instead.") ImagePair: public ImageSet {
546 };
547 #endif
548 
549 } // namespace
550 
551 #include "visiontransfer/imageset-opencv.h"
552 #endif
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::ImageType
ImageType
Supported image types.
Definition: imageset.h:91
Allied Vision