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