mirror of
https://github.com/open-mmlab/mmdeploy.git
synced 2025-01-14 08:09:43 +08:00
* hold async data and wait only at the end of the pipeline * fix use-after-free bugs * fix wording * bypass trivial cases for Pad to avoid ppl.cv's bug * fix pad * fix lint * cleanup * fix DefaultFormatBundle * fix all cpu preprocess impl * suppress log * fix dynamic library build & add comments for SyncOnScopeExit
43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
// Copyright (c) OpenMMLab. All rights reserved.
|
|
|
|
#include "core/utils/device_utils.h"
|
|
#include "opencv_utils.h"
|
|
#include "preprocess/transform/crop.h"
|
|
|
|
using namespace std;
|
|
|
|
namespace mmdeploy {
|
|
namespace cpu {
|
|
|
|
class CenterCropImpl : public ::mmdeploy::CenterCropImpl {
|
|
public:
|
|
explicit CenterCropImpl(const Value& args) : ::mmdeploy::CenterCropImpl(args) {}
|
|
|
|
protected:
|
|
Result<Tensor> CropImage(const Tensor& tensor, int top, int left, int bottom,
|
|
int right) override {
|
|
OUTCOME_TRY(auto src_tensor, MakeAvailableOnDevice(tensor, device_, stream_));
|
|
|
|
SyncOnScopeExit(stream_, src_tensor.buffer() != tensor.buffer(), src_tensor);
|
|
|
|
cv::Mat mat = Tensor2CVMat(src_tensor);
|
|
cv::Mat cropped_mat = Crop(mat, top, left, bottom, right);
|
|
return CVMat2Tensor(cropped_mat);
|
|
}
|
|
};
|
|
|
|
class CenterCropImplCreator : public Creator<::mmdeploy::CenterCropImpl> {
|
|
public:
|
|
const char* GetName() const override { return "cpu"; }
|
|
int GetVersion() const override { return 1; }
|
|
ReturnType Create(const Value& args) override { return make_unique<CenterCropImpl>(args); }
|
|
};
|
|
|
|
} // namespace cpu
|
|
} // namespace mmdeploy
|
|
|
|
using ::mmdeploy::CenterCropImpl;
|
|
using ::mmdeploy::cpu::CenterCropImplCreator;
|
|
|
|
REGISTER_MODULE(CenterCropImpl, CenterCropImplCreator);
|