@@ -72,7 +72,7 @@ analog to the ``WARP_INVERSE_MAP`` flag.
72
72
.AddOptionalArg(" pixel_origin" , R"doc( Pixel origin. Possible values: "corner", "center".
73
73
74
74
Determines the meaning of (0, 0) coordinates - "corner" places the origin at the top-left corner of
75
- the top-left pixel (like in OpenGL); "center" places (0, 0) in the center of
75
+ the top-left pixel (like in OpenGL); "center" places (0, 0) in the center of
76
76
the top-left pixel (like in OpenCV).))doc" , " corner" )
77
77
.AddOptionalArg<float >(" fill_value" ,
78
78
" Value used to fill areas that are outside the source image when the "
@@ -91,8 +91,8 @@ class WarpPerspective : public nvcvop::NVCVSequenceOperator<StatelessOperator> {
91
91
: nvcvop::NVCVSequenceOperator<StatelessOperator>(spec),
92
92
border_mode_(nvcvop::GetBorderMode(spec.GetArgument<std::string>(" border_mode" ))),
93
93
interp_type_(nvcvop::GetInterpolationType(spec.GetArgument<DALIInterpType>(" interp_type" ))),
94
- inverse_map_(spec.GetArgument<bool >(" inverse_map" )),
95
94
fill_value_arg_(spec.GetArgument<std::vector<float >>(" fill_value" )),
95
+ inverse_map_(spec.GetArgument<bool >(" inverse_map" )),
96
96
ocv_pixel_(OCVCompatArg(spec.GetArgument<std::string>(" pixel_origin" ))) {
97
97
matrix_data_.SetContiguity (BatchContiguity::Contiguous);
98
98
}
@@ -108,16 +108,16 @@ class WarpPerspective : public nvcvop::NVCVSequenceOperator<StatelessOperator> {
108
108
float4 GetFillValue (int channels) const {
109
109
if (fill_value_arg_.size () > 1 ) {
110
110
if (channels > 0 ) {
111
- if (channels == static_cast <int >(fill_value_arg_.size ())) {
112
- float4 fill_value{0 , 0 , 0 , 0 };
113
- memcpy (&fill_value, fill_value_arg_.data (), sizeof (decltype (fill_value)));
114
- return fill_value;
115
- } else {
111
+ if (channels != static_cast <int >(fill_value_arg_.size ())) {
116
112
DALI_FAIL (make_string (
117
113
" Number of values provided as a fill_value should match the number of channels.\n "
118
114
" Number of channels: " ,
119
115
channels, " . Number of values provided: " , fill_value_arg_.size (), " ." ));
120
116
}
117
+ assert (channels <= 4 );
118
+ float4 fill_value{0 , 0 , 0 , 0 };
119
+ memcpy (&fill_value, fill_value_arg_.data (), channels * sizeof (float ));
120
+ return fill_value;
121
121
} else {
122
122
DALI_FAIL (" Only scalar fill_value can be provided when processing data in planar layout." );
123
123
}
@@ -162,6 +162,8 @@ class WarpPerspective : public nvcvop::NVCVSequenceOperator<StatelessOperator> {
162
162
163
163
auto output_shape = input_shape;
164
164
int channels = (input_layout.find (' C' ) != -1 ) ? input_shape[0 ][input_layout.find (' C' )] : -1 ;
165
+ if (channels > 4 )
166
+ DALI_FAIL (" Images with more than 4 channels are not supported." );
165
167
fill_value_ = GetFillValue (channels);
166
168
if (size_arg_.HasExplicitValue ()) {
167
169
size_arg_.Acquire (spec_, ws, input_shape.size (), TensorShape<1 >(2 ));
@@ -226,14 +228,14 @@ class WarpPerspective : public nvcvop::NVCVSequenceOperator<StatelessOperator> {
226
228
ArgValue<float , 2 > matrix_arg_{" matrix" , spec_};
227
229
ArgValue<float , 1 > size_arg_{" size" , spec_};
228
230
int op_batch_size_ = 0 ;
229
- NVCVBorderType border_mode_{NVCV_BORDER_CONSTANT};
230
- NVCVInterpolationType interp_type_{NVCV_INTERP_NEAREST};
231
- bool inverse_map_{false };
231
+ NVCVBorderType border_mode_ = NVCV_BORDER_CONSTANT;
232
+ NVCVInterpolationType interp_type_ = NVCV_INTERP_NEAREST;
232
233
std::vector<float > fill_value_arg_{0 , 0 , 0 , 0 };
233
- float4 fill_value_{0 , 0 , 0 , 0 };
234
+ float4 fill_value_;
235
+ bool inverse_map_ = false ;
234
236
bool ocv_pixel_ = true ;
235
- std::optional<cvcuda::WarpPerspective> warp_perspective_{} ;
236
- TensorList<GPUBackend> matrix_data_{} ;
237
+ std::optional<cvcuda::WarpPerspective> warp_perspective_;
238
+ TensorList<GPUBackend> matrix_data_;
237
239
};
238
240
239
241
DALI_REGISTER_OPERATOR (experimental__WarpPerspective, WarpPerspective, GPU);
0 commit comments