libvisiontransfer  6.5.0
imagepair.h
1 /*******************************************************************************
2  * Copyright (c) 2019 Nerian Vision 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_IMAGEPAIR_H
16 #define VISIONTRANSFER_IMAGEPAIR_H
17 
18 #include <cassert>
19 #include <cstddef>
20 #include "visiontransfer/common.h"
21 
22 namespace visiontransfer {
23 
33 class VT_EXPORT ImagePair {
34 public:
38  enum ImageFormat {
41 
44 
47  FORMAT_12_BIT_MONO
48  };
49 
54  FORMAT_8_BIT = FORMAT_8_BIT_MONO,
55  FORMAT_12_BIT = FORMAT_12_BIT_MONO
56  };
57 
61  ImagePair();
62 
66  ImagePair(const ImagePair& other);
67 
68  ~ImagePair();
69  ImagePair& operator= (ImagePair const& other);
70 
74  void setWidth(int w) {width = w;}
75 
79  void setHeight(int h) {height = h;}
80 
88  void setRowStride(int imageNumber, int stride) {
89  assert(imageNumber >= 0 && imageNumber <=1);
90  rowStride[imageNumber] = stride;
91  }
92 
100  void setPixelFormat(int imageNumber, ImageFormat format) {
101  assert(imageNumber >= 0 && imageNumber <=1);
102  formats[imageNumber] = format;
103  }
104 
105 #ifndef DOXYGEN_SHOULD_SKIP_THIS
106  DEPRECATED(void setPixelFormat(int imageNumber, ImageFormat_Deprecated format)) {
107  setPixelFormat(imageNumber, static_cast<ImageFormat>(format));
108  }
109 #endif
110 
118  void setPixelData(int imageNumber, unsigned char* pixelData) {
119  assert(imageNumber >= 0 && imageNumber <=1);
120  data[imageNumber] = pixelData;
121  }
122 
129  void setQMatrix(const float* q) {
130  qMatrix = q;
131  }
132 
136  void setSequenceNumber(unsigned int num) {
137  seqNum = num;
138  }
139 
147  void setTimestamp(int seconds, int microsec) {
148  timeSec = seconds;
149  timeMicrosec = microsec;
150  }
151 
159  void setDisparityRange(int minimum, int maximum) {
160  minDisparity = minimum;
161  maxDisparity = maximum;
162  }
163 
167  void setSubpixelFactor(int subpixFact) {
168  subpixelFactor = subpixFact;
169  }
170 
175  void setImageDisparityPair(bool dispPair) {
176  disparityPair = dispPair;
177  }
178 
182  int getWidth() const {return width;}
183 
187  int getHeight() const {return height;}
188 
195  int getRowStride(int imageNumber) const {
196  assert(imageNumber >= 0 && imageNumber <=1);
197  return rowStride[imageNumber];
198  }
199 
206  ImageFormat getPixelFormat(int imageNumber) const {
207  assert(imageNumber >= 0 && imageNumber <=1);
208  return formats[imageNumber];
209  }
210 
217  unsigned char* getPixelData(int imageNumber) const {
218  assert(imageNumber >= 0 && imageNumber <=1);
219  return data[imageNumber];
220  }
221 
225  const float* getQMatrix() const {
226  return qMatrix;
227  }
228 
232  unsigned int getSequenceNumber() const {return seqNum;}
233 
241  void getTimestamp(int& seconds, int& microsec) const {
242  seconds = timeSec;
243  microsec = timeMicrosec;
244  }
245 
254  void getDisparityRange(int& minimum, int& maximum) const {
255  minimum = minDisparity;
256  maximum = maxDisparity;
257  }
258 
262  int getSubpixelFactor() const {
263  return subpixelFactor;
264  }
265 
272  void writePgmFile(int imageNumber, const char* fileName) const;
273 
278  bool isImageDisparityPair() const {
279  return disparityPair;
280  }
281 
285  void copyTo(ImagePair& dest);
286 
293  int getBytesPerPixel(int imageNumber) const {
294  assert(imageNumber >= 0 && imageNumber <=1);
295  return getBytesPerPixel(formats[imageNumber]);
296  }
297 
302  static int getBytesPerPixel(ImageFormat format);
303 
304 #ifdef CV_MAJOR_VERSION
305 
318  inline void toOpenCVImage(int imageNumber, cv::Mat& dest, bool convertRgbToBgr = true);
319 #endif
320 
321 private:
322  // No pimpl idiom here as almost everything is inlined.
323 
324  int width;
325  int height;
326  int rowStride[2];
327  ImageFormat formats[2];
328  unsigned char* data[2];
329  const float* qMatrix;
330  int timeSec;
331  int timeMicrosec;
332  unsigned int seqNum;
333  int minDisparity;
334  int maxDisparity;
335  int subpixelFactor;
336  bool disparityPair;
337  int* referenceCounter;
338 
339  void copyData(ImagePair& dest, const ImagePair& src, bool countRef);
340  void decrementReference();
341 };
342 
343 } // namespace
344 
345 #include "visiontransfer/imagepair-opencv.h"
346 #endif
347 
int getHeight() const
Returns the height of each image.
Definition: imagepair.h:187
void setImageDisparityPair(bool dispPair)
Sets whether this is a left camera image and disparity map pair, or two raw camera images...
Definition: imagepair.h:175
void setPixelFormat(int imageNumber, ImageFormat format)
Sets the pixel format for the given image.
Definition: imagepair.h:100
void setSubpixelFactor(int subpixFact)
Sets the subpixel factor for this image pair.
Definition: imagepair.h:167
void setPixelData(int imageNumber, unsigned char *pixelData)
Sets the pixel data for the given image.
Definition: imagepair.h:118
void setRowStride(int imageNumber, int stride)
Sets a new row stride for the pixel data of one image.
Definition: imagepair.h:88
unsigned int getSequenceNumber() const
Returns the sequence number for this image pair.
Definition: imagepair.h:232
void setQMatrix(const float *q)
Sets the pointer to the disparity-to-depth mapping matrix q.
Definition: imagepair.h:129
void getDisparityRange(int &minimum, int &maximum) const
Gets the value range for the disparity map contained in this image pair. If the image pair does not c...
Definition: imagepair.h:254
void setDisparityRange(int minimum, int maximum)
Sets the value range for the disparity map contained in this image pair.
Definition: imagepair.h:159
ImageFormat getPixelFormat(int imageNumber) const
Returns the pixel format for the given image.
Definition: imagepair.h:206
int getRowStride(int imageNumber) const
Returns the row stride for the pixel data of one image.
Definition: imagepair.h:195
ImageFormat
Image formats that can be transferred.
Definition: imagepair.h:38
void setWidth(int w)
Sets a new width for both images.
Definition: imagepair.h:74
void setSequenceNumber(unsigned int num)
Sets the sequence number for this image pair.
Definition: imagepair.h:136
void setTimestamp(int seconds, int microsec)
Sets the time at which this image pair has been captured.
Definition: imagepair.h:147
const float * getQMatrix() const
Returns a pointer to the disparity-to-depth mapping matrix q.
Definition: imagepair.h:225
int getWidth() const
Returns the width of each image.
Definition: imagepair.h:182
int getSubpixelFactor() const
Gets the subpixel factor for this image pair.
Definition: imagepair.h:262
bool isImageDisparityPair() const
Returns true if this is a left camera image and disparity map pair.
Definition: imagepair.h:278
void getTimestamp(int &seconds, int &microsec) const
Returns the time at which this image pair has been captured.
Definition: imagepair.h:241
unsigned char * getPixelData(int imageNumber) const
Returns the pixel data for the given image.
Definition: imagepair.h:217
void setHeight(int h)
Sets a new width for both images.
Definition: imagepair.h:79
A set of two images, which are usually the left camera image and the disparity map.
Definition: imagepair.h:33
int getBytesPerPixel(int imageNumber) const
Returns the number of bytes that are required to store one image pixel.
Definition: imagepair.h:293
Nerian Vision Technologies