summaryrefslogtreecommitdiffhomepage
path: root/video-opencv/impl.hpp
blob: ed5499b09bd02aafc3c4629d6a58f3da924810e8 (plain)
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
50
51
52
53
54
55
/* Copyright (c) 2019 Stanislaw Halik <sthalik@misaki.pl>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 */

#pragma once

#include "video/camera.hpp"
#include <optional>
#include <opencv2/videoio.hpp>

namespace opencv_camera_impl {

using namespace video::impl;

struct metadata : camera_
{
    metadata();
    std::vector<QString> camera_names() const override;
    std::unique_ptr<camera> make_camera(const QString& name) override;
    bool can_show_dialog(const QString& camera_name) override;
    bool show_dialog(const QString& camera_name) override;
};

struct cam final : camera
{
static constexpr int video_capture_backend =
#ifdef _WIN32
    cv::CAP_DSHOW;
#elif !defined __APPLE__
    cv::CAP_V4L2;
#else
    cv::CAP_ANY;
#endif

    cam(int idx);
    ~cam() override;

    bool start(info& args) override;
    void stop() override;
    bool is_open() override;
    std::tuple<const frame&, bool> get_frame() override;
    bool show_dialog() override;

    bool get_frame_();

    std::optional<cv::VideoCapture> cap;
    cv::Mat mat;
    frame frame_;
    int idx = -1;
};

} // ns opencv_camera_impl