42 #include <visp3/core/vpException.h>
43 #include <visp3/sensor/vpFlyCaptureGrabber.h>
45 #ifdef VISP_HAVE_FLYCAPTURE
47 #include <visp3/core/vpTime.h>
54 : m_camera(), m_guid(), m_index(0), m_numCameras(0), m_rawImage(), m_connected(false), m_capture(false)
68 unsigned int numCameras;
69 FlyCapture2::BusManager busMgr;
70 FlyCapture2::Error error = busMgr.GetNumOfCameras(&numCameras);
71 if (error != FlyCapture2::PGRERROR_OK) {
85 FlyCapture2::CameraInfo camInfo;
86 FlyCapture2::Error error =
m_camera.GetCameraInfo(&camInfo);
87 if (error != FlyCapture2::PGRERROR_OK) {
88 error.PrintErrorTrace();
91 os <<
"Camera information: " << std::endl;
92 os <<
" Serial number : " << camInfo.serialNumber << std::endl;
93 os <<
" Camera model : " << camInfo.modelName << std::endl;
94 os <<
" Camera vendor : " << camInfo.vendorName << std::endl;
95 os <<
" Sensor : " << camInfo.sensorInfo << std::endl;
96 os <<
" Resolution : " << camInfo.sensorResolution << std::endl;
97 os <<
" Firmware version : " << camInfo.firmwareVersion << std::endl;
98 os <<
" Firmware build time: " << camInfo.firmwareBuildTime << std::endl;
209 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::FRAME_RATE);
210 return prop.absValue;
229 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHUTTER);
230 return prop.absValue;
249 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::GAIN);
250 return prop.absValue;
269 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::BRIGHTNESS);
270 return prop.absValue;
289 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHARPNESS);
309 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::AUTO_EXPOSURE);
310 return prop.absValue;
347 if (index >= num_cameras) {
349 index, num_cameras));
351 unsigned int serial_id;
352 FlyCapture2::BusManager busMgr;
353 FlyCapture2::Error error;
354 error = busMgr.GetCameraSerialNumberFromIndex(index, &serial_id);
355 if (error != FlyCapture2::PGRERROR_OK) {
356 error.PrintErrorTrace();
418 FlyCapture2::BusManager busMgr;
419 FlyCapture2::Error error;
444 FlyCapture2::PropertyInfo propInfo;
447 if (propInfo.present) {
448 FlyCapture2::Property prop;
449 prop.type = prop_type;
450 prop.onOff = on && propInfo.onOffSupported;
451 prop.autoManualMode = auto_on && propInfo.autoSupported;
452 prop.absControl = propInfo.absValSupported;
453 switch (prop_value) {
455 float value_ = std::max<float>(std::min<float>((
float)value, (
float)propInfo.absMax), (
float)propInfo.absMin);
456 prop.absValue = value_;
460 unsigned int value_ =
461 std::max<unsigned int>(std::min<unsigned int>((
unsigned int)value, (
unsigned int)propInfo.max), (
unsigned int)propInfo.min);
462 prop.valueA = value_;
467 FlyCapture2::Error error;
468 error =
m_camera.SetProperty(&prop);
469 if (error != FlyCapture2::PGRERROR_OK) {
470 error.PrintErrorTrace();
512 this->
setProperty(FlyCapture2::FRAME_RATE,
true,
false, frame_rate);
513 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::FRAME_RATE);
514 return prop.absValue;
555 this->
setProperty(FlyCapture2::SHUTTER,
true, auto_shutter, shutter_ms);
556 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHUTTER);
557 return prop.absValue;
599 this->
setProperty(FlyCapture2::GAIN,
true, gain_auto, gain_value);
600 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::GAIN);
601 return prop.absValue;
643 this->
setProperty(FlyCapture2::BRIGHTNESS,
true, brightness_auto, brightness_value);
644 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::BRIGHTNESS);
645 return prop.absValue;
696 this->
setProperty(FlyCapture2::AUTO_EXPOSURE, exposure_on, exposure_auto, exposure_value);
697 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::AUTO_EXPOSURE);
698 return prop.absValue;
743 this->
setProperty(FlyCapture2::SHARPNESS, sharpness_on, sharpness_auto, (
float)sharpness_value,
VALUE_A);
744 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHARPNESS);
756 FlyCapture2::Property prop;
757 prop.type = prop_type;
758 FlyCapture2::Error error;
759 error =
m_camera.GetProperty(&prop);
760 if (error != FlyCapture2::PGRERROR_OK) {
761 error.PrintErrorTrace();
776 FlyCapture2::PropertyInfo propInfo;
777 propInfo.type = prop_type;
779 FlyCapture2::Error error;
780 error =
m_camera.GetPropertyInfo(&propInfo);
781 if (error != FlyCapture2::PGRERROR_OK) {
782 error.PrintErrorTrace();
822 FlyCapture2::Error error;
823 error =
m_camera.SetVideoModeAndFrameRate(video_mode, frame_rate);
824 if (error != FlyCapture2::PGRERROR_OK) {
825 error.PrintErrorTrace();
834 FlyCapture2::FrameRate frame_rate)
838 FlyCapture2::Error error;
839 bool supported =
false;
840 error =
m_camera.GetVideoModeAndFrameRateInfo(video_mode, frame_rate, &supported);
841 if (error != FlyCapture2::PGRERROR_OK) {
842 error.PrintErrorTrace();
856 if (size == 0 || size > max_size)
859 size = size / step * step;
860 const unsigned int offset = (max_size - size) / 2;
862 return std::make_pair(size, offset);
899 unsigned int w,
unsigned int h)
903 FlyCapture2::Format7Info fmt7_info;
905 FlyCapture2::Error error;
907 fmt7_info.mode = format7_mode;
908 error =
m_camera.GetFormat7Info(&fmt7_info, &fmt7_supported);
909 if (error != FlyCapture2::PGRERROR_OK) {
910 error.PrintErrorTrace();
913 if (!fmt7_supported) {
917 FlyCapture2::Format7ImageSettings fmt7_settings;
918 fmt7_settings.mode = format7_mode;
919 fmt7_settings.pixelFormat = pixel_format;
921 std::pair<unsigned int, unsigned int> roi_w = this->
centerRoi(w, fmt7_info.maxWidth, fmt7_info.imageHStepSize);
922 std::pair<unsigned int, unsigned int> roi_h = this->
centerRoi(h, fmt7_info.maxHeight, fmt7_info.imageVStepSize);
923 fmt7_settings.width = roi_w.first;
924 fmt7_settings.offsetX = roi_w.second;
925 fmt7_settings.height = roi_h.first;
926 fmt7_settings.offsetY = roi_h.second;
929 FlyCapture2::Format7PacketInfo fmt7_packet_info;
931 error =
m_camera.ValidateFormat7Settings(&fmt7_settings, &valid, &fmt7_packet_info);
932 if (error != FlyCapture2::PGRERROR_OK) {
933 error.PrintErrorTrace();
939 error =
m_camera.SetFormat7Configuration(&fmt7_settings, fmt7_packet_info.recommendedBytesPerPacket);
940 if (error != FlyCapture2::PGRERROR_OK) {
941 error.PrintErrorTrace();
953 FlyCapture2::Format7Info fmt7_info;
954 bool supported =
false;
955 FlyCapture2::Error error;
957 fmt7_info.mode = format7_mode;
958 error =
m_camera.GetFormat7Info(&fmt7_info, &supported);
959 if (error != FlyCapture2::PGRERROR_OK) {
960 error.PrintErrorTrace();
977 FlyCapture2::Error error;
979 if (error != FlyCapture2::PGRERROR_OK) {
980 error.PrintErrorTrace();
1001 FlyCapture2::Error error;
1003 if (error != FlyCapture2::PGRERROR_OK) {
1004 error.PrintErrorTrace();
1023 FlyCapture2::Error error;
1029 FlyCapture2::BusManager busMgr;
1032 if (error != FlyCapture2::PGRERROR_OK) {
1033 error.PrintErrorTrace();
1038 if (error != FlyCapture2::PGRERROR_OK) {
1039 error.PrintErrorTrace();
1059 FlyCapture2::Error error;
1061 if (error != FlyCapture2::PGRERROR_OK) {
1062 error.PrintErrorTrace();
1100 FlyCapture2::TimeStamp timestamp;
1115 FlyCapture2::Error error;
1118 if (error != FlyCapture2::PGRERROR_OK) {
1119 error.PrintErrorTrace();
1133 sizeof(
unsigned char) * I.
getSize(), FlyCapture2::PIXEL_FORMAT_MONO8);
1136 error =
m_rawImage.Convert(FlyCapture2::PIXEL_FORMAT_MONO8, &convertedImage);
1137 if (error != FlyCapture2::PGRERROR_OK) {
1138 error.PrintErrorTrace();
1151 FlyCapture2::TimeStamp timestamp;
1166 FlyCapture2::Error error;
1169 if (error != FlyCapture2::PGRERROR_OK) {
1170 error.PrintErrorTrace();
1176 FlyCapture2::Image convertedImage;
1179 error =
m_rawImage.Convert(FlyCapture2::PIXEL_FORMAT_RGBU, &convertedImage);
1180 if (error != FlyCapture2::PGRERROR_OK) {
1181 error.PrintErrorTrace();
1185 height = convertedImage.GetRows();
1186 width = convertedImage.GetCols();
1189 unsigned char *data = convertedImage.GetData();
1190 unsigned int stride = convertedImage.GetStride();
1191 unsigned int Bps = convertedImage.GetBitsPerPixel() / 8;
1195 for (
unsigned int i = 0; i <
height; ++i) {
1196 for (
unsigned int j = 0; j <
width; ++j) {
1197 unsigned char *pp = data + i * stride + j * Bps;
1252 const unsigned int powerReg = 0x400;
1253 unsigned int powerRegVal = 0;
1255 FlyCapture2::Error error;
1256 error =
m_camera.ReadRegister(powerReg, &powerRegVal);
1257 if (error != FlyCapture2::PGRERROR_OK) {
1261 return ((powerRegVal & 0x00008000) != 0);
1273 const unsigned int powerReg = 0x610;
1274 unsigned int powerRegVal = 0;
1276 FlyCapture2::Error error;
1277 error =
m_camera.ReadRegister(powerReg, &powerRegVal);
1278 if (error != FlyCapture2::PGRERROR_OK) {
1282 return ((powerRegVal & (0x1 << 31)) != 0);
1322 const unsigned int powerReg = 0x610;
1323 unsigned int powerRegVal = 0;
1325 powerRegVal = (on ==
true) ? 0x80000000 : 0x0;
1327 FlyCapture2::Error error;
1328 error =
m_camera.WriteRegister(powerReg, powerRegVal);
1329 if (error != FlyCapture2::PGRERROR_OK) {
1330 error.PrintErrorTrace();
1334 unsigned int millisecondsToSleep = 100;
1335 unsigned int regVal = 0;
1336 unsigned int retries = 10;
1341 error =
m_camera.ReadRegister(powerReg, ®Val);
1342 if (error == FlyCapture2::PGRERROR_TIMEOUT) {
1346 else if (error != FlyCapture2::PGRERROR_OK) {
1347 error.PrintErrorTrace();
1352 }
while ((regVal & powerRegVal) == 0 && retries > 0);
1355 if (error == FlyCapture2::PGRERROR_TIMEOUT) {
1356 error.PrintErrorTrace();
1408 void dummy_vpFlyCaptureGrabber() { };
error that can be emitted 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)