@@ -334,109 +334,111 @@ void SpinnakerCamera::grabImage(sensor_msgs::Image* image, const std::string& fr
334334 // std::string format(image_ptr->GetPixelFormatName());
335335 // std::printf("\033[100m format: %s \n", format.c_str());
336336
337- if (image_ptr->IsIncomplete ())
337+ // throw std::runtime_error("[SpinnakerCamera::grabImage] Image received from camera " + std::to_string(serial_) +
338+ // " is incomplete.");
339+ while (image_ptr->IsIncomplete ())
338340 {
339- throw std::runtime_error (" [SpinnakerCamera::grabImage] Image received from camera " + std::to_string (serial_) +
340- " is incomplete. " );
341+ ROS_WARN_STREAM_ONCE (" [SpinnakerCamera::grabImage] Image received from camera " << std::to_string (serial_) << " is incomplete. Trying again. " );
342+ image_ptr = pCam_-> GetNextImage (timeout_ );
341343 }
342- else
344+
345+
346+ // Set Image Time Stamp
347+ image->header .stamp .sec = image_ptr->GetTimeStamp () * 1e-9 ;
348+ image->header .stamp .nsec = image_ptr->GetTimeStamp ();
349+
350+ // Check the bits per pixel.
351+ size_t bitsPerPixel = image_ptr->GetBitsPerPixel ();
352+
353+ // --------------------------------------------------
354+ // Set the image encoding
355+ std::string imageEncoding = sensor_msgs::image_encodings::MONO8;
356+
357+ Spinnaker::GenApi::CEnumerationPtr color_filter_ptr =
358+ static_cast <Spinnaker::GenApi::CEnumerationPtr>(node_map_->GetNode (" PixelColorFilter" ));
359+
360+ Spinnaker::GenICam::gcstring color_filter_str = color_filter_ptr->ToString ();
361+ Spinnaker::GenICam::gcstring bayer_rg_str = " BayerRG" ;
362+ Spinnaker::GenICam::gcstring bayer_gr_str = " BayerGR" ;
363+ Spinnaker::GenICam::gcstring bayer_gb_str = " BayerGB" ;
364+ Spinnaker::GenICam::gcstring bayer_bg_str = " BayerBG" ;
365+
366+ // if(isColor_ && bayer_format != NONE)
367+ if (color_filter_ptr->GetCurrentEntry () != color_filter_ptr->GetEntryByName (" None" ))
343368 {
344- // Set Image Time Stamp
345- image->header .stamp .sec = image_ptr->GetTimeStamp () * 1e-9 ;
346- image->header .stamp .nsec = image_ptr->GetTimeStamp ();
347-
348- // Check the bits per pixel.
349- size_t bitsPerPixel = image_ptr->GetBitsPerPixel ();
350-
351- // --------------------------------------------------
352- // Set the image encoding
353- std::string imageEncoding = sensor_msgs::image_encodings::MONO8;
354-
355- Spinnaker::GenApi::CEnumerationPtr color_filter_ptr =
356- static_cast <Spinnaker::GenApi::CEnumerationPtr>(node_map_->GetNode (" PixelColorFilter" ));
357-
358- Spinnaker::GenICam::gcstring color_filter_str = color_filter_ptr->ToString ();
359- Spinnaker::GenICam::gcstring bayer_rg_str = " BayerRG" ;
360- Spinnaker::GenICam::gcstring bayer_gr_str = " BayerGR" ;
361- Spinnaker::GenICam::gcstring bayer_gb_str = " BayerGB" ;
362- Spinnaker::GenICam::gcstring bayer_bg_str = " BayerBG" ;
363-
364- // if(isColor_ && bayer_format != NONE)
365- if (color_filter_ptr->GetCurrentEntry () != color_filter_ptr->GetEntryByName (" None" ))
369+ if (bitsPerPixel == 16 )
366370 {
367- if (bitsPerPixel == 16 )
371+ // 16 Bits per Pixel
372+ if (color_filter_str.compare (bayer_rg_str) == 0 )
373+ {
374+ imageEncoding = sensor_msgs::image_encodings::BAYER_RGGB16;
375+ }
376+ else if (color_filter_str.compare (bayer_gr_str) == 0 )
377+ {
378+ imageEncoding = sensor_msgs::image_encodings::BAYER_GRBG16;
379+ }
380+ else if (color_filter_str.compare (bayer_gb_str) == 0 )
368381 {
369- // 16 Bits per Pixel
370- if (color_filter_str.compare (bayer_rg_str) == 0 )
371- {
372- imageEncoding = sensor_msgs::image_encodings::BAYER_RGGB16;
373- }
374- else if (color_filter_str.compare (bayer_gr_str) == 0 )
375- {
376- imageEncoding = sensor_msgs::image_encodings::BAYER_GRBG16;
377- }
378- else if (color_filter_str.compare (bayer_gb_str) == 0 )
379- {
380- imageEncoding = sensor_msgs::image_encodings::BAYER_GBRG16;
381- }
382- else if (color_filter_str.compare (bayer_bg_str) == 0 )
383- {
384- imageEncoding = sensor_msgs::image_encodings::BAYER_BGGR16;
385- }
386- else
387- {
388- throw std::runtime_error (" [SpinnakerCamera::grabImage] Bayer format not recognized for 16-bit format." );
389- }
382+ imageEncoding = sensor_msgs::image_encodings::BAYER_GBRG16;
383+ }
384+ else if (color_filter_str.compare (bayer_bg_str) == 0 )
385+ {
386+ imageEncoding = sensor_msgs::image_encodings::BAYER_BGGR16;
390387 }
391388 else
392389 {
393- // 8 Bits per Pixel
394- if (color_filter_str.compare (bayer_rg_str) == 0 )
395- {
396- imageEncoding = sensor_msgs::image_encodings::BAYER_RGGB8;
397- }
398- else if (color_filter_str.compare (bayer_gr_str) == 0 )
399- {
400- imageEncoding = sensor_msgs::image_encodings::BAYER_GRBG8;
401- }
402- else if (color_filter_str.compare (bayer_gb_str) == 0 )
403- {
404- imageEncoding = sensor_msgs::image_encodings::BAYER_GBRG8;
405- }
406- else if (color_filter_str.compare (bayer_bg_str) == 0 )
407- {
408- imageEncoding = sensor_msgs::image_encodings::BAYER_BGGR8;
409- }
410- else
411- {
412- throw std::runtime_error (" [SpinnakerCamera::grabImage] Bayer format not recognized for 8-bit format." );
413- }
390+ throw std::runtime_error (" [SpinnakerCamera::grabImage] Bayer format not recognized for 16-bit format." );
414391 }
415392 }
416- else // Mono camera or in pixel binned mode.
393+ else
417394 {
418- if (bitsPerPixel == 16 )
395+ // 8 Bits per Pixel
396+ if (color_filter_str.compare (bayer_rg_str) == 0 )
419397 {
420- imageEncoding = sensor_msgs::image_encodings::MONO16 ;
398+ imageEncoding = sensor_msgs::image_encodings::BAYER_RGGB8 ;
421399 }
422- else if (bitsPerPixel == 24 )
400+ else if (color_filter_str. compare (bayer_gr_str) == 0 )
423401 {
424- imageEncoding = sensor_msgs::image_encodings::RGB8;
402+ imageEncoding = sensor_msgs::image_encodings::BAYER_GRBG8;
403+ }
404+ else if (color_filter_str.compare (bayer_gb_str) == 0 )
405+ {
406+ imageEncoding = sensor_msgs::image_encodings::BAYER_GBRG8;
407+ }
408+ else if (color_filter_str.compare (bayer_bg_str) == 0 )
409+ {
410+ imageEncoding = sensor_msgs::image_encodings::BAYER_BGGR8;
425411 }
426412 else
427413 {
428- imageEncoding = sensor_msgs::image_encodings::MONO8 ;
414+ throw std::runtime_error ( " [SpinnakerCamera::grabImage] Bayer format not recognized for 8-bit format. " ) ;
429415 }
430416 }
417+ }
418+ else // Mono camera or in pixel binned mode.
419+ {
420+ if (bitsPerPixel == 16 )
421+ {
422+ imageEncoding = sensor_msgs::image_encodings::MONO16;
423+ }
424+ else if (bitsPerPixel == 24 )
425+ {
426+ imageEncoding = sensor_msgs::image_encodings::RGB8;
427+ }
428+ else
429+ {
430+ imageEncoding = sensor_msgs::image_encodings::MONO8;
431+ }
432+ }
431433
432- int width = image_ptr->GetWidth ();
433- int height = image_ptr->GetHeight ();
434- int stride = image_ptr->GetStride ();
434+ int width = image_ptr->GetWidth ();
435+ int height = image_ptr->GetHeight ();
436+ int stride = image_ptr->GetStride ();
435437
436- // ROS_INFO_ONCE("\033[93m wxh: (%d, %d), stride: %d \n", width, height, stride);
437- fillImage (*image, imageEncoding, height, width, stride, image_ptr->GetData ());
438- image->header .frame_id = frame_id;
439- } // end else
438+ // ROS_INFO_ONCE("\033[93m wxh: (%d, %d), stride: %d \n", width, height, stride);
439+ fillImage (*image, imageEncoding, height, width, stride, image_ptr->GetData ());
440+ image->header .frame_id = frame_id;
441+
440442 }
441443 catch (const Spinnaker::Exception& e)
442444 {
0 commit comments