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 issue of input image with RGB8 encoding #30

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
69 changes: 49 additions & 20 deletions src/image_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,65 @@ bool imageConverter::Convert( const sensor_msgs::ImageConstPtr& input )
ROS_INFO("converting %ux%u %s image", input->width, input->height, input->encoding.c_str());

// confirm bgr8 encoding
if( input->encoding != sensor_msgs::image_encodings::BGR8 )
if( input->encoding == sensor_msgs::image_encodings::BGR8 )
{
ROS_ERROR("%ux%u image is in %s format, expected %s", input->width, input->height, input->encoding.c_str(), sensor_msgs::image_encodings::BGR8.c_str());
return false;
}
// confirm step size
const uint32_t input_stride = input->width * sizeof(uchar3);

// confirm step size
const uint32_t input_stride = input->width * sizeof(uchar3);
if( input->step != input_stride )
{
ROS_ERROR("%ux%u image has step size of %u bytes, expected %u bytes", input->width, input->height, input->step, input_stride);
return false;
}

if( input->step != input_stride )
{
ROS_ERROR("%ux%u image has step size of %u bytes, expected %u bytes", input->width, input->height, input->step, input_stride);
return false;
// assure memory allocation
if( !Resize(input->width, input->height) )
return false;

// copy input to shared memory
memcpy(mInputCPU, input->data.data(), input->width * input->height * sizeof(uchar3)); // note: 3 channels assumes bgr/rgb

// convert to RGBA32f format
if( CUDA_FAILED(cudaBGR8ToRGBA32((uchar3*)mInputGPU, (float4*)mOutputGPU, mWidth, mHeight)) )
{
ROS_ERROR("failed to convert %ux%u image with CUDA", mWidth, mHeight);
return false;
}

return true;
}
else if( input->encoding == sensor_msgs::image_encodings::RGB8 )
{
// confirm step size
const uint32_t input_stride = input->width * sizeof(uchar3);

// assure memory allocation
if( !Resize(input->width, input->height) )
return false;
if( input->step != input_stride )
{
ROS_ERROR("%ux%u image has step size of %u bytes, expected %u bytes", input->width, input->height, input->step, input_stride);
return false;
}

// assure memory allocation
if( !Resize(input->width, input->height) )
return false;

// copy input to shared memory
memcpy(mInputCPU, input->data.data(), input->width * input->height * sizeof(uchar3)); // note: 3 channels assumes bgr/rgb
// copy input to shared memory
memcpy(mInputCPU, input->data.data(), input->width * input->height * sizeof(uchar3)); // note: 3 channels assumes bgr/rgb

// convert to RGBA32f format
if( CUDA_FAILED(cudaBGR8ToRGBA32((uchar3*)mInputGPU, (float4*)mOutputGPU, mWidth, mHeight)) )
// convert to RGBA32f format
if( CUDA_FAILED(cudaRGB8ToRGBA32((uchar3*)mInputGPU, (float4*)mOutputGPU, mWidth, mHeight)) )
{
ROS_ERROR("failed to convert %ux%u image with CUDA", mWidth, mHeight);
return false;
}

return true;
}
else
{
ROS_ERROR("failed to convert %ux%u image with CUDA", mWidth, mHeight);
ROS_ERROR("%ux%u image is in %s format, expected %s or %s", input->width, input->height, input->encoding.c_str(), sensor_msgs::image_encodings::BGR8.c_str(), sensor_msgs::image_encodings::RGB8.c_str());
return false;
}

return true;
}


Expand Down