@@ -132,7 +132,7 @@ GstFlowReturn ObjectsPreprocessing::preprocessing(
132132 cudaCheckError ()
133133 frames_map[(size_t ) inbuf].insert ({frame_meta->batch_id , (void *) copy_frame});
134134
135- int left_pencil_bbox =0 , top_pencil_bbox =0 , row_height=0 ;
135+ int left =0 , top =0 , row_height=0 ;
136136 int tmp_i = 0 ;
137137 int tmp_j = 0 ;
138138 for (object_meta_list = frame_meta->obj_meta_list ; object_meta_list != nullptr ; object_meta_list = object_meta_list -> next)
@@ -167,7 +167,7 @@ GstFlowReturn ObjectsPreprocessing::preprocessing(
167167 NppiSize dst_image_size = {.width = rect_params.width , .height = rect_params.height };
168168
169169 cudaCrop (
170- (Npp8u *) ref_frame ,
170+ (Npp8u *) copy_frame ,
171171 src_image_size,
172172 crop_rect,
173173 (Npp8u*) preproc_object->getDataPtr (),
@@ -186,30 +186,35 @@ GstFlowReturn ObjectsPreprocessing::preprocessing(
186186
187187
188188 NppiRect crop_rect = {.x =0 , .y =0 , .width = preproc_object->getWidth (), .height = preproc_object->getHeight ()};
189- NppiSize clc_pencil_image_size = {.width = preproc_object->getWidth (), .height = preproc_object->getHeight ()};
189+ NppiSize clc_image_size = {.width = preproc_object->getWidth (), .height = preproc_object->getHeight ()};
190+
191+ if (left + preproc_object->getWidth () > ref_frame_size.width )
192+ {
193+ left = 0 ;
194+ top += row_height;
195+ row_height = 0 ;
196+ if (top >= ref_frame_size.height ) throw std::runtime_error (" There is no place on frame to put object image." );
197+ }
198+ if (top + preproc_object->getHeight () > ref_frame_size.height )
199+ throw std::runtime_error (" There is no place on frame to put object image." );
200+ if (preproc_object->getHeight () > row_height) row_height = preproc_object->getHeight ();
201+
190202 cudaCrop (
191203 (Npp8u *) preproc_object->getDataPtr (),
192- clc_pencil_image_size ,
204+ clc_image_size ,
193205 crop_rect,
194206 ref_frame,
195207 ref_frame_size,
196- left_pencil_bbox,
197- top_pencil_bbox);
208+ left,
209+ top
210+ );
198211
199- object_meta->rect_params .left = (float ) left_pencil_bbox ;
200- object_meta->rect_params .top = (float ) top_pencil_bbox ;
212+ object_meta->rect_params .left = (float ) left ;
213+ object_meta->rect_params .top = (float ) top ;
201214 object_meta->rect_params .width = (float ) preproc_object->getWidth ();
202215 object_meta->rect_params .height = (float ) preproc_object->getHeight ();
203216
204- left_pencil_bbox += preproc_object->getWidth () ;
205- if (preproc_object->getHeight () > row_height) row_height = preproc_object->getHeight ();
206- if (left_pencil_bbox >= ref_frame_size.width )
207- {
208- left_pencil_bbox = 0 ;
209- top_pencil_bbox += row_height;
210- row_height = 0 ;
211- if (top_pencil_bbox >= ref_frame_size.height ) throw std::runtime_error (" There is no place on image to put pencil." );
212- }
217+ left += preproc_object->getWidth () ;
213218 if (preproc_object!=nullptr ) delete preproc_object;
214219 }
215220 }
@@ -227,7 +232,7 @@ GstFlowReturn ObjectsPreprocessing::preprocessing(
227232 }
228233}
229234
230- GstFlowReturn ObjectsPreprocessing::restore_frame (GstBuffer* gst_buffer, int batchID ){
235+ GstFlowReturn ObjectsPreprocessing::restore_frame (GstBuffer* gst_buffer){
231236
232237 GstMapInfo in_map_info;
233238 gboolean status;
0 commit comments