libvisiontransfer  6.4.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 = ImageFormat::FORMAT_8_BIT_MONO,
55  FORMAT_12_BIT = ImageFormat::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 
168  void setImageDisparityPair(bool dispPair) {
169  disparityPair = dispPair;
170  }
171 
175  int getWidth() const {return width;}
176 
180  int getHeight() const {return height;}
181 
188  int getRowStride(int imageNumber) const {
189  assert(imageNumber >= 0 && imageNumber <=1);
190  return rowStride[imageNumber];
191  }
192 
199  ImageFormat getPixelFormat(int imageNumber) const {
200  assert(imageNumber >= 0 && imageNumber <=1);
201  return formats[imageNumber];
202  }
203 
210  unsigned char* getPixelData(int imageNumber) const {
211  assert(imageNumber >= 0 && imageNumber <=1);
212  return data[imageNumber];
213  }
214 
218  const float* getQMatrix() const {
219  return qMatrix;
220  }
221 
225  unsigned int getSequenceNumber() const {return seqNum;}
226 
234  void getTimestamp(int& seconds, int& microsec) const {
235  seconds = timeSec;
236  microsec = timeMicrosec;
237  }
238 
247  void getDisparityRange(int& minimum, int& maximum) const {
248  minimum = minDisparity;
249  maximum = maxDisparity;
250  }
251 
258  void writePgmFile(int imageNumber, const char* fileName) const;
259 
264  bool isImageDisparityPair() const {
265  return disparityPair;
266  }
267 
271  void copyTo(ImagePair& dest);
272 
279  int getBytesPerPixel(int imageNumber) const {
280  assert(imageNumber >= 0 && imageNumber <=1);
281  return getBytesPerPixel(formats[imageNumber]);
282  }
283 
288  static int getBytesPerPixel(ImageFormat format);
289 
290 #ifdef CV_MAJOR_VERSION
291 
304  inline void toOpenCVImage(int imageNumber, cv::Mat& dest, bool convertRgbToBgr = true);
305 #endif
306 
307 private:
308  // No pimpl idiom here as almost everything is inlined.
309 
310  int width;
311  int height;
312  int rowStride[2];
313  ImageFormat formats[2];
314  unsigned char* data[2];
315  const float* qMatrix;
316  int timeSec;
317  int timeMicrosec;
318  unsigned int seqNum;
319  int minDisparity;
320  int maxDisparity;
321  bool disparityPair;
322  int* referenceCounter;
323 
324  void copyData(ImagePair& dest, const ImagePair& src, bool countRef);
325  void decrementReference();
326 };
327 
328 } // namespace
329 
330 #include "visiontransfer/imagepair-opencv.h"
331 #endif
332 
int getHeight() const
Returns the height of each image.
Definition: imagepair.h:180
void setImageDisparityPair(bool dispPair)
Sets whether this is a left camera image and disparity map pair, or two raw camera images...
Definition: imagepair.h:168
void setPixelFormat(int imageNumber, ImageFormat format)
Sets the pixel format for the given image.
Definition: imagepair.h:100
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:225
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:247
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:199
int getRowStride(int imageNumber) const
Returns the row stride for the pixel data of one image.
Definition: imagepair.h:188
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:218
int getWidth() const
Returns the width of each image.
Definition: imagepair.h:175
bool isImageDisparityPair() const
Returns true if this is a left camera image and disparity map pair.
Definition: imagepair.h:264
void getTimestamp(int &seconds, int &microsec) const
Returns the time at which this image pair has been captured.
Definition: imagepair.h:234
unsigned char * getPixelData(int imageNumber) const
Returns the pixel data for the given image.
Definition: imagepair.h:210
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:279
Nerian Vision Technologies