libvisiontransfer  5.2.0
imagepair.h
1 /*******************************************************************************
2  * Copyright (c) 2018 Nerian Vision Technologies
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 
30 class VT_EXPORT ImagePair {
31 public:
35  enum ImageFormat {
38 
41  FORMAT_12_BIT
42  };
43 
47  ImagePair();
48 
52  ImagePair(const ImagePair& other);
53 
54  ~ImagePair();
55  ImagePair& operator= (ImagePair const& other);
56 
60  void setWidth(int w) {width = w;}
61 
65  void setHeight(int h) {height = h;}
66 
74  void setRowStride(int imageNumber, int stride) {
75  assert(imageNumber >= 0 && imageNumber <=1);
76  rowStride[imageNumber] = stride;
77  }
78 
86  void setPixelFormat(int imageNumber, ImageFormat format) {
87  assert(imageNumber >= 0 && imageNumber <=1);
88  formats[imageNumber] = format;
89  }
90 
98  void setPixelData(int imageNumber, unsigned char* pixelData) {
99  assert(imageNumber >= 0 && imageNumber <=1);
100  data[imageNumber] = pixelData;
101  }
102 
109  void setQMatrix(const float* q) {
110  qMatrix = q;
111  }
112 
116  void setSequenceNumber(unsigned int num) {
117  seqNum = num;
118  }
119 
127  void setTimestamp(int seconds, int microsec) {
128  timeSec = seconds;
129  timeMicrosec = microsec;
130  }
131 
139  void setDisparityRange(int minimum, int maximum) {
140  minDisparity = minimum;
141  maxDisparity = maximum;
142  }
143 
148  void setImageDisparityPair(bool dispPair) {
149  disparityPair = dispPair;
150  }
151 
155  int getWidth() const {return width;}
156 
160  int getHeight() const {return height;}
161 
168  int getRowStride(int imageNumber) const {
169  assert(imageNumber >= 0 && imageNumber <=1);
170  return rowStride[imageNumber];
171  }
172 
179  ImageFormat getPixelFormat(int imageNumber) const {
180  assert(imageNumber >= 0 && imageNumber <=1);
181  return formats[imageNumber];
182  }
183 
190  unsigned char* getPixelData(int imageNumber) const {
191  assert(imageNumber >= 0 && imageNumber <=1);
192  return data[imageNumber];
193  }
194 
198  const float* getQMatrix() const {
199  return qMatrix;
200  }
201 
205  unsigned int getSequenceNumber() const {return seqNum;}
206 
214  void getTimestamp(int& seconds, int& microsec) const {
215  seconds = timeSec;
216  microsec = timeMicrosec;
217  }
218 
227  void getDisparityRange(int& minimum, int& maximum) const {
228  minimum = minDisparity;
229  maximum = maxDisparity;
230  }
231 
238  void writePgmFile(int imageNumber, const char* fileName) const;
239 
244  bool isImageDisparityPair() const {
245  return disparityPair;
246  }
247 
251  void copyTo(ImagePair& dest);
252 
253 private:
254  // No pimpl idiom here as almost everything is inlined.
255 
256  int width;
257  int height;
258  int rowStride[2];
259  ImageFormat formats[2];
260  unsigned char* data[2];
261  const float* qMatrix;
262  int timeSec;
263  int timeMicrosec;
264  unsigned int seqNum;
265  int minDisparity;
266  int maxDisparity;
267  bool disparityPair;
268  int* referenceCounter;
269 
270  void copyData(ImagePair& dest, const ImagePair& src, bool countRef);
271  void decrementReference();
272 };
273 
274 #endif
275 
bool isImageDisparityPair() const
Returns true if this is a left camera image and disparity map pair.
Definition: imagepair.h:244
void setTimestamp(int seconds, int microsec)
Sets the time at which this image pair has been captured.
Definition: imagepair.h:127
void setHeight(int h)
Sets a new width for both images.
Definition: imagepair.h:65
void setSequenceNumber(unsigned int num)
Sets the sequence number for this image pair.
Definition: imagepair.h:116
void setPixelFormat(int imageNumber, ImageFormat format)
Sets the pixel format for the given image.
Definition: imagepair.h:86
unsigned char * getPixelData(int imageNumber) const
Returns the pixel data for the given image.
Definition: imagepair.h:190
const float * getQMatrix() const
Returns a pointer to the disparity-to-depth mapping matrix q.
Definition: imagepair.h:198
int getWidth() const
Returns the width of each image.
Definition: imagepair.h:155
void setDisparityRange(int minimum, int maximum)
Sets the value range for the disparity map contained in this image pair.
Definition: imagepair.h:139
void setWidth(int w)
Sets a new width for both images.
Definition: imagepair.h:60
void setQMatrix(const float *q)
Sets the pointer to the disparity-to-depth mapping matrix q.
Definition: imagepair.h:109
void setRowStride(int imageNumber, int stride)
Sets a new row stride for the pixel data of one image.
Definition: imagepair.h:74
void getTimestamp(int &seconds, int &microsec) const
Returns the time at which this image pair has been captured.
Definition: imagepair.h:214
void setPixelData(int imageNumber, unsigned char *pixelData)
Sets the pixel data for the given image.
Definition: imagepair.h:98
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:227
A set of two images, which are usually the left camera image and the disparity map.
Definition: imagepair.h:30
ImageFormat getPixelFormat(int imageNumber) const
Returns the pixel format for the given image.
Definition: imagepair.h:179
8-bit greyscale format
Definition: imagepair.h:37
int getHeight() const
Returns the height of each image.
Definition: imagepair.h:160
unsigned int getSequenceNumber() const
Returns the sequence number for this image pair.
Definition: imagepair.h:205
int getRowStride(int imageNumber) const
Returns the row stride for the pixel data of one image.
Definition: imagepair.h:168
void setImageDisparityPair(bool dispPair)
Sets whether this is a left camera image and disparity map pair, or two raw camera images...
Definition: imagepair.h:148
ImageFormat
Image formats that can be transferred.
Definition: imagepair.h:35
Nerian Vision Technologies