OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
DirectShowImageSource.cpp
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 // Internal Includes
26 #include "ImageSourceFactories.h"
28 #include "DirectShowToCV.h"
29 
30 // Library/third-party includes
31 // - none
32 
33 // Standard includes
34 // - none
35 
36 namespace osvr {
37 namespace vbtracker {
38  using directx_camera_server_ptr = std::unique_ptr<directx_camera_server>;
39  class DirectShowImageSource : public ImageSource {
40  public:
41  DirectShowImageSource(directx_camera_server_ptr &&cam)
42  : m_camera(std::move(cam)) {
43  m_camera->read_image_to_memory();
44  if (m_camera->isOpened()) {
45  storeRes();
46  }
47  }
48  virtual ~DirectShowImageSource() {}
49 
50  bool ok() const override {
51  return m_camera && m_gotRes && m_camera->working() &&
52  m_camera->isOpened();
53  }
54  bool grab() override;
55  void retrieveColor(cv::Mat &color) override;
56  cv::Size resolution() const override;
57 
58  private:
59  void storeRes();
60  directx_camera_server_ptr m_camera;
61  bool m_gotRes = false;
62  cv::Size m_res;
63  };
64  ImageSourcePtr openHDKCameraDirectShow() {
65 
66  auto ret = ImageSourcePtr{};
67  auto cam = getDirectShowHDKCamera();
68  if (!cam) {
69  return ret;
70  }
71  ret.reset(new DirectShowImageSource{std::move(cam)});
72  return ret;
73  }
75  return m_camera->read_image_to_memory();
76  }
77  void DirectShowImageSource::retrieveColor(cv::Mat &color) {
78  color = ::retrieve(*m_camera);
79  }
80  cv::Size DirectShowImageSource::resolution() const { return m_res; }
81 
82  void DirectShowImageSource::storeRes() {
83  int minx, miny, maxx, maxy;
84  m_camera->read_range(minx, maxx, miny, maxy);
85  m_res = cv::Size(maxx - minx + 1, maxy - miny + 1);
86  m_gotRes = true;
87  }
88 } // namespace vbtracker
89 } // namespace osvr
cv::Size resolution() const override
Get resolution of the images from this source.
STL namespace.
void retrieveColor(cv::Mat &color, osvr::util::time::TimeValue &timestamp) override
virtual void retrieve(cv::Mat &color, cv::Mat &gray, osvr::util::time::TimeValue &timestamp)
Call after grab() to get the actual image data.
Definition: ImageSource.cpp:37