30 #ifndef OPENCVCAPTURE_H
31 #define OPENCVCAPTURE_H
33 #include <condition_variable>
37 #include <opencv2/opencv.hpp>
38 #include <opencv2/highgui/highgui.hpp>
40 #include "captureinterface.h"
90 std::string
getPath()
const override {
return path; }
109 {
return INTERFACE_TYPE::OPENCV; }
126 bool isOpen()
const override {
return opened; }
133 bool open(
int index);
135 bool open(
const std::string& path)
override;
150 void resetStats()
override { missed_frames = 0; retrieved_frames = 0; }
180 static cv::Mat applyBarrel(
const cv::Mat& image,
double effect);
188 void clearBuffer() { buffer = createEmptyFrame(resolution); }
199 static cv::Mat convertTo3Channels(
const cv::Mat& image);
206 static FrameCapture createEmptyFrame(
const cv::Size& frame_size);
214 inline void getFrameSize();
225 inline void keepWorkerReady();
238 inline bool retrieve_next(std::unique_lock<std::mutex>& guard);
252 std::string path =
"";
254 int retrieved_frames;
258 double barrel_correction = 0.0;
259 bool capture =
false;
260 std::condition_variable capture_next;
262 bool read_error =
false;
263 std::condition_variable retrieved;
264 std::unique_ptr<std::thread> retriever =
nullptr;
265 cv::VideoCapture source;
266 bool terminate =
false;
270 #endif // OPENCVCAPTURE_H
double getProperty(int propId)
Gets the OpenCV specific source properties.
Definition: opencvcapture.cpp:241
DISALLOW_COPY_AND_ASSIGN(OpenCVCapture)
Copy and assign of the class is not allowed.
std::string getPath() const override
Retrieves the path given during the initialization.
Definition: opencvcapture.h:90
Interface for the capture devices.
Definition: captureinterface.h:47
bool setProperty(int propId, double value)
Sets OpenCV specific source properties.
Definition: opencvcapture.cpp:480
std::string getDescription() const override
Retrieves the description of the device.
Definition: opencvcapture.cpp:180
bool hasNew() override
Checks whether the device has a new image to be retrieved or not.
Definition: opencvcapture.cpp:278
The OpenCV capturing class.
Definition: opencvcapture.h:65
int getMissedFrames() const override
Retrieves the logged frame misses.
Definition: opencvcapture.h:86
void release()
Forces the release of the worker thread.
Definition: opencvcapture.cpp:364
void setBarrelCorrection(double amount) override
Sets the amount of the barrel correction to be applied.
Definition: opencvcapture.cpp:468
void resetStats() override
Resets the statistical counters.
Definition: opencvcapture.h:150
bool setResolution(const cv::Size &new_size) override
Sets the capturing device resolution.
Definition: opencvcapture.cpp:506
bool isOpen() const override
Checks whether the source has been initialized or not.
Definition: opencvcapture.h:126
std::uint64_t FrameTime
Used to store milliseconds interval in frame times.
Definition: common.h:138
double getBarrelCorrection() override
Retrieves the barrel correction applied to the source.
Definition: opencvcapture.cpp:158
The structure is used for storing a single source frame.
Definition: common.h:241
double getFramerate() const override
Retrieves the capture device framerate.
Definition: opencvcapture.h:84
cv::Size getResolution() const override
Retrieves the capture device resolution.
Definition: opencvcapture.h:104
int getRetrievedFrames() const override
Retrieves the total logged frames.
Definition: opencvcapture.h:106
const int UNKNOWN_DEVICE
Used to indicate unknown hardware device.
Definition: common.h:224
FrameCapture getNext(bool skip, bool *error) override
Retrieves the next frame.
Definition: opencvcapture.cpp:208
int getDeviceID() const override
Returns the ID number the device was initialized with.
Definition: opencvcapture.h:82
INTERFACE_TYPE
Used to define the type of source interface.
Definition: captureinterface.h:140
bool open(int index)
Opens OpenCV VideoCapture for the hardware device.
Definition: opencvcapture.cpp:334
FrameCapture getBuffered() override
Retrieves the currently buffered frame.
Definition: opencvcapture.cpp:173
INTERFACE_TYPE getType() const overridefinal
Retrieves the type of the device.
Definition: opencvcapture.h:108