-
Notifications
You must be signed in to change notification settings - Fork 0
/
slmat_to_cvmat.cpp
49 lines (41 loc) · 1.79 KB
/
slmat_to_cvmat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// This code is from stereolabs github https://github.com/stereolabs/zed-opencv
// and at the point of writing licensed with the MIT License
//
#include "slmat_to_cvmat.h"
#include <opencv2/core/mat.hpp>
#include <sl/Camera.hpp>
#include <opencv2/opencv.hpp>
// OpenCV dep
//#include <opencv2/cvconfig.h>
// todo: integrate to object_detector
int getOCVtype(sl::MAT_TYPE type) {
int cv_type = -1;
switch (type) {
case sl::MAT_TYPE::F32_C1: cv_type = CV_32FC1; break;
case sl::MAT_TYPE::F32_C2: cv_type = CV_32FC2; break;
case sl::MAT_TYPE::F32_C3: cv_type = CV_32FC3; break;
case sl::MAT_TYPE::F32_C4: cv_type = CV_32FC4; break;
case sl::MAT_TYPE::U8_C1: cv_type = CV_8UC1; break;
case sl::MAT_TYPE::U8_C2: cv_type = CV_8UC2; break;
case sl::MAT_TYPE::U8_C3: cv_type = CV_8UC3; break;
case sl::MAT_TYPE::U8_C4: cv_type = CV_8UC4; break;
default: break;
}
return cv_type;
}
/**
* Conversion function between sl::Mat and cv::Mat
**/
cv::Mat slMat2cvMat(sl::Mat &input) {
// Since cv::Mat data requires a uchar* pointer, we get the uchar1 pointer from sl::Mat (getPtr<T>())
// cv::Mat and sl::Mat will share a single memory structure
return cv::Mat(input.getHeight(), input.getWidth(), getOCVtype(input.getDataType()), input.getPtr<sl::uchar1>(sl::MEM::CPU), input.getStepBytes(sl::MEM::CPU));
}
//#ifdef HAVE_CUDA
//cv::cuda::GpuMat slMat2cvMatGPU(sl::Mat& input) {
// // Since cv::Mat data requires a uchar* pointer, we get the uchar1 pointer from sl::Mat (getPtr<T>())
// // cv::Mat and sl::Mat will share a single memory structure
// return cv::cuda::GpuMat(input.getHeight(), input.getWidth(), getOCVtype(input.getDataType()), input.getPtr<sl::uchar1>(MEM::GPU), input.getStepBytes(sl::MEM::GPU));
//}
//#endif