plugin  0.1.0
images_capture.h
1 // Copyright (C) 2020-2024 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 #include <stddef.h>
7 
8 #include <limits>
9 #include <memory>
10 #include <string>
11 
12 #include <opencv2/core.hpp>
13 
15 
16 enum class read_type { efficient, safe };
17 
19 public:
20  const bool loop;
21 
22  ImagesCapture(bool loop) : loop{loop} {}
23  virtual double fps() const = 0;
24  virtual cv::Mat read() = 0;
25  virtual std::string getType() const = 0;
26  const PerformanceMetrics& getMetrics() {
27  return readerMetrics;
28  }
29  virtual ~ImagesCapture() = default;
30 
31 protected:
32  PerformanceMetrics readerMetrics;
33 };
34 
35 // An advanced version of
36 // try {
37 // return cv::VideoCapture(std::stoi(input));
38 // } catch (const std::invalid_argument&) {
39 // return cv::VideoCapture(input);
40 // } catch (const std::out_of_range&) {
41 // return cv::VideoCapture(input);
42 // }
43 // Some VideoCapture backends continue owning the video buffer under cv::Mat. safe_copy forses to return a copy from
44 // read()
45 // https://github.com/opencv/opencv/blob/46e1560678dba83d25d309d8fbce01c40f21b7be/modules/gapi/include/opencv2/gapi/streaming/cap.hpp#L72-L76
46 std::unique_ptr<ImagesCapture> openImagesCapture(
47  const std::string& input,
48  bool loop,
49  read_type type = read_type::efficient,
50  size_t initialImageId = 0,
51  size_t readLengthLimit = std::numeric_limits<size_t>::max(), // General option
52  cv::Size cameraResolution = {1280, 720});
Definition: images_capture.h:18
Definition: performance_metrics.hpp:19
a header file for performance metrics calculation class