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

Added support for YUV422 and RGB8 #141

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added CATKIN_IGNORE
Empty file.
22 changes: 20 additions & 2 deletions pointgrey_camera_driver/cfg/PointGrey.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,29 @@ codings = gen.enum([gen.const("Mono8", str_t, "mono8", ""),
gen.const("Mono16", str_t, "mono16", ""),
gen.const("Raw8", str_t, "raw8", ""),
gen.const("Raw16", str_t, "raw16", ""),
gen.const("RGB8", str_t, "rgb8", "")],
gen.const("RGB8", str_t, "rgb8", ""),
gen.const("YUV422", str_t, "yuv422", "")],
"Format7 color coding methods")

gen.add("format7_color_coding", str_t, SensorLevels.RECONFIGURE_STOP, "Color coding (only for Format7 modes)", "raw8", edit_method = codings)


# Color processing http://www.ptgrey.com/KB/10141
gen.add("color_processing", bool_t, SensorLevels.RECONFIGURE_RUNNING, "Enable color processing.", False)
color_processing_algos = gen.enum([gen.const("DEFAULT", str_t, "DEFAULT", ""),
gen.const("NO", str_t, "NO_COLOR_PROCESSING", ""),
gen.const("NEAREST_NEIGHBOR", str_t, "NEAREST_NEIGHBOR", ""),
gen.const("EDGE_SENSING", str_t, "EDGE_SENSING", ""),
gen.const("HQ_LINEAR", str_t, "HQ_LINEAR", ""),
gen.const("RIGOROUS", str_t, "RIGOROUS", ""),
gen.const("IPP", str_t, "IPP", ""),
gen.const("DIRECTIONAL_FILTER", str_t, "DIRECTIONAL_FILTER", ""),
gen.const("WEIGHTED_DIRECTIONAL_FILTER", str_t, "WEIGHTED_DIRECTIONAL_FILTER", "")],
"Color processing algorithms")

gen.add("color_processing_algo", str_t, SensorLevels.RECONFIGURE_RUNNING, "Color processing algorithms", "DEFAULT", edit_method = color_processing_algos)


# Trigger parameters
gen.add("enable_trigger", bool_t, SensorLevels.RECONFIGURE_RUNNING, "Enable the external triggering mode.", False)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ class PointGreyCamera
/// If true, camera is currently running in color mode, otherwise camera is running in mono mode
bool isColor_;

bool color_processing_;
FlyCapture2::ColorProcessingAlgorithm color_processing_algo_;

// For GigE cameras:
/// If true, GigE packet size is automatically determined, otherwise packet_size_ is used:
bool auto_packet_size_;
Expand Down Expand Up @@ -241,6 +244,17 @@ class PointGreyCamera
*/
bool getFormat7PixelFormatFromString(std::string &sformat, FlyCapture2::PixelFormat &fmt7PixFmt);

/*!
* \brief Converts the dynamic_reconfigure string type into a FlyCapture2::ColorProcessingAlgorithm
*
* This function will convert the string input from dynamic_reconfigure into the proper datatype for use with FlyCapture enum.
* \param cproc input Color Processing Algorithm.
* \param algo_out FlyCapture2::ColorProcessingAlgorithm, will be changed to either the corresponding type as cproc, or to the most compatible type.
*
* \return Returns true when the configuration could be applied without modification.
*/
bool getColorProcessingAlgoFromString(std::string &cproc, FlyCapture2::ColorProcessingAlgorithm &algo_out);

bool setProperty(const FlyCapture2::PropertyType &type, const bool &autoSet, unsigned int &valueA, unsigned int &valueB);

/*!
Expand Down
153 changes: 133 additions & 20 deletions pointgrey_camera_driver/src/PointGreyCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ bool PointGreyCamera::setNewConfiguration(pointgrey_camera_driver::PointGreyConf
PointGreyCamera::connect();
}

// Activate mutex to prevent us from grabbing images during this time
boost::mutex::scoped_lock scopedLock(mutex_);

// return true if we can set values as desired.
bool retVal = true;

color_processing_=config.color_processing;
retVal &= PointGreyCamera::getColorProcessingAlgoFromString(config.color_processing_algo,color_processing_algo_);

// Activate mutex to prevent us from grabbing images during this time
boost::mutex::scoped_lock scopedLock(mutex_);

// Check video mode
VideoMode vMode; // video mode desired
Mode fmt7Mode; // fmt7Mode to set
Expand All @@ -75,19 +78,33 @@ bool PointGreyCamera::setNewConfiguration(pointgrey_camera_driver::PointGreyConf
{
PixelFormat fmt7PixFmt;
PointGreyCamera::getFormat7PixelFormatFromString(config.format7_color_coding, fmt7PixFmt);
switch(fmt7PixFmt)
{
case PIXEL_FORMAT_RAW8: ROS_INFO_STREAM("Setting PIXEL_FORMAT_RAW8");break;
case PIXEL_FORMAT_RAW16: ROS_INFO_STREAM("Setting PIXEL_FORMAT_RAW16");break;
case PIXEL_FORMAT_MONO8: ROS_INFO_STREAM("Setting PIXEL_FORMAT_MONO8");break;
case PIXEL_FORMAT_MONO16: ROS_INFO_STREAM("Setting PIXEL_FORMAT_MONO16");break;
case PIXEL_FORMAT_422YUV8: ROS_INFO_STREAM("Setting PIXEL_FORMAT_422YUV8");break;
case PIXEL_FORMAT_RGB8: ROS_INFO_STREAM("Setting PIXEL_FORMAT_RGB8");break;
case PIXEL_FORMAT_BGR: ROS_INFO_STREAM("Setting PIXEL_FORMAT_BGR");break;
default: ROS_INFO_STREAM("GetDefaultOutputFormat "<<std::hex<<fmt7PixFmt);
}
// Oh no, these all need to be converted into uints, so my pass by reference trick doesn't work
uint16_t uwidth = (uint16_t)config.format7_roi_width;
uint16_t uheight = (uint16_t)config.format7_roi_height;
uint16_t uoffsetx = (uint16_t)config.format7_x_offset;
uint16_t uoffsety = (uint16_t)config.format7_y_offset;
retVal &= PointGreyCamera::setFormat7(fmt7Mode, fmt7PixFmt, uwidth, uheight, uoffsetx, uoffsety);
ROS_INFO_STREAM("Setting VIDEOMODE_FORMAT7 MODE "<<fmt7Mode);

config.format7_roi_width = uwidth;
config.format7_roi_height = uheight;
config.format7_x_offset = uoffsetx;
config.format7_y_offset = uoffsety;
}
else
{
ROS_INFO_STREAM("Setting VIDEOMODE "<<vMode);
// Need to set just videoMode
PointGreyCamera::setVideoMode(vMode);
}
Expand Down Expand Up @@ -323,6 +340,67 @@ bool PointGreyCamera::setFormat7(FlyCapture2::Mode &fmt7Mode, FlyCapture2::Pixel
return retVal;
}

bool PointGreyCamera::getColorProcessingAlgoFromString(std::string &cproc, FlyCapture2::ColorProcessingAlgorithm &algo_out)
{
// return true if we can set values as desired.
bool retVal = true;

// Get camera info to check if color or black and white chameleon
CameraInfo cInfo;
Error error = cam_.GetCameraInfo(&cInfo);
PointGreyCamera::handleError("PointGreyCamera::getVideoModeFromString Failed to get camera info.", error);

if(cproc.compare("DEFAULT") == 0)
{
algo_out = DEFAULT;
}
else if(cproc.compare("NO_COLOR_PROCESSING") == 0)
{
algo_out = NO_COLOR_PROCESSING;
color_processing_ = false;
}
else if(cproc.compare("NEAREST_NEIGHBOR") == 0)
{
algo_out = NEAREST_NEIGHBOR;

}
else if(cproc.compare("EDGE_SENSING") == 0)
{
algo_out = EDGE_SENSING;
}
else if(cproc.compare("HQ_LINEAR") == 0)
{
algo_out = HQ_LINEAR;
}
else if(cproc.compare("RIGOROUS") == 0)
{
algo_out = RIGOROUS;
}
else if(cproc.compare("IPP") == 0)
{
algo_out = IPP;
}
else if(cproc.compare("DIRECTIONAL_FILTER") == 0)
{
algo_out = DIRECTIONAL_FILTER;
}
else if(cproc.compare("WEIGHTED_DIRECTIONAL_FILTER") == 0)
{
algo_out = WEIGHTED_DIRECTIONAL_FILTER;
}
else if(cproc.compare("COLOR_PROCESSING_ALGORITHM_FORCE_32BITS") == 0)
{
algo_out = COLOR_PROCESSING_ALGORITHM_FORCE_32BITS;
}
else // Something not supported was asked of us, drop down into the most compatible mode
{
algo_out = DEFAULT;
retVal &= false;
}

return retVal;
}

bool PointGreyCamera::getVideoModeFromString(std::string &vmode, FlyCapture2::VideoMode &vmode_out, FlyCapture2::Mode &fmt7Mode)
{
// return true if we can set values as desired.
Expand Down Expand Up @@ -436,8 +514,13 @@ bool PointGreyCamera::getFormat7PixelFormatFromString(std::string &sformat, FlyC
{
fmt7PixFmt = PIXEL_FORMAT_MONO16;
}
else if(sformat.compare("rgb8") == 0){
fmt7PixFmt = PIXEL_FORMAT_RGB;
else if(sformat.compare("rgb8") == 0)
{
fmt7PixFmt = PIXEL_FORMAT_RGB8;
}
else if(sformat.compare("yuv422") == 0)
{
fmt7PixFmt = PIXEL_FORMAT_422YUV8;
}
else
{
Expand Down Expand Up @@ -983,11 +1066,16 @@ void PointGreyCamera::grabImage(sensor_msgs::Image &image, const std::string &fr
{
// Make a FlyCapture2::Image to hold the buffer returned by the camera.
Image rawImage;
Image convertedImage;
bool isImageConverted = false;
// Retrieve an image
Error error = cam_.RetrieveBuffer(&rawImage);
PointGreyCamera::handleError("PointGreyCamera::grabImage Failed to retrieve buffer", error);
metadata_ = rawImage.GetMetadata();




// Set header timestamp as embedded for now
TimeStamp embeddedTime = rawImage.GetTimeStamp();
image.header.stamp.sec = embeddedTime.seconds;
Expand All @@ -996,9 +1084,13 @@ void PointGreyCamera::grabImage(sensor_msgs::Image &image, const std::string &fr
// Check the bits per pixel.
uint8_t bitsPerPixel = rawImage.GetBitsPerPixel();

// Set the image encoding
// Set the default image encoding
std::string imageEncoding = sensor_msgs::image_encodings::MONO8;

//Get image encoding details
BayerTileFormat bayer_format = rawImage.GetBayerTileFormat();
PixelFormat p_fmt=rawImage.GetPixelFormat();

if(isColor_ && bayer_format != NONE)
{
if(bitsPerPixel == 16)
Expand All @@ -1018,6 +1110,14 @@ void PointGreyCamera::grabImage(sensor_msgs::Image &image, const std::string &fr
imageEncoding = sensor_msgs::image_encodings::BAYER_BGGR16;
break;
}
if (color_processing_)
{
//http://www.ptgrey.com/KB/10141
rawImage.SetColorProcessing( color_processing_algo_ );
Error convertError = rawImage.Convert( PIXEL_FORMAT_RGB8, &convertedImage );
if(convertError == PGRERROR_OK)
isImageConverted = true;
}
}
else
{
Expand All @@ -1036,25 +1136,38 @@ void PointGreyCamera::grabImage(sensor_msgs::Image &image, const std::string &fr
imageEncoding = sensor_msgs::image_encodings::BAYER_BGGR8;
break;
}
if (color_processing_)
{
//http://www.ptgrey.com/KB/10141
rawImage.SetColorProcessing( color_processing_algo_ );
Error convertError = rawImage.Convert( PIXEL_FORMAT_RGB8, &convertedImage );
if(convertError == PGRERROR_OK)
isImageConverted = true;
}
}
}
else // Mono camera or in pixel binned mode.
else
{
if(bitsPerPixel == 16)
switch(p_fmt)
{
imageEncoding = sensor_msgs::image_encodings::MONO16;
}
else if(bitsPerPixel==24)
{
imageEncoding = sensor_msgs::image_encodings::RGB8;
}
else
{
imageEncoding = sensor_msgs::image_encodings::MONO8;
}
}

fillImage(image, imageEncoding, rawImage.GetRows(), rawImage.GetCols(), rawImage.GetStride(), rawImage.GetData());
case PIXEL_FORMAT_422YUV8:
imageEncoding = sensor_msgs::image_encodings::YUV422;break;
case PIXEL_FORMAT_RGB8:
imageEncoding = sensor_msgs::image_encodings::RGB8;break;
case PIXEL_FORMAT_MONO8:
imageEncoding = sensor_msgs::image_encodings::MONO8;break;
case PIXEL_FORMAT_MONO16:
imageEncoding = sensor_msgs::image_encodings::MONO16;break;
default:
ROS_WARN_STREAM(" imageEncoding not supported (defaults to MONO8)");
imageEncoding = sensor_msgs::image_encodings::MONO8;
}
}
if (isImageConverted)
fillImage(image, sensor_msgs::image_encodings::RGB8, convertedImage.GetRows(), convertedImage.GetCols(), convertedImage.GetStride(), convertedImage.GetData());
else
fillImage(image, imageEncoding, rawImage.GetRows(), rawImage.GetCols(), rawImage.GetStride(), rawImage.GetData());
image.header.frame_id = frame_id;
}
else if(cam_.IsConnected())
Expand Down