libvisiontransfer  6.1.1
imagepair.h
1 /*******************************************************************************
2  * Copyright (c) 2018 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 
31 class VT_EXPORT ImagePair {
32 public:
36  enum ImageFormat {
39 
42 
45  FORMAT_12_BIT_MONO
46  };
47 
52  FORMAT_8_BIT = ImageFormat::FORMAT_8_BIT_MONO,
53  FORMAT_12_BIT = ImageFormat::FORMAT_12_BIT_MONO
54  };
55 
59  ImagePair();
60 
64  ImagePair(const ImagePair& other);
65 
66  ~ImagePair();
67  ImagePair& operator= (ImagePair const& other);
68 
72  void setWidth(int w) {width = w;}
73 
77  void setHeight(int h) {height = h;}
78 
86  void setRowStride(int imageNumber, int stride) {
87  assert(imageNumber >= 0 && imageNumber <=1);
88  rowStride[imageNumber] = stride;
89  }
90 
98  void setPixelFormat(int imageNumber, ImageFormat format) {
99  assert(imageNumber >= 0 && imageNumber <=1);
100  formats[imageNumber] = format;
101  }
102 
103 #ifndef DOXYGEN_SHOULD_SKIP_THIS
104  DEPRECATED(void setPixelFormat(int imageNumber, ImageFormat_Deprecated format)) {
105  setPixelFormat(imageNumber, static_cast<ImageFormat>(format));
106  }
107 #endif
108 
116  void setPixelData(int imageNumber, unsigned char* pixelData) {
117  assert(imageNumber >= 0 && imageNumber <=1);
118  data[imageNumber] = pixelData;
119  }
120 
127  void setQMatrix(const float* q) {
128  qMatrix = q;
129  }
130 
134  void setSequenceNumber(unsigned int num) {
135  seqNum = num;
136  }
137 
145  void setTimestamp(int seconds, int microsec) {
146  timeSec = seconds;
147  timeMicrosec = microsec;
148  }
149 
157  void setDisparityRange(int minimum, int maximum) {
158  minDisparity = minimum;
159  maxDisparity = maximum;
160  }
161 
166  void setImageDisparityPair(bool dispPair) {
167  disparityPair = dispPair;
168  }
169 
173  int getWidth() const {return width;}
174 
178  int getHeight() const {return height;}
179 
186  int getRowStride(int imageNumber) const {
187  assert(imageNumber >= 0 && imageNumber <=1);
188  return rowStride[imageNumber];
189  }
190 
197  ImageFormat getPixelFormat(int imageNumber) const {
198  assert(imageNumber >= 0 && imageNumber <=1);
199  return formats[imageNumber];
200  }
201 
208  unsigned char* getPixelData(int imageNumber) const {
209  assert(imageNumber >= 0 && imageNumber <=1);
210  return data[imageNumber];
211  }
212 
216  const float* getQMatrix() const {
217  return qMatrix;
218  }
219 
223  unsigned int getSequenceNumber() const {return seqNum;}
224 
232  void getTimestamp(int& seconds, int& microsec) const {
233  seconds = timeSec;
234  microsec = timeMicrosec;
235  }
236 
245  void getDisparityRange(int& minimum, int& maximum) const {
246  minimum = minDisparity;
247  maximum = maxDisparity;
248  }
249 
256  void writePgmFile(int imageNumber, const char* fileName) const;
257 
262  bool isImageDisparityPair() const {
263  return disparityPair;
264  }
265 
269  void copyTo(ImagePair& dest);
270 
277  int getBytesPerPixel(int imageNumber) const {
278  assert(imageNumber >= 0 && imageNumber <=1);
279  return getBytesPerPixel(formats[imageNumber]);
280  }
281 
286  static int getBytesPerPixel(ImageFormat format);
287 
288 #ifdef CV_MAJOR_VERSION
289 
302  inline void toOpenCVImage(int imageNumber, cv::Mat& dest, bool convertRgbToBgr = true);
303 #endif
304 
305 private:
306  // No pimpl idiom here as almost everything is inlined.
307 
308  int width;
309  int height;
310  int rowStride[2];
311  ImageFormat formats[2];
312  unsigned char* data[2];
313  const float* qMatrix;
314  int timeSec;
315  int timeMicrosec;
316  unsigned int seqNum;
317  int minDisparity;
318  int maxDisparity;
319  bool disparityPair;
320  int* referenceCounter;
321 
322  void copyData(ImagePair& dest, const ImagePair& src, bool countRef);
323  void decrementReference();
324 };
325 
326 #include "visiontransfer/imagepair-opencv.h"
327 #endif
328 
void setTimestamp(int seconds, int microsec)
Sets the time at which this image pair has been captured.
Definition: imagepair.h:145
void setHeight(int h)
Sets a new width for both images.
Definition: imagepair.h:77
8-bit greyscale format
Definition: imagepair.h:38
void setSequenceNumber(unsigned int num)
Sets the sequence number for this image pair.
Definition: imagepair.h:134
int getHeight() const
Returns the height of each image.
Definition: imagepair.h:178
void setPixelFormat(int imageNumber, ImageFormat format)
Sets the pixel format for the given image.
Definition: imagepair.h:98
int getRowStride(int imageNumber) const
Returns the row stride for the pixel data of one image.
Definition: imagepair.h:186
ImageFormat getPixelFormat(int imageNumber) const
Returns the pixel format for the given image.
Definition: imagepair.h:197
unsigned char * getPixelData(int imageNumber) const
Returns the pixel data for the given image.
Definition: imagepair.h:208
void setDisparityRange(int minimum, int maximum)
Sets the value range for the disparity map contained in this image pair.
Definition: imagepair.h:157
void setWidth(int w)
Sets a new width for both images.
Definition: imagepair.h:72
void setQMatrix(const float *q)
Sets the pointer to the disparity-to-depth mapping matrix q.
Definition: imagepair.h:127
void setRowStride(int imageNumber, int stride)
Sets a new row stride for the pixel data of one image.
Definition: imagepair.h:86
unsigned int getSequenceNumber() const
Returns the sequence number for this image pair.
Definition: imagepair.h:223
8-bit RGB format
Definition: imagepair.h:41
void setPixelData(int imageNumber, unsigned char *pixelData)
Sets the pixel data for the given image.
Definition: imagepair.h:116
ImageFormat_Deprecated
Definition: imagepair.h:51
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:245
int getWidth() const
Returns the width of each image.
Definition: imagepair.h:173
A set of two images, which are usually the left camera image and the disparity map.
Definition: imagepair.h:31
void getTimestamp(int &seconds, int &microsec) const
Returns the time at which this image pair has been captured.
Definition: imagepair.h:232
const float * getQMatrix() const
Returns a pointer to the disparity-to-depth mapping matrix q.
Definition: imagepair.h:216
bool isImageDisparityPair() const
Returns true if this is a left camera image and disparity map pair.
Definition: imagepair.h:262
void setImageDisparityPair(bool dispPair)
Sets whether this is a left camera image and disparity map pair, or two raw camera images...
Definition: imagepair.h:166
ImageFormat
Image formats that can be transferred.
Definition: imagepair.h:36
int getBytesPerPixel(int imageNumber) const
Returns the number of bytes that are required to store one image pixel.
Definition: imagepair.h:277
Nerian Vision Technologies