2021-12-07 10:57:55 +08:00
|
|
|
// Copyright (c) OpenMMLab. All rights reserved.
|
|
|
|
|
|
|
|
#ifndef MMDEPLOY_LOAD_H
|
|
|
|
#define MMDEPLOY_LOAD_H
|
|
|
|
|
|
|
|
#include "core/mat.h"
|
|
|
|
#include "core/tensor.h"
|
|
|
|
#include "transform.h"
|
|
|
|
|
|
|
|
namespace mmdeploy {
|
2022-02-24 20:08:44 +08:00
|
|
|
class MMDEPLOY_API PrepareImageImpl : public TransformImpl {
|
2021-12-07 10:57:55 +08:00
|
|
|
public:
|
|
|
|
explicit PrepareImageImpl(const Value& args);
|
2022-03-16 15:52:57 +08:00
|
|
|
~PrepareImageImpl() override = default;
|
2021-12-07 10:57:55 +08:00
|
|
|
|
|
|
|
Result<Value> Process(const Value& input) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual Result<Tensor> ConvertToBGR(const Mat& img) = 0;
|
|
|
|
virtual Result<Tensor> ConvertToGray(const Mat& img) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
struct prepare_image_arg_t {
|
|
|
|
bool to_float32{false};
|
|
|
|
std::string color_type{"color"};
|
|
|
|
};
|
|
|
|
using ArgType = struct prepare_image_arg_t;
|
|
|
|
|
|
|
|
ArgType arg_;
|
|
|
|
};
|
|
|
|
|
2022-02-24 20:08:44 +08:00
|
|
|
class MMDEPLOY_API PrepareImage : public Transform {
|
2021-12-07 10:57:55 +08:00
|
|
|
public:
|
|
|
|
explicit PrepareImage(const Value& args, int version = 0);
|
2022-03-16 15:52:57 +08:00
|
|
|
~PrepareImage() override = default;
|
2021-12-07 10:57:55 +08:00
|
|
|
|
|
|
|
Result<Value> Process(const Value& input) override { return impl_->Process(input); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<PrepareImageImpl> impl_;
|
|
|
|
};
|
|
|
|
|
2022-02-24 20:08:44 +08:00
|
|
|
MMDEPLOY_DECLARE_REGISTRY(PrepareImageImpl);
|
|
|
|
|
2021-12-07 10:57:55 +08:00
|
|
|
} // namespace mmdeploy
|
|
|
|
|
|
|
|
#endif // MMDEPLOY_LOAD_H
|