Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / samples / common / format_reader / MnistUbyte.h
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 /**
6  * \brief Mnist reader
7  * \file MnistUbyte.h
8  */
9 #pragma once
10
11 #include <memory>
12 #include <string>
13 #include <format_reader.h>
14
15 #include "register.h"
16
17 namespace FormatReader {
18 /**
19  * \class MnistUbyte
20  * \brief Reader for mnist db files
21  */
22 class MnistUbyte : public Reader {
23 private:
24     int reverseInt(int i);
25
26     static Register<MnistUbyte> reg;
27
28 public:
29     /**
30      * \brief Constructor of Mnist reader
31      * @param filename - path to input data
32      * @return MnistUbyte reader object
33      */
34     explicit MnistUbyte(const std::string &filename);
35     virtual ~MnistUbyte() {
36     }
37
38     /**
39      * \brief Get size
40      * @return size
41      */
42     size_t size() const override {
43         return _width * _height * 1;
44     }
45
46     void Release() noexcept override {
47         delete this;
48     }
49
50     std::shared_ptr<unsigned char> getData(size_t width, size_t height) override {
51         if ((width * height != 0) && (_width * _height != width * height)) {
52             std::cout << "[ WARNING ] Image won't be resized! Please use OpenCV.\n";
53             return nullptr;
54         }
55         return _data;
56     }
57 };
58 }  // namespace FormatReader