@@ -148,7 +148,6 @@ FusionNode<Msg3D, Msg2D, ExportObj>::FusionNode(
148
148
// 2d detection status initialization
149
149
det2d_list_.resize (rois_number_);
150
150
for (std::size_t roi_i = 0 ; roi_i < rois_number_; ++roi_i) {
151
- det2d_list_.at (roi_i).mtx_ptr = std::make_unique<std::mutex>();
152
151
det2d_list_.at (roi_i).id = roi_i;
153
152
det2d_list_.at (roi_i).project_to_unrectified_image =
154
153
point_project_to_unrectified_image.at (roi_i);
@@ -261,13 +260,16 @@ void FusionNode<Msg3D, Msg2D, ExportObj>::subCallback(
261
260
// PROCESS: if the main message is remained (and roi is not collected all) publish the main
262
261
// message may processed partially with arrived 2d rois
263
262
stop_watch_ptr_->toc (" processing_time" , true );
264
- std::lock_guard<std::mutex> lock_det3d (mutex_det3d_msg_);
265
263
exportProcess ();
266
264
267
265
// reset flags
268
- clearAllDet2dFlags ();
266
+ for (auto & det2d : det2d_list_) {
267
+ det2d.is_fused = false ;
268
+ }
269
269
}
270
270
271
+ std::lock_guard<std::mutex> lock (mutex_cached_msgs_);
272
+
271
273
// TIMING: reset timer to the timeout time
272
274
auto period = std::chrono::duration_cast<std::chrono::nanoseconds>(
273
275
std::chrono::duration<double , std::milli>(timeout_ms_));
@@ -291,7 +293,6 @@ void FusionNode<Msg3D, Msg2D, ExportObj>::subCallback(
291
293
// for loop for each roi
292
294
for (auto & det2d : det2d_list_) {
293
295
const auto roi_i = det2d.id ;
294
- std::lock_guard<std::mutex> lock_det2d (*(det2d.mtx_ptr ));
295
296
296
297
// check camera info
297
298
if (det2d.camera_projector_ptr == nullptr ) {
@@ -333,7 +334,7 @@ void FusionNode<Msg3D, Msg2D, ExportObj>::subCallback(
333
334
334
335
fuseOnSingleImage (*det3d_msg, det2d, *(det2d_msgs[matched_stamp]), *output_msg);
335
336
det2d_msgs.erase (matched_stamp);
336
- setDet2dFused ( det2d) ;
337
+ det2d. is_fused = true ;
337
338
338
339
// add timestamp interval for debug
339
340
if (debug_publisher_) {
@@ -348,15 +349,16 @@ void FusionNode<Msg3D, Msg2D, ExportObj>::subCallback(
348
349
}
349
350
350
351
// PROCESS: check if the fused message is ready to publish
351
- std::lock_guard<std::mutex> lock_det3d (mutex_det3d_msg_);
352
352
cached_det3d_msg_timestamp_ = timestamp_nsec;
353
353
cached_det3d_msg_ptr_ = output_msg;
354
354
if (checkAllDet2dFused ()) {
355
355
// if all camera fused, postprocess and publish the main message
356
356
exportProcess ();
357
357
358
358
// reset flags
359
- clearAllDet2dFlags ();
359
+ for (auto & det2d : det2d_list_) {
360
+ det2d.is_fused = false ;
361
+ }
360
362
} else {
361
363
// if all of rois are not collected, publish the old Msg(if exists) and cache the
362
364
// current Msg
@@ -374,14 +376,11 @@ void FusionNode<Msg3D, Msg2D, ExportObj>::roiCallback(
374
376
stop_watch_ptr_->toc (" processing_time" , true );
375
377
376
378
auto & det2d = det2d_list_.at (roi_i);
377
- std::lock_guard<std::mutex> lock_det2d (*(det2d.mtx_ptr ));
378
379
379
380
int64_t timestamp_nsec =
380
381
(*det2d_msg).header .stamp .sec * static_cast <int64_t >(1e9 ) + (*det2d_msg).header .stamp .nanosec ;
381
382
// if cached Msg exist, try to match
382
383
if (cached_det3d_msg_ptr_ != nullptr ) {
383
- std::lock_guard<std::mutex> lock_det3d (mutex_det3d_msg_);
384
-
385
384
int64_t new_stamp =
386
385
cached_det3d_msg_timestamp_ + det2d.input_offset_ms * static_cast <int64_t >(1e6 );
387
386
int64_t interval = abs (timestamp_nsec - new_stamp);
@@ -401,7 +400,7 @@ void FusionNode<Msg3D, Msg2D, ExportObj>::roiCallback(
401
400
}
402
401
// PROCESS: fuse the main message with the roi message
403
402
fuseOnSingleImage (*(cached_det3d_msg_ptr_), det2d, *det2d_msg, *(cached_det3d_msg_ptr_));
404
- setDet2dFused ( det2d) ;
403
+ det2d. is_fused = true ;
405
404
406
405
if (debug_publisher_) {
407
406
double timestamp_interval_ms = (timestamp_nsec - cached_det3d_msg_timestamp_) / 1e6 ;
@@ -416,7 +415,9 @@ void FusionNode<Msg3D, Msg2D, ExportObj>::roiCallback(
416
415
if (checkAllDet2dFused ()) {
417
416
exportProcess ();
418
417
// reset flags
419
- clearAllDet2dFlags ();
418
+ for (auto & det2d : det2d_list_) {
419
+ det2d.is_fused = false ;
420
+ }
420
421
}
421
422
processing_time_ms = processing_time_ms + stop_watch_ptr_->toc (" processing_time" , true );
422
423
return ;
@@ -440,17 +441,19 @@ void FusionNode<Msg3D, Msg2D, ExportObj>::timer_callback()
440
441
441
442
using std::chrono_literals::operator " " ms;
442
443
timer_->cancel ();
443
- if (mutex_det3d_msg_ .try_lock ()) {
444
+ if (mutex_cached_msgs_ .try_lock ()) {
444
445
// PROCESS: if timeout, postprocess cached msg
445
446
if (cached_det3d_msg_ptr_ != nullptr ) {
446
447
stop_watch_ptr_->toc (" processing_time" , true );
447
448
exportProcess ();
448
449
}
449
450
450
451
// reset flags whether the message is fused or not
451
- clearAllDet2dFlags ();
452
+ for (auto & det2d : det2d_list_) {
453
+ det2d.is_fused = false ;
454
+ }
452
455
453
- mutex_det3d_msg_ .unlock ();
456
+ mutex_cached_msgs_ .unlock ();
454
457
} else {
455
458
// TIMING: retry the process after 10ms
456
459
try {
0 commit comments