diff options
author | Éanna Ó Catháin <eanna.ocathain@arm.com> | 2020-09-14 17:36:49 +0100 |
---|---|---|
committer | Jim Flynn <jim.flynn@arm.com> | 2020-09-14 18:40:01 +0000 |
commit | 919c14ef132986aa1514b2070ce6d19b5579a6ab (patch) | |
tree | 5c281e02a083768f65871cb861ab9b32ac7d8767 /samples/ObjectDetection/include/CvVideoFrameReader.hpp | |
parent | 589e3e81a86c83456580e112978bf7a0ed5f43ac (diff) | |
download | armnn-919c14ef132986aa1514b2070ce6d19b5579a6ab.tar.gz |
MLECO-929 Add Object Detection sample application using the public ArmNN C++ API
Change-Id: I14aa1b4b726212cffbefd6687203f93f936fa872
Signed-off-by: Éanna Ó Catháin <eanna.ocathain@arm.com>
Diffstat (limited to 'samples/ObjectDetection/include/CvVideoFrameReader.hpp')
-rw-r--r-- | samples/ObjectDetection/include/CvVideoFrameReader.hpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/samples/ObjectDetection/include/CvVideoFrameReader.hpp b/samples/ObjectDetection/include/CvVideoFrameReader.hpp new file mode 100644 index 0000000000..081f92620e --- /dev/null +++ b/samples/ObjectDetection/include/CvVideoFrameReader.hpp @@ -0,0 +1,108 @@ +// +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + + +#include "IFrameReader.hpp" +#include <opencv2/opencv.hpp> + +namespace od +{ + +class CvVideoFrameReader : + public IFrameReader<cv::Mat> +{ +public: + /** + * @brief Default constructor. + * + * Underlying open cv video capture object will be instantiated. + */ + CvVideoFrameReader() = default; + + ~CvVideoFrameReader() override = default; + + /** + *@brief Initialises reader to capture frames from video file. + * + * @param source path to the video file or image sequence. + * + * @throws std::runtime_error if init failed + */ + void Init(const std::string& source); + + std::shared_ptr <cv::Mat> ReadFrame() override; + + bool IsExhausted(const std::shared_ptr <cv::Mat>& frame) const override; + + /** + * Returns effective video frame width supported by the source/set by the user. + * Must be called after Init method. + * @return frame width + */ + int GetSourceWidth() const; + + /** + * Returns effective video frame height supported by the source/set by the user. + * Must be called after Init method. + * @return frame height + */ + int GetSourceHeight() const; + + /** + * Returns effective fps value supported by the source/set by the user. + * @return fps value + */ + double GetSourceFps() const; + + /** + * Will query OpenCV to convert images to RGB + * Copy is actually default behaviour, but the set function needs to be called + * in order to know whether OpenCV supports conversion from our source format. + * @return boolean, + * true: OpenCV returns RGB + * false: OpenCV returns the fourcc format from GetSourceEncoding + */ + bool ConvertToRGB(); + + /** + * Returns 4-character code of codec. + * @return codec name + */ + std::string GetSourceEncoding() const; + + /** + * Get the fourcc int from its string name. + * @return codec int + */ + int GetSourceEncodingInt() const; + + int GetFrameCount() const; + +private: + cv::VideoCapture m_capture; + + void CheckIsOpen(const std::string& source); +}; + +class CvVideoFrameReaderRgbWrapper : + public IFrameReader<cv::Mat> +{ +public: + CvVideoFrameReaderRgbWrapper() = delete; + CvVideoFrameReaderRgbWrapper(const CvVideoFrameReaderRgbWrapper& o) = delete; + CvVideoFrameReaderRgbWrapper(CvVideoFrameReaderRgbWrapper&& o) = delete; + + CvVideoFrameReaderRgbWrapper(std::unique_ptr<od::CvVideoFrameReader> reader); + + std::shared_ptr<cv::Mat> ReadFrame() override; + + bool IsExhausted(const std::shared_ptr<cv::Mat>& frame) const override; + +private: + std::unique_ptr<od::CvVideoFrameReader> m_reader; +}; + +}// namespace od
\ No newline at end of file |