gtsam_points
Loading...
Searching...
No Matches
texture_opencv.hpp
Go to the documentation of this file.
1#ifndef GLK_TEXTURE_OPENCV_HPP
2#define GLK_TEXTURE_OPENCV_HPP
3
4#include <glk/texture.hpp>
5#include <opencv2/opencv.hpp>
6
7// for old OpenCV
8#ifndef CV_16F
9#define CV_16F 7
10#endif
11
12namespace glk {
13
14static std::shared_ptr<glk::Texture> create_texture(const cv::Mat& image) {
15 Eigen::Vector2i size(image.cols, image.rows);
16
17 GLuint format = GL_BGR;
19
20 switch(image.depth()) {
21 case CV_8U:
22 type = GL_UNSIGNED_BYTE;
23 break;
24 case CV_16U:
25 type = GL_UNSIGNED_SHORT;
26 break;
27 case CV_8S:
28 type = GL_BYTE;
29 break;
30 case CV_16S:
31 type = GL_SHORT;
32 break;
33 case CV_32S:
34 type = GL_INT;
35 break;
36 case CV_16F:
37 type = GL_HALF_FLOAT;
38 break;
39 case CV_32F:
40 type = GL_FLOAT;
41 break;
42 case CV_64F:
43 type = GL_DOUBLE;
44 break;
45 default:
46 std::cerr << "error: unsupported depth " << image.depth() << std::endl;
47 break;
48 }
49
50 switch(image.channels()) {
51 case 1:
52 format = GL_RED;
53 break;
54 case 2:
55 format = GL_RG;
56 break;
57 case 3:
58 format = GL_BGR;
59 break;
60 case 4:
61 format = GL_BGRA;
62 break;
63 default:
64 std::cerr << "error: unsupported channels " << image.channels() << std::endl;
65 break;
66 }
67
68 return std::make_shared<glk::Texture>(size, GL_RGBA, format, type, image.data);
69}
70
71} // namespace glk
72
73#endif
Definition async_buffer_copy.hpp:6
std::enable_if_t< needs_aligned_allocator< T >::value, std::shared_ptr< T > > make_shared(Args &&... args)
Definition make_shared.hpp:20
static std::shared_ptr< glk::Texture > create_texture(const cv::Mat &image)
Definition texture_opencv.hpp:14
#define CV_16F
Definition texture_opencv.hpp:9