29 #include <opencv2/highgui/highgui.hpp>
36 using CVCapturePtr = std::unique_ptr<cv::VideoCapture>;
38 class OpenCVImageSource :
public ImageSource {
40 OpenCVImageSource(CVCapturePtr &&cam) : m_camera(
std::move(cam)) {
41 if (m_camera->isOpened()) {
45 virtual ~OpenCVImageSource() {}
47 bool ok()
const override {
return m_camera && m_camera->isOpened(); }
54 CVCapturePtr m_camera;
58 ImageSourcePtr openOpenCVCamera(
int which) {
59 auto ret = ImageSourcePtr{};
60 auto cam = CVCapturePtr{
new cv::VideoCapture(which)};
61 if (!cam->isOpened()) {
65 ret.reset(
new OpenCVImageSource{std::move(cam)});
72 m_camera->retrieve(color);
77 void OpenCVImageSource::storeRes() {
78 int height =
static_cast<int>(m_camera->get(CV_CAP_PROP_FRAME_HEIGHT));
79 int width =
static_cast<int>(m_camera->get(CV_CAP_PROP_FRAME_WIDTH));
80 m_res = cv::Size(width, height);
cv::Size resolution() const override
Get resolution of the images from this source.
void retrieveColor(cv::Mat &color, osvr::util::time::TimeValue ×tamp) override