43 #include <visp3/core/vpException.h>
44 #include <visp3/sensor/vpFlyCaptureGrabber.h>
46 #ifdef VISP_HAVE_FLYCAPTURE
48 #include <visp3/core/vpTime.h>
54 : m_camera(), m_guid(), m_index(0), m_numCameras(0), m_rawImage(), m_connected(false), m_capture(false)
71 unsigned int numCameras;
72 FlyCapture2::BusManager busMgr;
73 FlyCapture2::Error error = busMgr.GetNumOfCameras(&numCameras);
74 if (error != FlyCapture2::PGRERROR_OK) {
88 FlyCapture2::CameraInfo camInfo;
89 FlyCapture2::Error error =
m_camera.GetCameraInfo(&camInfo);
90 if (error != FlyCapture2::PGRERROR_OK) {
91 error.PrintErrorTrace();
94 os <<
"Camera information: " << std::endl;
95 os <<
" Serial number : " << camInfo.serialNumber << std::endl;
96 os <<
" Camera model : " << camInfo.modelName << std::endl;
97 os <<
" Camera vendor : " << camInfo.vendorName << std::endl;
98 os <<
" Sensor : " << camInfo.sensorInfo << std::endl;
99 os <<
" Resolution : " << camInfo.sensorResolution << std::endl;
100 os <<
" Firmware version : " << camInfo.firmwareVersion << std::endl;
101 os <<
" Firmware build time: " << camInfo.firmwareBuildTime << std::endl;
211 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::FRAME_RATE);
212 return prop.absValue;
231 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHUTTER);
232 return prop.absValue;
251 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::GAIN);
252 return prop.absValue;
271 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::BRIGHTNESS);
272 return prop.absValue;
291 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHARPNESS);
311 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::AUTO_EXPOSURE);
312 return prop.absValue;
348 if(index >= num_cameras) {
350 "The camera with index %u is not present. Only %d cameras connected.",
351 index, num_cameras) );
353 unsigned int serial_id;
354 FlyCapture2::BusManager busMgr;
355 FlyCapture2::Error error;
356 error = busMgr.GetCameraSerialNumberFromIndex(index, &serial_id);
357 if (error != FlyCapture2::PGRERROR_OK) {
358 error.PrintErrorTrace();
360 "Cannot get camera with index %d serial id.", index) );
385 "The camera with index %u is not present. Only %d cameras connected.",
422 FlyCapture2::BusManager busMgr;
423 FlyCapture2::Error error;
432 "The camera with serial id %u is not present.",
446 bool on,
bool auto_on,
451 FlyCapture2::PropertyInfo propInfo;
454 if (propInfo.present) {
455 FlyCapture2::Property prop;
456 prop.type = prop_type;
457 prop.onOff = on && propInfo.onOffSupported;
458 prop.autoManualMode = auto_on && propInfo.autoSupported;
459 prop.absControl = propInfo.absValSupported;
462 float value_ = std::max<float>(std::min<float>(value, propInfo.absMax), propInfo.absMin);
463 prop.absValue = value_;
467 unsigned int value_ = std::max<unsigned int>(std::min<unsigned int>((
unsigned int)value, propInfo.max), propInfo.min);
468 prop.valueA = value_;
473 FlyCapture2::Error error;
474 error =
m_camera.SetProperty(&prop);
475 if (error != FlyCapture2::PGRERROR_OK) {
476 error.PrintErrorTrace();
478 "Cannot set property %d.",
520 this->
setProperty(FlyCapture2::FRAME_RATE,
true,
false, frame_rate);
521 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::FRAME_RATE);
522 return prop.absValue;
562 this->
setProperty(FlyCapture2::SHUTTER,
true, auto_shutter, shutter_ms);
563 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHUTTER);
564 return prop.absValue;
606 this->
setProperty(FlyCapture2::GAIN,
true, gain_auto, gain_value);
607 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::GAIN);
608 return prop.absValue;
648 this->
setProperty(FlyCapture2::BRIGHTNESS,
true, brightness_auto, brightness_value);
649 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::BRIGHTNESS);
650 return prop.absValue;
700 this->
setProperty(FlyCapture2::AUTO_EXPOSURE, exposure_on, exposure_auto, exposure_value);
701 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::AUTO_EXPOSURE);
702 return prop.absValue;
745 this->
setProperty(FlyCapture2::SHARPNESS, sharpness_on, sharpness_auto, (
float)sharpness_value,
VALUE_A);
746 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHARPNESS);
758 FlyCapture2::Property prop;
759 prop.type = prop_type;
760 FlyCapture2::Error error;
761 error =
m_camera.GetProperty( &prop );
762 if (error != FlyCapture2::PGRERROR_OK) {
763 error.PrintErrorTrace();
765 "Cannot get property %d value.", (
int)prop_type));
775 FlyCapture2::PropertyInfo
780 FlyCapture2::PropertyInfo propInfo;
781 propInfo.type = prop_type;
783 FlyCapture2::Error error;
784 error =
m_camera.GetPropertyInfo(&propInfo);
785 if (error != FlyCapture2::PGRERROR_OK) {
786 error.PrintErrorTrace();
824 FlyCapture2::FrameRate frame_rate)
828 FlyCapture2::Error error;
829 error =
m_camera.SetVideoModeAndFrameRate(video_mode, frame_rate);
830 if (error != FlyCapture2::PGRERROR_OK) {
831 error.PrintErrorTrace();
840 FlyCapture2::FrameRate frame_rate)
844 FlyCapture2::Error error;
845 bool supported =
false;
846 error =
m_camera.GetVideoModeAndFrameRateInfo(video_mode, frame_rate, &supported);
847 if (error != FlyCapture2::PGRERROR_OK) {
848 error.PrintErrorTrace();
860 std::pair<unsigned int, unsigned int>
863 if (size == 0 || size > max_size) size = max_size;
865 size = size / step * step;
866 const unsigned int offset = (max_size - size) / 2;
868 return std::make_pair(size, offset);
902 FlyCapture2::PixelFormat pixel_format,
903 unsigned int width,
unsigned int height)
907 FlyCapture2::Format7Info fmt7_info;
909 FlyCapture2::Error error;
911 fmt7_info.mode = format7_mode;
912 error =
m_camera.GetFormat7Info(&fmt7_info, &fmt7_supported);
913 if (error != FlyCapture2::PGRERROR_OK) {
914 error.PrintErrorTrace();
917 if (! fmt7_supported) {
921 FlyCapture2::Format7ImageSettings fmt7_settings;
922 fmt7_settings.mode = format7_mode;
923 fmt7_settings.pixelFormat = pixel_format;
925 std::pair<unsigned int, unsigned int> roi_w = this->
centerRoi(width, fmt7_info.maxWidth, fmt7_info.imageHStepSize);
926 std::pair<unsigned int, unsigned int> roi_h = this->
centerRoi(height, fmt7_info.maxHeight, fmt7_info.imageVStepSize);
927 fmt7_settings.width = roi_w.first;
928 fmt7_settings.offsetX = roi_w.second;
929 fmt7_settings.height = roi_h.first;
930 fmt7_settings.offsetY = roi_h.second;
933 FlyCapture2::Format7PacketInfo fmt7_packet_info;
935 error =
m_camera.ValidateFormat7Settings(&fmt7_settings, &valid, &fmt7_packet_info);
936 if (error != FlyCapture2::PGRERROR_OK) {
937 error.PrintErrorTrace();
943 error =
m_camera.SetFormat7Configuration(&fmt7_settings, fmt7_packet_info.recommendedBytesPerPacket);
944 if (error != FlyCapture2::PGRERROR_OK) {
945 error.PrintErrorTrace();
957 FlyCapture2::Format7Info fmt7_info;
958 bool supported =
false;
959 FlyCapture2::Error error;
961 fmt7_info.mode = format7_mode;
962 error =
m_camera.GetFormat7Info(&fmt7_info, &supported);
963 if (error != FlyCapture2::PGRERROR_OK) {
964 error.PrintErrorTrace();
981 FlyCapture2::Error error;
983 if (error != FlyCapture2::PGRERROR_OK) {
984 error.PrintErrorTrace();
1005 FlyCapture2::Error error;
1007 if (error != FlyCapture2::PGRERROR_OK) {
1008 error.PrintErrorTrace();
1027 FlyCapture2::Error error;
1033 FlyCapture2::BusManager busMgr;
1036 if (error != FlyCapture2::PGRERROR_OK) {
1037 error.PrintErrorTrace();
1039 "Cannot retrieve guid of camera with index %u.",
1044 if (error != FlyCapture2::PGRERROR_OK) {
1045 error.PrintErrorTrace();
1066 FlyCapture2::Error error;
1068 if (error != FlyCapture2::PGRERROR_OK) {
1069 error.PrintErrorTrace();
1106 FlyCapture2::TimeStamp timestamp;
1121 FlyCapture2::Error error;
1124 if (error != FlyCapture2::PGRERROR_OK) {
1125 error.PrintErrorTrace();
1132 FlyCapture2::Image convertedImage;
1135 error =
m_rawImage.Convert( FlyCapture2::PIXEL_FORMAT_MONO8, &convertedImage );
1136 if (error != FlyCapture2::PGRERROR_OK) {
1137 error.PrintErrorTrace();
1141 height = convertedImage.GetRows();
1142 width = convertedImage.GetCols();
1143 unsigned char *data = convertedImage.GetData();
1155 FlyCapture2::TimeStamp timestamp;
1170 FlyCapture2::Error error;
1173 if (error != FlyCapture2::PGRERROR_OK) {
1174 error.PrintErrorTrace();
1181 FlyCapture2::Image convertedImage;
1184 error =
m_rawImage.Convert( FlyCapture2::PIXEL_FORMAT_RGBU, &convertedImage );
1185 if (error != FlyCapture2::PGRERROR_OK) {
1186 error.PrintErrorTrace();
1190 height = convertedImage.GetRows();
1191 width = convertedImage.GetCols();
1192 unsigned char *data = convertedImage.GetData();
1194 unsigned int bps = convertedImage.GetBitsPerPixel();
1245 const unsigned int powerReg = 0x400;
1246 unsigned int powerRegVal = 0;
1248 FlyCapture2::Error error;
1249 error =
m_camera.ReadRegister( powerReg, &powerRegVal );
1250 if ( error != FlyCapture2::PGRERROR_OK ) {
1254 return ( (powerRegVal & 0x00008000 ) != 0 );
1266 const unsigned int powerReg = 0x610;
1267 unsigned int powerRegVal = 0 ;
1269 FlyCapture2::Error error;
1270 error =
m_camera.ReadRegister( powerReg, &powerRegVal );
1271 if ( error != FlyCapture2::PGRERROR_OK ) {
1275 return ( (powerRegVal & (0x1 << 31)) != 0 );
1312 "Cannot power on camera. Feature not available") );
1316 const unsigned int powerReg = 0x610;
1317 unsigned int powerRegVal = 0;
1319 powerRegVal = (on ==
true) ? 0x80000000 : 0x0;
1321 FlyCapture2::Error error;
1322 error =
m_camera.WriteRegister( powerReg, powerRegVal );
1323 if (error != FlyCapture2::PGRERROR_OK) {
1324 error.PrintErrorTrace();
1328 const unsigned int millisecondsToSleep = 100;
1329 unsigned int regVal = 0;
1330 unsigned int retries = 10;
1336 error =
m_camera.ReadRegister(powerReg, ®Val);
1337 if (error == FlyCapture2::PGRERROR_TIMEOUT) {
1341 else if (error != FlyCapture2::PGRERROR_OK) {
1342 error.PrintErrorTrace();
1347 }
while ((regVal & powerRegVal) == 0 && retries > 0);
1350 if (error == FlyCapture2::PGRERROR_TIMEOUT) {
1351 error.PrintErrorTrace();
1402 void dummy_vpFlyCaptureGrabber() {};
void setFormat7VideoMode(FlyCapture2::Mode format7_mode, FlyCapture2::PixelFormat pixel_format, unsigned int width, unsigned int height)
FlyCapture2::Image m_rawImage
Image buffer.
VISP_EXPORT int wait(double t0, double t)
FlyCapture2::Camera m_camera
Pointer to each camera.
Type * bitmap
points toward the bitmap
unsigned int getSharpness()
void setCameraSerial(unsigned int serial)
float setShutter(bool auto_shutter, float shutter_ms=10)
void acquire(vpImage< unsigned char > &I)
error that can be emited by ViSP classes.
bool isCameraPowerAvailable()
float setBrightness(bool brightness_auto, float brightness_value=0)
Consider FlyCapture2::Property::valueA.
FlyCapture2::Camera * getCameraHandler()
void setCameraIndex(unsigned int index)
std::pair< unsigned int, unsigned int > centerRoi(unsigned int size, unsigned int max_size, unsigned int step)
float setExposure(bool exposure_on, bool exposure_auto, float exposure_value=0)
float setGain(bool gain_auto, float gain_value=0)
FlyCapture2::PGRGuid m_guid
Active camera guid.
unsigned int height
Number of rows in the image.
void setProperty(const FlyCapture2::PropertyType &prop_type, bool on, bool auto_on, float value, PropertyValue prop_value=ABS_VALUE)
FlyCapture2::PropertyInfo getPropertyInfo(FlyCapture2::PropertyType prop_type)
bool isFormat7Supported(FlyCapture2::Mode format7_mode)
bool m_connected
true if camera connected
void resize(const unsigned int h, const unsigned int w)
resize the image : Image initialization
Consider FlyCapture2::Property::absValue.
unsigned int setSharpness(bool sharpness_on, bool sharpness_auto, unsigned int sharpness_value=0)
bool m_capture
true is capture started
vpFlyCaptureGrabber & operator>>(vpImage< unsigned char > &I)
FlyCapture2::Property getProperty(FlyCapture2::PropertyType prop_type)
bool init
Set to true if the frame grabber has been initialized.
static unsigned int getNumCameras()
virtual ~vpFlyCaptureGrabber()
unsigned int m_index
Active camera index.
static unsigned int getCameraSerial(unsigned int index)
float setFrameRate(float frame_rate)
unsigned int m_numCameras
Number of connected cameras.
std::ostream & getCameraInfo(std::ostream &os)
void setCameraPower(bool on)
bool isVideoModeAndFrameRateSupported(FlyCapture2::VideoMode video_mode, FlyCapture2::FrameRate frame_rate)
unsigned int width
Number of columns in the image.
void setVideoModeAndFrameRate(FlyCapture2::VideoMode video_mode, FlyCapture2::FrameRate frame_rate)