diff --git a/fastdeploy/backends/tensorrt/utils.h b/fastdeploy/backends/tensorrt/utils.h index bf84b2ef2..f76230526 100644 --- a/fastdeploy/backends/tensorrt/utils.h +++ b/fastdeploy/backends/tensorrt/utils.h @@ -35,7 +35,8 @@ struct FDInferDeleter { template void operator()(T* obj) const { if (obj) { - obj->destroy(); + delete obj; +// obj->destroy(); } } }; diff --git a/fastdeploy/vision/classification/ppcls/model.cc b/fastdeploy/vision/classification/ppcls/model.cc index 5f962f266..57e354111 100644 --- a/fastdeploy/vision/classification/ppcls/model.cc +++ b/fastdeploy/vision/classification/ppcls/model.cc @@ -108,7 +108,7 @@ bool PaddleClasModel::Preprocess(Mat* mat, FDTensor* output) { int height = mat->Height(); output->name = InputInfoOfRuntime(0).name; output->SetExternalData({1, channel, height, width}, FDDataType::FP32, - mat->GetCpuMat()->ptr()); + mat->GetOpenCVMat()->ptr()); return true; } diff --git a/fastdeploy/vision/common/processors/base.h b/fastdeploy/vision/common/processors/base.h index fa52e5e0d..d066a2f94 100644 --- a/fastdeploy/vision/common/processors/base.h +++ b/fastdeploy/vision/common/processors/base.h @@ -34,9 +34,10 @@ class Processor { virtual bool ImplByOpenCV(Mat* mat) = 0; -// virtual bool ImplByFalconCV(Mat* mat) { -// return ImplByOpenCV(mat); -// } + virtual bool ImplByFalconCV(Mat* mat) { + FDASSERT(false, "%s is not implemented with FalconCV, please use OpenCV instead.", Name().c_str()); + return false; + } virtual bool operator()(Mat* mat, ProcLib lib = ProcLib::OPENCV); diff --git a/fastdeploy/vision/common/processors/cast.cc b/fastdeploy/vision/common/processors/cast.cc index cbdaed311..44933345d 100644 --- a/fastdeploy/vision/common/processors/cast.cc +++ b/fastdeploy/vision/common/processors/cast.cc @@ -18,7 +18,7 @@ namespace fastdeploy { namespace vision { bool Cast::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); int c = im->channels(); if (dtype_ == "float") { if (im->type() != CV_32FC(c)) { diff --git a/fastdeploy/vision/common/processors/center_crop.cc b/fastdeploy/vision/common/processors/center_crop.cc index 8508fa942..d229347c4 100644 --- a/fastdeploy/vision/common/processors/center_crop.cc +++ b/fastdeploy/vision/common/processors/center_crop.cc @@ -18,7 +18,7 @@ namespace fastdeploy { namespace vision { bool CenterCrop::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); int height = static_cast(im->rows); int width = static_cast(im->cols); if (height < height_ || width < width_) { diff --git a/fastdeploy/vision/common/processors/color_space_convert.cc b/fastdeploy/vision/common/processors/color_space_convert.cc index 7ec1a0ed8..7c614a048 100644 --- a/fastdeploy/vision/common/processors/color_space_convert.cc +++ b/fastdeploy/vision/common/processors/color_space_convert.cc @@ -17,7 +17,7 @@ namespace fastdeploy { namespace vision { bool BGR2RGB::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); cv::Mat new_im; cv::cvtColor(*im, new_im, cv::COLOR_BGR2RGB); mat->SetMat(new_im); @@ -25,7 +25,7 @@ bool BGR2RGB::ImplByOpenCV(Mat* mat) { } bool RGB2BGR::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); cv::Mat new_im; cv::cvtColor(*im, new_im, cv::COLOR_RGB2BGR); mat->SetMat(new_im); diff --git a/fastdeploy/vision/common/processors/convert.cc b/fastdeploy/vision/common/processors/convert.cc index a8aa8337d..73ae5a0ef 100644 --- a/fastdeploy/vision/common/processors/convert.cc +++ b/fastdeploy/vision/common/processors/convert.cc @@ -29,7 +29,7 @@ Convert::Convert(const std::vector& alpha, } bool Convert::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); std::vector split_im; cv::split(*im, split_im); for (int c = 0; c < im->channels(); c++) { diff --git a/fastdeploy/vision/common/processors/crop.cc b/fastdeploy/vision/common/processors/crop.cc index b2898b1ac..1b5c8bcb8 100644 --- a/fastdeploy/vision/common/processors/crop.cc +++ b/fastdeploy/vision/common/processors/crop.cc @@ -18,7 +18,7 @@ namespace fastdeploy { namespace vision { bool Crop::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); int height = static_cast(im->rows); int width = static_cast(im->cols); if (height < height_ + offset_h_ || width < width_ + offset_w_) { diff --git a/fastdeploy/vision/common/processors/hwc2chw.cc b/fastdeploy/vision/common/processors/hwc2chw.cc index 70fb91b61..aeb073a74 100644 --- a/fastdeploy/vision/common/processors/hwc2chw.cc +++ b/fastdeploy/vision/common/processors/hwc2chw.cc @@ -22,7 +22,7 @@ bool HWC2CHW::ImplByOpenCV(Mat* mat) { << std::endl; return false; } - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); cv::Mat im_clone = im->clone(); int rh = im->rows; int rw = im->cols; diff --git a/fastdeploy/vision/common/processors/limit_by_stride.cc b/fastdeploy/vision/common/processors/limit_by_stride.cc index 1edb0aafa..3f9db27bc 100644 --- a/fastdeploy/vision/common/processors/limit_by_stride.cc +++ b/fastdeploy/vision/common/processors/limit_by_stride.cc @@ -18,7 +18,7 @@ namespace fastdeploy { namespace vision { bool LimitByStride::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); int origin_w = im->cols; int origin_h = im->rows; int rw = origin_w - origin_w % stride_; diff --git a/fastdeploy/vision/common/processors/limit_long.cc b/fastdeploy/vision/common/processors/limit_long.cc index 0758fe7f8..7109636cc 100644 --- a/fastdeploy/vision/common/processors/limit_long.cc +++ b/fastdeploy/vision/common/processors/limit_long.cc @@ -18,7 +18,7 @@ namespace fastdeploy { namespace vision { bool LimitLong::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); int origin_w = im->cols; int origin_h = im->rows; int im_size_max = std::max(origin_w, origin_h); diff --git a/fastdeploy/vision/common/processors/limit_short.cc b/fastdeploy/vision/common/processors/limit_short.cc index 29ae30b3f..348291ff0 100644 --- a/fastdeploy/vision/common/processors/limit_short.cc +++ b/fastdeploy/vision/common/processors/limit_short.cc @@ -18,7 +18,7 @@ namespace fastdeploy { namespace vision { bool LimitShort::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); int origin_w = im->cols; int origin_h = im->rows; int im_size_min = std::min(origin_w, origin_h); diff --git a/fastdeploy/vision/common/processors/mat.cc b/fastdeploy/vision/common/processors/mat.cc index 6d4066bda..efc109f0b 100644 --- a/fastdeploy/vision/common/processors/mat.cc +++ b/fastdeploy/vision/common/processors/mat.cc @@ -12,17 +12,26 @@ // See the License for the specific language governing permissions and // limitations under the License. #include "fastdeploy/vision/common/processors/mat.h" +#include "fastdeploy/vision/common/processors/utils.h" #include "fastdeploy/utils/utils.h" + namespace fastdeploy { namespace vision { -cv::Mat* Mat::GetCpuMat() { - return &cpu_mat; +void* Mat::Data() { + if (mat_type == ProcLib::FALCONCV) { +#ifdef ENABLE_FALCONCV + return fcv_mat.data(); +#else + FDASSERT(false, "FastDeploy didn't compile with FalconCV, but met data type with fcv::Mat."); +#endif + } + return cpu_mat.ptr(); } void Mat::ShareWithTensor(FDTensor* tensor) { tensor->SetExternalData({Channels(), Height(), Width()}, Type(), - GetCpuMat()->ptr()); + Data()); tensor->device = Device::CPU; if (layout == Layout::HWC) { tensor->shape = {Height(), Width(), Channels()}; @@ -30,8 +39,7 @@ void Mat::ShareWithTensor(FDTensor* tensor) { } bool Mat::CopyToTensor(FDTensor* tensor) { - cv::Mat* im = GetCpuMat(); - int total_bytes = im->total() * im->elemSize(); + int total_bytes = Height() * Width() * Channels() * FDDataTypeSize(Type()); if (total_bytes != tensor->Nbytes()) { FDERROR << "While copy Mat to Tensor, requires the memory size be same, " "but now size of Tensor = " @@ -39,53 +47,52 @@ bool Mat::CopyToTensor(FDTensor* tensor) { << std::endl; return false; } - memcpy(tensor->MutableData(), im->ptr(), im->total() * im->elemSize()); + memcpy(tensor->MutableData(), Data(), total_bytes); return true; } void Mat::PrintInfo(const std::string& flag) { - cv::Mat* im = GetCpuMat(); - cv::Scalar mean = cv::mean(*im); - std::cout << flag << ": " - << "Channel=" << Channels() << ", height=" << Height() - << ", width=" << Width() << ", mean="; - for (int i = 0; i < Channels(); ++i) { - std::cout << mean[i] << " "; + if (mat_type == ProcLib::FALCONCV) { +#ifdef ENABLE_FALCONCV + fcv::Scalar mean = fcv::mean(fcv_mat); + std::cout << flag << ": " + << "DataType=" << Type() << ", " + << "Channel=" << Channels() << ", " + << "Height=" << Height() << ", " + << "Width=" << Width() << ", " + << "Mean="; + for (int i = 0; i < Channels(); ++i) { + std::cout << mean[i] << " "; + } + std::cout << std::endl; +#else + FDASSERT(false, "FastDeploy didn't compile with FalconCV, but met data type with fcv::Mat."); +#endif + } else { + cv::Scalar mean = cv::mean(cpu_mat); + std::cout << flag << ": " + << "DataType=" << Type() << ", " + << "Channel=" << Channels() << ", " + << "Height=" << Height() << ", " + << "Width=" << Width() << ", " + << "Mean="; + for (int i = 0; i < Channels(); ++i) { + std::cout << mean[i] << " "; + } + std::cout << std::endl; } - std::cout << std::endl; } FDDataType Mat::Type() { - int type = -1; - type = cpu_mat.type(); - if (type < 0) { - FDASSERT(false, - "While calling Mat::Type(), get negative value, which is not " - "expected!."); - } - type = type % 8; - if (type == 0) { - return FDDataType::UINT8; - } else if (type == 1) { - return FDDataType::INT8; - } else if (type == 2) { - FDASSERT(false, - "While calling Mat::Type(), get UINT16 type which is not " - "supported now."); - } else if (type == 3) { - return FDDataType::INT16; - } else if (type == 4) { - return FDDataType::INT32; - } else if (type == 5) { - return FDDataType::FP32; - } else if (type == 6) { - return FDDataType::FP64; - } else { - FDASSERT( - false, - "While calling Mat::Type(), get type = %d, which is not expected!.", - type); + int type = -1; + if (mat_type == ProcLib::FALCONCV) { +#ifdef ENABLE_FALCONCV + return FalconCVDataTypeToFD(fcv_mat.type()); +#else + FDASSERT(false, "FastDeploy didn't compile with FalconCV, but met data type with fcv::Mat."); +#endif } + return OpenCVDataTypeToFD(cpu_mat.type()); } Mat CreateFromTensor(const FDTensor& tensor) { @@ -139,5 +146,6 @@ Mat CreateFromTensor(const FDTensor& tensor) { return mat; } + } // namespace vision } // namespace fastdeploy diff --git a/fastdeploy/vision/common/processors/mat.h b/fastdeploy/vision/common/processors/mat.h index 78dbefbdf..ab1a1f35e 100644 --- a/fastdeploy/vision/common/processors/mat.h +++ b/fastdeploy/vision/common/processors/mat.h @@ -22,10 +22,14 @@ #include "opencv2/cudawarping.hpp" #endif +namespace fcv { + class Mat; +} + namespace fastdeploy { namespace vision { -enum ProcLib { DEFAULT, OPENCV}; +enum ProcLib { DEFAULT, OPENCV, FALCONCV}; enum Layout { HWC, CHW }; struct FASTDEPLOY_DECL Mat { @@ -47,13 +51,25 @@ struct FASTDEPLOY_DECL Mat { mat_type = ProcLib::OPENCV; } + inline cv::Mat* GetOpenCVMat() { + FDASSERT(mat_type == ProcLib::OPENCV, "Met non cv::Mat data structure."); + return &cpu_mat; + } + #ifdef ENABLE_FALCONCV void SetMat(const fcv::Mat& mat) { fcv_mat = mat; mat_type = Proclib::FALCONCV; } + + inline fcv::Mat* GetFalconCVMat() { + FDASSERT(mat_type == ProcLib::FALCONCV, "Met non fcv::Mat data strucure."); + return &fcv_mat; + } #endif + void* Data(); + private: int channels; int height; @@ -70,8 +86,6 @@ struct FASTDEPLOY_DECL Mat { return &cpu_mat; } - cv::Mat* GetCpuMat(); - FDDataType Type(); int Channels() const { return channels; } int Width() const { return width; } diff --git a/fastdeploy/vision/common/processors/normalize.cc b/fastdeploy/vision/common/processors/normalize.cc index a81d7a917..e3f3d894a 100644 --- a/fastdeploy/vision/common/processors/normalize.cc +++ b/fastdeploy/vision/common/processors/normalize.cc @@ -53,7 +53,7 @@ Normalize::Normalize(const std::vector& mean, } bool Normalize::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); std::vector split_im; cv::split(*im, split_im); for (int c = 0; c < im->channels(); c++) { diff --git a/fastdeploy/vision/common/processors/pad.cc b/fastdeploy/vision/common/processors/pad.cc index 5692daf22..ab6e6df1e 100644 --- a/fastdeploy/vision/common/processors/pad.cc +++ b/fastdeploy/vision/common/processors/pad.cc @@ -34,7 +34,7 @@ bool Pad::ImplByOpenCV(Mat* mat) { << std::endl; return false; } - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); cv::Scalar value; if (value_.size() == 1) { value = cv::Scalar(value_[0]); diff --git a/fastdeploy/vision/common/processors/pad_to_size.cc b/fastdeploy/vision/common/processors/pad_to_size.cc index 8a446ad3a..290505df1 100644 --- a/fastdeploy/vision/common/processors/pad_to_size.cc +++ b/fastdeploy/vision/common/processors/pad_to_size.cc @@ -56,7 +56,7 @@ bool PadToSize::ImplByOpenCV(Mat* mat) { return true; } - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); cv::Scalar value; if (value_.size() == 1) { value = cv::Scalar(value_[0]); diff --git a/fastdeploy/vision/common/processors/resize.cc b/fastdeploy/vision/common/processors/resize.cc index 73d5e8887..44e27a22a 100644 --- a/fastdeploy/vision/common/processors/resize.cc +++ b/fastdeploy/vision/common/processors/resize.cc @@ -22,7 +22,7 @@ bool Resize::ImplByOpenCV(Mat* mat) { FDERROR << "Resize: The format of input is not HWC." << std::endl; return false; } - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); int origin_w = im->cols; int origin_h = im->rows; if (width_ > 0 && height_ > 0) { diff --git a/fastdeploy/vision/common/processors/resize_by_long.cc b/fastdeploy/vision/common/processors/resize_by_long.cc index 928060814..20edca413 100644 --- a/fastdeploy/vision/common/processors/resize_by_long.cc +++ b/fastdeploy/vision/common/processors/resize_by_long.cc @@ -18,7 +18,7 @@ namespace fastdeploy { namespace vision { bool ResizeByLong::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); int origin_w = im->cols; int origin_h = im->rows; double scale = GenerateScale(origin_w, origin_h); diff --git a/fastdeploy/vision/common/processors/resize_by_short.cc b/fastdeploy/vision/common/processors/resize_by_short.cc index fa2b0442e..0c48a7e18 100644 --- a/fastdeploy/vision/common/processors/resize_by_short.cc +++ b/fastdeploy/vision/common/processors/resize_by_short.cc @@ -18,7 +18,7 @@ namespace fastdeploy { namespace vision { bool ResizeByShort::ImplByOpenCV(Mat* mat) { - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); int origin_w = im->cols; int origin_h = im->rows; double scale = GenerateScale(origin_w, origin_h); diff --git a/fastdeploy/vision/common/processors/stride_pad.cc b/fastdeploy/vision/common/processors/stride_pad.cc index c9a62ad64..50e3fd660 100644 --- a/fastdeploy/vision/common/processors/stride_pad.cc +++ b/fastdeploy/vision/common/processors/stride_pad.cc @@ -45,7 +45,7 @@ bool StridePad::ImplByOpenCV(Mat* mat) { if (pad_h == 0 && pad_w == 0) { return true; } - cv::Mat* im = mat->GetCpuMat(); + cv::Mat* im = mat->GetOpenCVMat(); cv::Scalar value; if (value_.size() == 1) { value = cv::Scalar(value_[0]); diff --git a/fastdeploy/vision/common/processors/utils.cc b/fastdeploy/vision/common/processors/utils.cc new file mode 100644 index 000000000..d291f7812 --- /dev/null +++ b/fastdeploy/vision/common/processors/utils.cc @@ -0,0 +1,138 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "fastdeploy/vision/common/processors/utils.h" + +namespace fastdeploy { +namespace vision { + +FDDataType OpenCVDataTypeToFD(int type) { + type = type % 8; + if (type == 0) { + return FDDataType::UINT8; + } else if (type == 1) { + return FDDataType::INT8; + } else if (type == 2) { + FDASSERT(false, + "While calling OpenCVDataTypeToFD(), get UINT16 type which is not " + "supported now."); + } else if (type == 3) { + return FDDataType::INT16; + } else if (type == 4) { + return FDDataType::INT32; + } else if (type == 5) { + return FDDataType::FP32; + } else if (type == 6) { + return FDDataType::FP64; + } else { + FDASSERT(false, "While calling OpenCVDataTypeToFD(), get type = %d, which is not expected.", type); + } +} + +#ifdef ENABLE_FALCONCV +FDDataType FalconCVDataTypeToFD(fcv::FCVImageType type) { + if (type == fcv::FCVImageType::GRAY_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PACKAGE_BGR_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PACKAGE_RGB_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PACKAGE_BGR_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PACKAGE_RGB_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PLANAR_BGR_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PLANAR_RGB_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PLANAR_BGRA_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PLANAR_RGBA_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PLANAR_BGR_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PLANAR_RGB_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PLANAR_BGRA_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PLANAR_RGBA_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PACKAGE_BGRA_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PACKAGE_RGBA_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PACKAGE_BGRA_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PACKAGE_RGBA_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PACKAGE_BGR565_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::PACKAGE_RGB565_U8) { + return FDDataType::UINT8; + } else if (type == fcv::FCVImageType::GRAY_S32) { + return FDDataType::INT32; + } else if (type == fcv::FCVImageType::GRAY_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PACKAGE_BGR_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PACKAGE_RGB_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PACKAGE_BGR_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PACKAGE_RGB_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PACKAGE_BGRA_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PACKAGE_RGBA_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PACKAGE_BGRA_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::PACKAGE_RGBA_F32) { + return FDDataType::FP32; + } else if (type == fcv::FCVImageType::GRAY_F64) { + return FDDataType::FP64; + } + FDASSERT(false, "While calling FalconDataTypeToFD(), get unexpected type:" + std::to_string(int(type)) + "."); + return FDDataType::UNKNOWN; +} + +fcv::FCVImageType CreateFalconDataCVType(FDDataType type, int channel) { + FDASSERT(channel == 1 || channel == 3 || channel == 4, + "Only support channel be 1/3/4 in Falcon."); + if (type == FDDataType::UINT8) { + if (channel == 1) { + return fcv::FCVImageType::GRAY_U8; + } else if (channel == 3) { + return fcv::FCVImageType::PACKAGE_BGR_U8; + } else { + return fcv::FCVImageType::PACKAGE_BGRA_U8; + } + } else if (type == FDDataType::FP32) { + if (channel == 1) { + return fcv::FCVImageType::GRAY_F32; + } else if (channel == 3) { + return fcv::FCVImageType::PACKAGE_BGR_F32; + } else { + return fcv::FCVImageType::PACKAGE_BGRA_F32; + } + } + FDASSERT(false, "Data type of " + Str(type) + " is not supported."); + return fcv::FCVImageType::PACKAGE_BGR_F32; +} +#endif + + + +} // namespace vision +} // namespace fastdeploy diff --git a/fastdeploy/vision/common/processors/utils.h b/fastdeploy/vision/common/processors/utils.h new file mode 100644 index 000000000..c6b6eb5ad --- /dev/null +++ b/fastdeploy/vision/common/processors/utils.h @@ -0,0 +1,34 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "fastdeploy/utils/utils.h" +#include "fastdeploy/core/fd_tensor.h" + +namespace fastdeploy { +namespace vision { + +// Convert data type of opencv to FDDataType +FDDataType OpenCVDataTypeToFD(int type); + +#ifdef ENABLE_FALCONCV +// Convert data type of falconcv to FDDataType +FDDataType FalconCVDataTypeToFD(fcv::FCVImageType type); +// Create data type of falconcv by FDDataType +fcv::FCVImageType CreateFalconCVDataType(FDDataType type, int channel = 1); +#endif + +} // namespace vision +} // namespace fastdeploy diff --git a/fastdeploy/vision/matting/contrib/modnet.cc b/fastdeploy/vision/matting/contrib/modnet.cc index a52d9b1e8..06c1ab52f 100644 --- a/fastdeploy/vision/matting/contrib/modnet.cc +++ b/fastdeploy/vision/matting/contrib/modnet.cc @@ -118,7 +118,7 @@ bool MODNet::Postprocess( int numel = ipt_h * ipt_w; int nbytes = numel * sizeof(float); result->Resize(numel); - std::memcpy(result->alpha.data(), alpha_resized.GetCpuMat()->data, nbytes); + std::memcpy(result->alpha.data(), alpha_resized.GetOpenCVMat()->data, nbytes); return true; } @@ -151,4 +151,4 @@ bool MODNet::Predict(cv::Mat* im, MattingResult* result) { } // namespace matting } // namespace vision -} // namespace fastdeploy \ No newline at end of file +} // namespace fastdeploy diff --git a/fastdeploy/vision/matting/ppmatting/ppmatting.cc b/fastdeploy/vision/matting/ppmatting/ppmatting.cc index a11e220b4..33ac11b58 100644 --- a/fastdeploy/vision/matting/ppmatting/ppmatting.cc +++ b/fastdeploy/vision/matting/ppmatting/ppmatting.cc @@ -196,7 +196,7 @@ bool PPMatting::Postprocess( int numel = iter_ipt->second[0] * iter_ipt->second[1]; int nbytes = numel * sizeof(float); result->Resize(numel); - std::memcpy(result->alpha.data(), mat.GetCpuMat()->data, nbytes); + std::memcpy(result->alpha.data(), mat.GetOpenCVMat()->data, nbytes); return true; }