@@ -63,20 +63,16 @@ bool RobustVideoMatting::Preprocess(
63
63
if (resize_h != mat->Height () || resize_w != mat->Width ()) {
64
64
Resize::Run (mat, resize_w, resize_h);
65
65
}
66
- BGR2RGB::Run (mat);
67
-
68
- // Normalize
66
+ // Convert_and_permute(swap_rb=true)
69
67
std::vector<float > alpha = {1 .0f / 255 .0f , 1 .0f / 255 .0f , 1 .0f / 255 .0f };
70
68
std::vector<float > beta = {0 .0f , 0 .0f , 0 .0f };
71
- Convert::Run (mat, alpha, beta);
69
+ ConvertAndPermute::Run (mat, alpha, beta, true );
70
+
72
71
// Record output shape of preprocessed image
73
72
(*im_info)[" output_shape" ] = {mat->Height (), mat->Width ()};
74
73
75
- HWC2CHW::Run (mat);
76
- Cast::Run (mat, " float" );
77
-
78
74
mat->ShareWithTensor (output);
79
- output->shape . insert (output-> shape . begin (), 1 ); // reshape to n, h, w, c
75
+ output->ExpandDim ( 0 ); // reshape to n, h, w, c
80
76
return true ;
81
77
}
82
78
@@ -120,8 +116,6 @@ bool RobustVideoMatting::Postprocess(
120
116
121
117
// for alpha
122
118
float * alpha_ptr = static_cast <float *>(alpha.Data ());
123
- // cv::Mat alpha_zero_copy_ref(out_h, out_w, CV_32FC1, alpha_ptr);
124
- // Mat alpha_resized(alpha_zero_copy_ref); // ref-only, zero copy.
125
119
Mat alpha_resized = Mat::Create (out_h, out_w, 1 , FDDataType::FP32,
126
120
alpha_ptr); // ref-only, zero copy.
127
121
if ((out_h != in_h) || (out_w != in_w)) {
@@ -130,8 +124,6 @@ bool RobustVideoMatting::Postprocess(
130
124
131
125
// for foreground
132
126
float * fgr_ptr = static_cast <float *>(fgr.Data ());
133
- // cv::Mat fgr_zero_copy_ref(out_h, out_w, CV_32FC1, fgr_ptr);
134
- // Mat fgr_resized(fgr_zero_copy_ref); // ref-only, zero copy.
135
127
Mat fgr_resized = Mat::Create (out_h, out_w, 1 , FDDataType::FP32,
136
128
fgr_ptr); // ref-only, zero copy.
137
129
if ((out_h != in_h) || (out_w != in_w)) {
0 commit comments