OSVR-Core
DirectShowToCV.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_DirectShowToCV_h_GUID_C9B19C46_CA43_4481_A5B9_CB76397DD2C3
26 #define INCLUDED_DirectShowToCV_h_GUID_C9B19C46_CA43_4481_A5B9_CB76397DD2C3
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
32 #include <opencv2/core/core.hpp>
33 
34 // Standard includes
35 // - none
36 
37 template <typename CameraType> inline cv::Mat retrieve(CameraType &camera) {
38  int minx, miny, maxx, maxy;
39  camera.read_range(minx, maxx, miny, maxy);
40  auto height = maxy - miny + 1;
41  auto width = maxx - minx + 1;
42  // auto frame = cv::Mat(height, width, CV_8UC3, camera.get_pixel_buffer());
43  auto frame =
44  cv::Mat(camera.get_pixel_buffer()).reshape(3 /*channels*/, height);
45  auto ret = cv::Mat{};
46  cv::flip(frame, ret, 0);
47  return ret;
48 }
49 
50 #endif // INCLUDED_DirectShowToCV_h_GUID_C9B19C46_CA43_4481_A5B9_CB76397DD2C3