1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 #include "opencv_wraper.h"
10 #include <opencv2/opencv.hpp>
12 #include <samples/slog.hpp>
15 using namespace FormatReader;
17 OCVReader::OCVReader(const string &filename) {
18 img = cv::imread(filename);
25 _size = img.size().width * img.size().height * img.channels();
26 _width = img.size().width;
27 _height = img.size().height;
30 std::shared_ptr<unsigned char> OCVReader::getData(size_t width = 0, size_t height = 0) {
32 if (width != 0 && height != 0) {
33 size_t iw = img.size().width;
34 size_t ih = img.size().height;
35 if (width != iw || height != ih) {
36 slog::warn << "Image is resized from (" << iw << ", " << ih << ") to (" << width << ", " << height << ")" << slog::endl;
38 cv::resize(img, resized, cv::Size(width, height));
41 size_t size = resized.size().width * resized.size().height * resized.channels();
42 _data.reset(new unsigned char[size], std::default_delete<unsigned char[]>());
43 for (size_t id = 0; id < size; ++id) {
44 _data.get()[id] = resized.data[id];