libvisiontransfer  6.2.1
imagepair-opencv.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_OPENCV_H
16 #define VISIONTRANSFER_IMAGEPAIR_OPENCV_H
17 
18 #ifdef CV_MAJOR_VERSION
19 
20 /*
21  * OpenCV-specific implementations that need to be inlined in order to avoid
22  * dependencies for projects that do not make use of OpenCV
23  */
24 
25 inline void ImagePair::toOpenCVImage(int imageNumber, cv::Mat& dest, bool convertRgbToBgr) {
26  assert(imageNumber >= 0 && imageNumber <=1);
27 
28  switch(formats[imageNumber]) {
30  dest= cv::Mat_<unsigned short>(height, width,
31  reinterpret_cast<unsigned short*>(data[imageNumber]), rowStride[imageNumber]);
32  break;
34  dest = cv::Mat_<unsigned char>(height, width,
35  data[imageNumber], rowStride[imageNumber]);
36  break;
38  dest = cv::Mat_<cv::Vec3b>(height, width,
39  reinterpret_cast<cv::Vec3b*>(data[imageNumber]), rowStride[imageNumber]);
40  if(convertRgbToBgr) {
41  cv::cvtColor(dest, dest, cv::COLOR_RGB2BGR);
42  }
43  break;
44  }
45 }
46 
47 #endif
48 #endif
8-bit greyscale format
Definition: imagepair.h:38
void toOpenCVImage(int imageNumber, cv::Mat &dest, bool convertRgbToBgr=true)
Converts one image of the pair to an OpenCV image.
8-bit RGB format
Definition: imagepair.h:41
Nerian Vision Technologies