15 #include "fastdeploy/core/fd_tensor.h" 16 #include "fastdeploy/vision/common/processors/proc_lib.h" 17 #include "opencv2/core/core.hpp" 24 #include <cuda_runtime_api.h> 30 enum Layout { HWC, CHW };
34 struct FASTDEPLOY_DECL
Mat {
36 explicit Mat(
const cv::Mat& mat) {
39 height = cpu_mat.rows;
41 channels = cpu_mat.channels();
42 mat_type = ProcLib::OPENCV;
46 explicit Mat(
const fcv::Mat& mat) {
49 height = fcv_mat.height();
50 width = fcv_mat.width();
51 channels = fcv_mat.channels();
52 mat_type = ProcLib::FLYCV;
56 Mat(
const Mat& mat) =
default;
57 Mat& operator=(
const Mat& mat) =
default;
60 Mat(
Mat&& other) =
default;
66 void SetMat(
const cv::Mat& mat) {
68 mat_type = ProcLib::OPENCV;
71 cv::Mat* GetOpenCVMat();
74 void SetMat(
const fcv::Mat& mat) {
76 mat_type = ProcLib::FLYCV;
78 fcv::Mat* GetFlyCVMat();
89 void SetTensor(std::shared_ptr<FDTensor>& tensor);
100 cudaStream_t stream =
nullptr;
104 std::shared_ptr<FDTensor> fd_tensor = std::make_shared<FDTensor>();
108 int Channels()
const {
return channels; }
109 int Width()
const {
return width; }
110 int Height()
const {
return height; }
111 void SetChannels(
int s) { channels = s; }
112 void SetWidth(
int w) { width = w; }
113 void SetHeight(
int h) { height = h; }
120 cudaStream_t Stream()
const {
return stream; }
121 void SetStream(cudaStream_t s) { stream = s; }
125 void ShareWithTensor(
FDTensor* tensor);
127 bool CopyToTensor(
FDTensor* tensor);
134 void PrintInfo(
const std::string& flag);
136 ProcLib mat_type = ProcLib::OPENCV;
137 Layout layout = Layout::HWC;
138 Device device = Device::CPU;
139 ProcLib proc_lib = ProcLib::DEFAULT;
149 static Mat Create(
const FDTensor& tensor, ProcLib lib);
150 static Mat Create(
int height,
int width,
int channels,
151 FDDataType type,
void* data);
152 static Mat Create(
int height,
int width,
int channels,
153 FDDataType type,
void* data, ProcLib lib);
160 FASTDEPLOY_DECL FDMat WrapMat(
const cv::Mat& image);
164 FASTDEPLOY_DECL std::vector<FDMat> WrapMat(
const std::vector<cv::Mat>& images);
166 bool CheckShapeConsistency(std::vector<Mat>* mats);
FDTensor object used to represend data matrix.
Definition: fd_tensor.h:31
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16