2022-01-19 01:07:49 +03:00
|
|
|
// Copyright (C) 2018-2022 Intel Corporation
|
2018-10-16 13:45:03 +03:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifdef USE_OPENCV
|
2021-08-11 14:47:29 +03:00
|
|
|
# include <fstream>
|
|
|
|
|
# include <iostream>
|
2021-12-13 11:30:58 +03:00
|
|
|
|
|
|
|
|
// clang-format off
|
2021-08-11 14:47:29 +03:00
|
|
|
# include <opencv2/opencv.hpp>
|
2021-12-13 11:30:58 +03:00
|
|
|
|
|
|
|
|
# include "samples/slog.hpp"
|
|
|
|
|
# include "opencv_wrapper.h"
|
|
|
|
|
// clang-format on
|
2018-10-16 13:45:03 +03:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace FormatReader;
|
|
|
|
|
|
2021-04-22 14:02:54 +03:00
|
|
|
OCVReader::OCVReader(const string& filename) {
|
2018-10-16 13:45:03 +03:00
|
|
|
img = cv::imread(filename);
|
|
|
|
|
_size = 0;
|
|
|
|
|
|
|
|
|
|
if (img.empty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-22 14:02:54 +03:00
|
|
|
_size = img.size().width * img.size().height * img.channels();
|
|
|
|
|
_width = img.size().width;
|
2018-10-16 13:45:03 +03:00
|
|
|
_height = img.size().height;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-12 18:25:53 +03:00
|
|
|
std::shared_ptr<unsigned char> OCVReader::getData(size_t width = 0, size_t height = 0) {
|
2021-10-28 12:58:08 +03:00
|
|
|
if (width == 0)
|
|
|
|
|
width = img.cols;
|
|
|
|
|
|
|
|
|
|
if (height == 0)
|
|
|
|
|
height = img.rows;
|
2018-10-16 13:45:03 +03:00
|
|
|
|
2021-10-28 12:58:08 +03:00
|
|
|
size_t size = width * height * img.channels();
|
2018-10-16 13:45:03 +03:00
|
|
|
_data.reset(new unsigned char[size], std::default_delete<unsigned char[]>());
|
2021-10-28 12:58:08 +03:00
|
|
|
|
2021-11-10 19:19:31 +09:00
|
|
|
cv::Mat resized(cv::Size(width, height), img.type(), _data.get());
|
2021-10-28 12:58:08 +03:00
|
|
|
|
|
|
|
|
if (width != img.cols || height != img.rows) {
|
|
|
|
|
slog::warn << "Image is resized from (" << img.cols << ", " << img.rows << ") to (" << width << ", " << height
|
|
|
|
|
<< ")" << slog::endl;
|
2018-10-16 13:45:03 +03:00
|
|
|
}
|
2021-10-28 12:58:08 +03:00
|
|
|
// cv::resize() just copy data to output image if sizes are the same
|
|
|
|
|
cv::resize(img, resized, cv::Size(width, height));
|
|
|
|
|
|
2018-10-16 13:45:03 +03:00
|
|
|
return _data;
|
|
|
|
|
}
|
|
|
|
|
#endif
|