MLECO-1252 ASR sample application using the public ArmNN C++ API.

Change-Id: I98cd505b8772a8c8fa88308121bc94135bb45068
Signed-off-by: Éanna Ó Catháin <eanna.ocathain@arm.com>
diff --git a/samples/common/include/CVUtils/CvVideoFileWriter.hpp b/samples/common/include/CVUtils/CvVideoFileWriter.hpp
new file mode 100644
index 0000000..30348f0
--- /dev/null
+++ b/samples/common/include/CVUtils/CvVideoFileWriter.hpp
@@ -0,0 +1,61 @@
+//
+// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include "IFrameOutput.hpp"
+#include <opencv2/opencv.hpp>
+
+namespace common
+{
+
+class CvVideoFileWriter : public IFrameOutput<cv::Mat> {
+public:
+    /**
+     * @brief Default constructor.
+     *
+     * Underlying open cv video writer object will be instantiated.
+     */
+    CvVideoFileWriter() = default;
+
+    ~CvVideoFileWriter() override = default;
+
+    /**
+     * @brief Initialises video file writer.
+     *
+     * Opens opencv writer with given params. FFMPEG backend is used.
+     *
+     * @param outputVideo path to the video file.
+     * @param encoding cv::CAP_PROP_FOURCC code.
+     * @param fps target frame rate.
+     * @param width target frame width.
+     * @param height target frame height.
+     *
+     */
+    void Init(const std::string& outputVideo, int encoding, double fps, int width, int height);
+
+    /**
+     * Writes frame to the file using opencv writer.
+     *
+     * @param frame data to write.
+     */
+    void WriteFrame(std::shared_ptr<cv::Mat>& frame) override;
+
+    /**
+     * Releases opencv writer.
+     */
+    void Close() override;
+
+    /**
+     * Checks if opencv writer was successfully opened.
+     * @return true is underlying writer is ready to be used, false otherwise.
+     */
+    bool IsReady() const override;
+
+private:
+    cv::VideoWriter m_cvWriter{};
+    bool m_ready = false;
+};
+}// namespace common
\ No newline at end of file
diff --git a/samples/common/include/CVUtils/CvVideoFrameReader.hpp b/samples/common/include/CVUtils/CvVideoFrameReader.hpp
new file mode 100644
index 0000000..96d94f4
--- /dev/null
+++ b/samples/common/include/CVUtils/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 common
+{
+
+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<common::CvVideoFrameReader> reader);
+
+    std::shared_ptr<cv::Mat> ReadFrame() override;
+
+    bool IsExhausted(const std::shared_ptr<cv::Mat>& frame) const override;
+
+private:
+    std::unique_ptr<common::CvVideoFrameReader> m_reader;
+};
+
+}// namespace common
\ No newline at end of file
diff --git a/samples/common/include/CVUtils/CvWindowOutput.hpp b/samples/common/include/CVUtils/CvWindowOutput.hpp
new file mode 100644
index 0000000..4b9ae3b
--- /dev/null
+++ b/samples/common/include/CVUtils/CvWindowOutput.hpp
@@ -0,0 +1,53 @@
+//
+// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include "IFrameOutput.hpp"
+#include <opencv2/opencv.hpp>
+
+namespace common
+{
+
+class CvWindowOutput : public IFrameOutput<cv::Mat> {
+public:
+
+    CvWindowOutput() = default;
+
+    ~CvWindowOutput() override = default;
+
+    /**
+     * @brief Creates a named window.
+     *
+     * Uses opencv to create a window with given name.
+     *
+     * @param windowName opencv window name.
+     *
+     */
+    void Init(const std::string& windowName);
+
+    /**
+     * Writes frame to the window.
+     *
+     * @param frame data to write.
+     */
+    void WriteFrame(std::shared_ptr<cv::Mat>& frame) override;
+
+    /**
+     * Releases all windows.
+     */
+    void Close() override;
+
+    /**
+     * Always true.
+     * @return true.
+     */
+    bool IsReady() const override;
+
+private:
+    std::string m_windowName;
+
+};
+}// namespace common
\ No newline at end of file
diff --git a/samples/common/include/CVUtils/IFrameOutput.hpp b/samples/common/include/CVUtils/IFrameOutput.hpp
new file mode 100644
index 0000000..6f7ca0b
--- /dev/null
+++ b/samples/common/include/CVUtils/IFrameOutput.hpp
@@ -0,0 +1,48 @@
+//
+// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <cstddef>
+#include <memory>
+
+namespace common
+{
+/**
+ * @brief Frames output interface
+ *
+ * @tparam FrameDataT frame container data type
+ */
+    template<typename FrameDataT> class IFrameOutput
+    {
+
+    public:
+        /**
+         * @brief Writes frame to the selected output
+         *
+         * @param frame container
+         */
+        virtual void WriteFrame(std::shared_ptr <FrameDataT>& frame) = 0;
+
+        /**
+         * @brief Closes the frame output
+         */
+        virtual void Close() = 0;
+
+        /**
+         * @brief Checks if the frame sink is ready to write.
+         *
+         * @return True if frame sink is ready, False otherwise
+         */
+        virtual bool IsReady() const = 0;
+
+        /**
+         * @brief Default destructor
+         */
+        virtual ~IFrameOutput() = default;
+
+    };
+
+}// namespace common
diff --git a/samples/common/include/CVUtils/IFrameReader.hpp b/samples/common/include/CVUtils/IFrameReader.hpp
new file mode 100644
index 0000000..e171b3b
--- /dev/null
+++ b/samples/common/include/CVUtils/IFrameReader.hpp
@@ -0,0 +1,45 @@
+//
+// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <cstddef>
+#include <memory>
+
+namespace common
+{
+/**
+ * @brief Frame source reader interface
+ *
+ * @tparam FrameDataT frame container data type
+ */
+template<typename FrameDataT> class IFrameReader
+{
+
+public:
+    /**
+     * @brief Reads the next frame from the source
+     *
+     * @return pointer to the frame container
+     */
+    virtual std::shared_ptr <FrameDataT> ReadFrame() = 0;
+
+    /**
+     * @brief Checks if the frame source has more frames to read.
+     *
+     * @param[in] frame the pointer to the last frame captured with the ReadFrame method could be used in
+     *                  implementation specific logic to check frames source state.
+     * @return True if frame source was exhausted, False otherwise
+     */
+    virtual bool IsExhausted(const std::shared_ptr <FrameDataT>& frame) const = 0;
+
+    /**
+     * @brief Default destructor
+     */
+    virtual ~IFrameReader() = default;
+
+};
+
+}// namespace common
\ No newline at end of file