45 #include <visp3/core/vpException.h>
46 #include <visp3/sensor/vpFlyCaptureGrabber.h>
48 #ifdef VISP_HAVE_FLYCAPTURE
50 #include <visp3/core/vpTime.h>
57 : 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;
349 if (index >= num_cameras) {
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();
420 FlyCapture2::BusManager busMgr;
421 FlyCapture2::Error error;
446 FlyCapture2::PropertyInfo propInfo;
449 if (propInfo.present) {
450 FlyCapture2::Property prop;
451 prop.type = prop_type;
452 prop.onOff = on && propInfo.onOffSupported;
453 prop.autoManualMode = auto_on && propInfo.autoSupported;
454 prop.absControl = propInfo.absValSupported;
455 switch (prop_value) {
457 float value_ = (std::max)((std::min)((float)value, (
float)propInfo.absMax), (
float)propInfo.absMin);
458 prop.absValue = value_;
462 unsigned int value_ =
463 (std::max)((std::min)((
unsigned int)value, (
unsigned int)propInfo.max), (
unsigned int)propInfo.min);
464 prop.valueA = value_;
469 FlyCapture2::Error error;
470 error =
m_camera.SetProperty(&prop);
471 if (error != FlyCapture2::PGRERROR_OK) {
472 error.PrintErrorTrace();
514 this->
setProperty(FlyCapture2::FRAME_RATE,
true,
false, frame_rate);
515 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::FRAME_RATE);
516 return prop.absValue;
557 this->
setProperty(FlyCapture2::SHUTTER,
true, auto_shutter, shutter_ms);
558 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHUTTER);
559 return prop.absValue;
601 this->
setProperty(FlyCapture2::GAIN,
true, gain_auto, gain_value);
602 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::GAIN);
603 return prop.absValue;
645 this->
setProperty(FlyCapture2::BRIGHTNESS,
true, brightness_auto, brightness_value);
646 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::BRIGHTNESS);
647 return prop.absValue;
698 this->
setProperty(FlyCapture2::AUTO_EXPOSURE, exposure_on, exposure_auto, exposure_value);
699 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::AUTO_EXPOSURE);
700 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();
778 FlyCapture2::PropertyInfo propInfo;
779 propInfo.type = prop_type;
781 FlyCapture2::Error error;
782 error =
m_camera.GetPropertyInfo(&propInfo);
783 if (error != FlyCapture2::PGRERROR_OK) {
784 error.PrintErrorTrace();
824 FlyCapture2::Error error;
825 error =
m_camera.SetVideoModeAndFrameRate(video_mode, frame_rate);
826 if (error != FlyCapture2::PGRERROR_OK) {
827 error.PrintErrorTrace();
836 FlyCapture2::FrameRate frame_rate)
840 FlyCapture2::Error error;
841 bool supported =
false;
842 error =
m_camera.GetVideoModeAndFrameRateInfo(video_mode, frame_rate, &supported);
843 if (error != FlyCapture2::PGRERROR_OK) {
844 error.PrintErrorTrace();
858 if (size == 0 || size > max_size)
861 size = size / step * step;
862 const unsigned int offset = (max_size - size) / 2;
864 return std::make_pair(size, offset);
901 unsigned int w,
unsigned int h)
905 FlyCapture2::Format7Info fmt7_info;
907 FlyCapture2::Error error;
909 fmt7_info.mode = format7_mode;
910 error =
m_camera.GetFormat7Info(&fmt7_info, &fmt7_supported);
911 if (error != FlyCapture2::PGRERROR_OK) {
912 error.PrintErrorTrace();
915 if (!fmt7_supported) {
919 FlyCapture2::Format7ImageSettings fmt7_settings;
920 fmt7_settings.mode = format7_mode;
921 fmt7_settings.pixelFormat = pixel_format;
923 std::pair<unsigned int, unsigned int> roi_w = this->
centerRoi(w, fmt7_info.maxWidth, fmt7_info.imageHStepSize);
924 std::pair<unsigned int, unsigned int> roi_h = this->
centerRoi(h, fmt7_info.maxHeight, fmt7_info.imageVStepSize);
925 fmt7_settings.width = roi_w.first;
926 fmt7_settings.offsetX = roi_w.second;
927 fmt7_settings.height = roi_h.first;
928 fmt7_settings.offsetY = roi_h.second;
931 FlyCapture2::Format7PacketInfo fmt7_packet_info;
933 error =
m_camera.ValidateFormat7Settings(&fmt7_settings, &valid, &fmt7_packet_info);
934 if (error != FlyCapture2::PGRERROR_OK) {
935 error.PrintErrorTrace();
941 error =
m_camera.SetFormat7Configuration(&fmt7_settings, fmt7_packet_info.recommendedBytesPerPacket);
942 if (error != FlyCapture2::PGRERROR_OK) {
943 error.PrintErrorTrace();
955 FlyCapture2::Format7Info fmt7_info;
956 bool supported =
false;
957 FlyCapture2::Error error;
959 fmt7_info.mode = format7_mode;
960 error =
m_camera.GetFormat7Info(&fmt7_info, &supported);
961 if (error != FlyCapture2::PGRERROR_OK) {
962 error.PrintErrorTrace();
979 FlyCapture2::Error error;
981 if (error != FlyCapture2::PGRERROR_OK) {
982 error.PrintErrorTrace();
1003 FlyCapture2::Error error;
1005 if (error != FlyCapture2::PGRERROR_OK) {
1006 error.PrintErrorTrace();
1025 FlyCapture2::Error error;
1031 FlyCapture2::BusManager busMgr;
1034 if (error != FlyCapture2::PGRERROR_OK) {
1035 error.PrintErrorTrace();
1040 if (error != FlyCapture2::PGRERROR_OK) {
1041 error.PrintErrorTrace();
1061 FlyCapture2::Error error;
1063 if (error != FlyCapture2::PGRERROR_OK) {
1064 error.PrintErrorTrace();
1102 FlyCapture2::TimeStamp timestamp;
1117 FlyCapture2::Error error;
1120 if (error != FlyCapture2::PGRERROR_OK) {
1121 error.PrintErrorTrace();
1135 sizeof(
unsigned char) * I.
getSize(), FlyCapture2::PIXEL_FORMAT_MONO8);
1138 error =
m_rawImage.Convert(FlyCapture2::PIXEL_FORMAT_MONO8, &convertedImage);
1139 if (error != FlyCapture2::PGRERROR_OK) {
1140 error.PrintErrorTrace();
1153 FlyCapture2::TimeStamp timestamp;
1168 FlyCapture2::Error error;
1171 if (error != FlyCapture2::PGRERROR_OK) {
1172 error.PrintErrorTrace();
1178 FlyCapture2::Image convertedImage;
1181 error =
m_rawImage.Convert(FlyCapture2::PIXEL_FORMAT_RGBU, &convertedImage);
1182 if (error != FlyCapture2::PGRERROR_OK) {
1183 error.PrintErrorTrace();
1187 height = convertedImage.GetRows();
1188 width = convertedImage.GetCols();
1191 unsigned char *data = convertedImage.GetData();
1192 unsigned int stride = convertedImage.GetStride();
1193 unsigned int Bps = convertedImage.GetBitsPerPixel() / 8;
1197 for (
unsigned int i = 0; i <
height; ++i) {
1198 for (
unsigned int j = 0; j <
width; ++j) {
1199 unsigned char *pp = data + i * stride + j * Bps;
1254 const unsigned int powerReg = 0x400;
1255 unsigned int powerRegVal = 0;
1257 FlyCapture2::Error error;
1258 error =
m_camera.ReadRegister(powerReg, &powerRegVal);
1259 if (error != FlyCapture2::PGRERROR_OK) {
1263 return ((powerRegVal & 0x00008000) != 0);
1275 const unsigned int powerReg = 0x610;
1276 unsigned int powerRegVal = 0;
1278 FlyCapture2::Error error;
1279 error =
m_camera.ReadRegister(powerReg, &powerRegVal);
1280 if (error != FlyCapture2::PGRERROR_OK) {
1284 return ((powerRegVal & (0x1 << 31)) != 0);
1324 const unsigned int powerReg = 0x610;
1325 unsigned int powerRegVal = 0;
1327 powerRegVal = (on ==
true) ? 0x80000000 : 0x0;
1329 FlyCapture2::Error error;
1330 error =
m_camera.WriteRegister(powerReg, powerRegVal);
1331 if (error != FlyCapture2::PGRERROR_OK) {
1332 error.PrintErrorTrace();
1336 unsigned int millisecondsToSleep = 100;
1337 unsigned int regVal = 0;
1338 unsigned int retries = 10;
1343 error =
m_camera.ReadRegister(powerReg, ®Val);
1344 if (error == FlyCapture2::PGRERROR_TIMEOUT) {
1347 }
else if (error != FlyCapture2::PGRERROR_OK) {
1348 error.PrintErrorTrace();
1353 }
while ((regVal & powerRegVal) == 0 && retries > 0);
1356 if (error == FlyCapture2::PGRERROR_TIMEOUT) {
1357 error.PrintErrorTrace();
1409 void dummy_vpFlyCaptureGrabber(){};
error that can be emited by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
unsigned int getSharpness()
FlyCapture2::Camera * getCameraHandler()
static unsigned int getNumCameras()
FlyCapture2::Image m_rawImage
Image buffer.
float setGain(bool gain_auto, float gain_value=0)
std::pair< unsigned int, unsigned int > centerRoi(unsigned int size, unsigned int max_size, unsigned int step)
float setShutter(bool auto_shutter, float shutter_ms=10)
void setCameraPower(bool on)
float setExposure(bool exposure_on, bool exposure_auto, float exposure_value=0)
void setProperty(const FlyCapture2::PropertyType &prop_type, bool on, bool auto_on, float value, PropertyValue prop_value=ABS_VALUE)
bool m_capture
true is capture started
vpFlyCaptureGrabber & operator>>(vpImage< unsigned char > &I)
void setCameraSerial(unsigned int serial)
void setCameraIndex(unsigned int index)
float setFrameRate(float frame_rate)
bool isCameraPowerAvailable()
FlyCapture2::Camera m_camera
Pointer to each camera.
unsigned int m_index
Active camera index.
FlyCapture2::PropertyInfo getPropertyInfo(FlyCapture2::PropertyType prop_type)
static unsigned int getCameraSerial(unsigned int index)
void setFormat7VideoMode(FlyCapture2::Mode format7_mode, FlyCapture2::PixelFormat pixel_format, unsigned int width, unsigned int height)
unsigned int m_numCameras
Number of connected cameras.
unsigned int setSharpness(bool sharpness_on, bool sharpness_auto, unsigned int sharpness_value=0)
void acquire(vpImage< unsigned char > &I)
FlyCapture2::Property getProperty(FlyCapture2::PropertyType prop_type)
bool isVideoModeAndFrameRateSupported(FlyCapture2::VideoMode video_mode, FlyCapture2::FrameRate frame_rate)
std::ostream & getCameraInfo(std::ostream &os)
bool isFormat7Supported(FlyCapture2::Mode format7_mode)
@ VALUE_A
Consider FlyCapture2::Property::valueA.
@ ABS_VALUE
Consider FlyCapture2::Property::absValue.
virtual ~vpFlyCaptureGrabber()
void setVideoModeAndFrameRate(FlyCapture2::VideoMode video_mode, FlyCapture2::FrameRate frame_rate)
bool m_connected
true if camera connected
FlyCapture2::PGRGuid m_guid
Active camera guid.
float setBrightness(bool brightness_auto, float brightness_value=0)
unsigned int height
Number of rows in the image.
bool init
Set to true if the frame grabber has been initialized.
unsigned int width
Number of columns in the image.
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getSize() const
Type * bitmap
points toward the bitmap
VISP_EXPORT int wait(double t0, double t)