Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #56 (Another function call inside ROS callback function might not be sequential) #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 27 additions & 34 deletions src/node_detectnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,6 @@ void info_callback()
}


// publish overlay image
bool publish_overlay( detectNet::Detection* detections, int numDetections )
{
// get the image dimensions
const uint32_t width = input_cvt->GetWidth();
const uint32_t height = input_cvt->GetHeight();

// assure correct image size
if( !overlay_cvt->Resize(width, height, imageConverter::ROSOutputFormat) )
return false;

// generate the overlay
if( !net->Overlay(input_cvt->ImageGPU(), overlay_cvt->ImageGPU(), width, height,
imageConverter::InternalFormat, detections, numDetections, overlay_flags) )
{
return false;
}

// populate the message
sensor_msgs::Image msg;

if( !overlay_cvt->Convert(msg, imageConverter::ROSOutputFormat) )
return false;

// populate timestamp in header field
msg.header.stamp = ROS_TIME_NOW();

// publish the message
overlay_pub->publish(msg);
ROS_DEBUG("publishing %ux%u overlay image", width, height);
}


// input image subscriber callback
void img_callback( const sensor_msgs::ImageConstPtr input )
{
Expand Down Expand Up @@ -153,7 +120,33 @@ void img_callback( const sensor_msgs::ImageConstPtr input )

// generate the overlay (if there are subscribers)
if( ROS_NUM_SUBSCRIBERS(overlay_pub) > 0 )
publish_overlay(detections, numDetections);
{
// get the image dimensions
const uint32_t width = input_cvt->GetWidth();
const uint32_t height = input_cvt->GetHeight();

// assure correct image size
if( !overlay_cvt->Resize(width, height, imageConverter::ROSOutputFormat) )
return;

// generate the overlay
if( !net->Overlay(input_cvt->ImageGPU(), overlay_cvt->ImageGPU(), width, height,
imageConverter::InternalFormat, detections, numDetections, overlay_flags) )
return;

// populate the message
sensor_msgs::Image msg;

if( !overlay_cvt->Convert(msg, imageConverter::ROSOutputFormat) )
return;

// populate timestamp in header field
msg.header.stamp = ROS_TIME_NOW();

// publish the message
overlay_pub->publish(msg);
ROS_DEBUG("publishing %ux%u overlay image", width, height);
}
}


Expand Down