42 #include <visp3/core/vpException.h>
43 #include <visp3/sensor/vpFlyCaptureGrabber.h>
45 #ifdef VISP_HAVE_FLYCAPTURE
47 #include <visp3/core/vpTime.h>
56 : m_camera(), m_guid(), m_index(0), m_numCameras(0), m_rawImage(), m_connected(false), m_capture(false)
70 unsigned int numCameras;
71 FlyCapture2::BusManager busMgr;
72 FlyCapture2::Error error = busMgr.GetNumOfCameras(&numCameras);
73 if (error != FlyCapture2::PGRERROR_OK) {
87 FlyCapture2::CameraInfo camInfo;
88 FlyCapture2::Error error =
m_camera.GetCameraInfo(&camInfo);
89 if (error != FlyCapture2::PGRERROR_OK) {
90 error.PrintErrorTrace();
93 os <<
"Camera information: " << std::endl;
94 os <<
" Serial number : " << camInfo.serialNumber << std::endl;
95 os <<
" Camera model : " << camInfo.modelName << std::endl;
96 os <<
" Camera vendor : " << camInfo.vendorName << std::endl;
97 os <<
" Sensor : " << camInfo.sensorInfo << std::endl;
98 os <<
" Resolution : " << camInfo.sensorResolution << std::endl;
99 os <<
" Firmware version : " << camInfo.firmwareVersion << std::endl;
100 os <<
" Firmware build time: " << camInfo.firmwareBuildTime << std::endl;
218 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::FRAME_RATE);
219 return prop.absValue;
238 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHUTTER);
239 return prop.absValue;
258 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::GAIN);
259 return prop.absValue;
278 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::BRIGHTNESS);
279 return prop.absValue;
298 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHARPNESS);
318 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::AUTO_EXPOSURE);
319 return prop.absValue;
360 if (index >= num_cameras) {
362 index, num_cameras));
364 unsigned int serial_id;
365 FlyCapture2::BusManager busMgr;
366 FlyCapture2::Error error;
367 error = busMgr.GetCameraSerialNumberFromIndex(index, &serial_id);
368 if (error != FlyCapture2::PGRERROR_OK) {
369 error.PrintErrorTrace();
435 FlyCapture2::BusManager busMgr;
436 FlyCapture2::Error error;
461 FlyCapture2::PropertyInfo propInfo;
464 if (propInfo.present) {
465 FlyCapture2::Property prop;
466 prop.type = prop_type;
467 prop.onOff = on && propInfo.onOffSupported;
468 prop.autoManualMode = auto_on && propInfo.autoSupported;
469 prop.absControl = propInfo.absValSupported;
470 switch (prop_value) {
472 float value_ = std::max<float>(std::min<float>((
float)value, (
float)propInfo.absMax), (
float)propInfo.absMin);
473 prop.absValue = value_;
477 unsigned int value_ =
478 std::max<unsigned int>(std::min<unsigned int>((
unsigned int)value, (
unsigned int)propInfo.max), (
unsigned int)propInfo.min);
479 prop.valueA = value_;
484 FlyCapture2::Error error;
485 error =
m_camera.SetProperty(&prop);
486 if (error != FlyCapture2::PGRERROR_OK) {
487 error.PrintErrorTrace();
533 this->
setProperty(FlyCapture2::FRAME_RATE,
true,
false, frame_rate);
534 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::FRAME_RATE);
535 return prop.absValue;
579 this->
setProperty(FlyCapture2::SHUTTER,
true, auto_shutter, shutter_ms);
580 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHUTTER);
581 return prop.absValue;
627 this->
setProperty(FlyCapture2::GAIN,
true, gain_auto, gain_value);
628 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::GAIN);
629 return prop.absValue;
675 this->
setProperty(FlyCapture2::BRIGHTNESS,
true, brightness_auto, brightness_value);
676 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::BRIGHTNESS);
677 return prop.absValue;
733 this->
setProperty(FlyCapture2::AUTO_EXPOSURE, exposure_on, exposure_auto, exposure_value);
734 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::AUTO_EXPOSURE);
735 return prop.absValue;
785 this->
setProperty(FlyCapture2::SHARPNESS, sharpness_on, sharpness_auto, (
float)sharpness_value,
VALUE_A);
786 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHARPNESS);
798 FlyCapture2::Property prop;
799 prop.type = prop_type;
800 FlyCapture2::Error error;
801 error =
m_camera.GetProperty(&prop);
802 if (error != FlyCapture2::PGRERROR_OK) {
803 error.PrintErrorTrace();
818 FlyCapture2::PropertyInfo propInfo;
819 propInfo.type = prop_type;
821 FlyCapture2::Error error;
822 error =
m_camera.GetPropertyInfo(&propInfo);
823 if (error != FlyCapture2::PGRERROR_OK) {
824 error.PrintErrorTrace();
868 FlyCapture2::Error error;
869 error =
m_camera.SetVideoModeAndFrameRate(video_mode, frame_rate);
870 if (error != FlyCapture2::PGRERROR_OK) {
871 error.PrintErrorTrace();
880 FlyCapture2::FrameRate frame_rate)
884 FlyCapture2::Error error;
885 bool supported =
false;
886 error =
m_camera.GetVideoModeAndFrameRateInfo(video_mode, frame_rate, &supported);
887 if (error != FlyCapture2::PGRERROR_OK) {
888 error.PrintErrorTrace();
902 if (size == 0 || size > max_size)
905 size = size / step * step;
906 const unsigned int offset = (max_size - size) / 2;
908 return std::make_pair(size, offset);
946 unsigned int w,
unsigned int h)
950 FlyCapture2::Format7Info fmt7_info;
952 FlyCapture2::Error error;
954 fmt7_info.mode = format7_mode;
955 error =
m_camera.GetFormat7Info(&fmt7_info, &fmt7_supported);
956 if (error != FlyCapture2::PGRERROR_OK) {
957 error.PrintErrorTrace();
960 if (!fmt7_supported) {
964 FlyCapture2::Format7ImageSettings fmt7_settings;
965 fmt7_settings.mode = format7_mode;
966 fmt7_settings.pixelFormat = pixel_format;
968 std::pair<unsigned int, unsigned int> roi_w = this->
centerRoi(w, fmt7_info.maxWidth, fmt7_info.imageHStepSize);
969 std::pair<unsigned int, unsigned int> roi_h = this->
centerRoi(h, fmt7_info.maxHeight, fmt7_info.imageVStepSize);
970 fmt7_settings.width = roi_w.first;
971 fmt7_settings.offsetX = roi_w.second;
972 fmt7_settings.height = roi_h.first;
973 fmt7_settings.offsetY = roi_h.second;
976 FlyCapture2::Format7PacketInfo fmt7_packet_info;
978 error =
m_camera.ValidateFormat7Settings(&fmt7_settings, &valid, &fmt7_packet_info);
979 if (error != FlyCapture2::PGRERROR_OK) {
980 error.PrintErrorTrace();
986 error =
m_camera.SetFormat7Configuration(&fmt7_settings, fmt7_packet_info.recommendedBytesPerPacket);
987 if (error != FlyCapture2::PGRERROR_OK) {
988 error.PrintErrorTrace();
1000 FlyCapture2::Format7Info fmt7_info;
1001 bool supported =
false;
1002 FlyCapture2::Error error;
1004 fmt7_info.mode = format7_mode;
1005 error =
m_camera.GetFormat7Info(&fmt7_info, &supported);
1006 if (error != FlyCapture2::PGRERROR_OK) {
1007 error.PrintErrorTrace();
1024 FlyCapture2::Error error;
1026 if (error != FlyCapture2::PGRERROR_OK) {
1027 error.PrintErrorTrace();
1048 FlyCapture2::Error error;
1050 if (error != FlyCapture2::PGRERROR_OK) {
1051 error.PrintErrorTrace();
1070 FlyCapture2::Error error;
1076 FlyCapture2::BusManager busMgr;
1079 if (error != FlyCapture2::PGRERROR_OK) {
1080 error.PrintErrorTrace();
1085 if (error != FlyCapture2::PGRERROR_OK) {
1086 error.PrintErrorTrace();
1106 FlyCapture2::Error error;
1108 if (error != FlyCapture2::PGRERROR_OK) {
1109 error.PrintErrorTrace();
1147 FlyCapture2::TimeStamp timestamp;
1162 FlyCapture2::Error error;
1165 if (error != FlyCapture2::PGRERROR_OK) {
1166 error.PrintErrorTrace();
1180 sizeof(
unsigned char) * I.
getSize(), FlyCapture2::PIXEL_FORMAT_MONO8);
1183 error =
m_rawImage.Convert(FlyCapture2::PIXEL_FORMAT_MONO8, &convertedImage);
1184 if (error != FlyCapture2::PGRERROR_OK) {
1185 error.PrintErrorTrace();
1198 FlyCapture2::TimeStamp timestamp;
1213 FlyCapture2::Error error;
1216 if (error != FlyCapture2::PGRERROR_OK) {
1217 error.PrintErrorTrace();
1223 FlyCapture2::Image convertedImage;
1226 error =
m_rawImage.Convert(FlyCapture2::PIXEL_FORMAT_RGBU, &convertedImage);
1227 if (error != FlyCapture2::PGRERROR_OK) {
1228 error.PrintErrorTrace();
1232 height = convertedImage.GetRows();
1233 width = convertedImage.GetCols();
1236 unsigned char *data = convertedImage.GetData();
1237 unsigned int stride = convertedImage.GetStride();
1238 unsigned int Bps = convertedImage.GetBitsPerPixel() / 8;
1242 for (
unsigned int i = 0; i <
height; ++i) {
1243 for (
unsigned int j = 0; j <
width; ++j) {
1244 unsigned char *pp = data + i * stride + j * Bps;
1299 const unsigned int powerReg = 0x400;
1300 unsigned int powerRegVal = 0;
1302 FlyCapture2::Error error;
1303 error =
m_camera.ReadRegister(powerReg, &powerRegVal);
1304 if (error != FlyCapture2::PGRERROR_OK) {
1308 return ((powerRegVal & 0x00008000) != 0);
1320 const unsigned int powerReg = 0x610;
1321 unsigned int powerRegVal = 0;
1323 FlyCapture2::Error error;
1324 error =
m_camera.ReadRegister(powerReg, &powerRegVal);
1325 if (error != FlyCapture2::PGRERROR_OK) {
1329 return ((powerRegVal & (0x1 << 31)) != 0);
1373 const unsigned int powerReg = 0x610;
1374 unsigned int powerRegVal = 0;
1376 powerRegVal = (on ==
true) ? 0x80000000 : 0x0;
1378 FlyCapture2::Error error;
1379 error =
m_camera.WriteRegister(powerReg, powerRegVal);
1380 if (error != FlyCapture2::PGRERROR_OK) {
1381 error.PrintErrorTrace();
1385 unsigned int millisecondsToSleep = 100;
1386 unsigned int regVal = 0;
1387 unsigned int retries = 10;
1392 error =
m_camera.ReadRegister(powerReg, ®Val);
1393 if (error == FlyCapture2::PGRERROR_TIMEOUT) {
1397 else if (error != FlyCapture2::PGRERROR_OK) {
1398 error.PrintErrorTrace();
1403 }
while ((regVal & powerRegVal) == 0 && retries > 0);
1406 if (error == FlyCapture2::PGRERROR_TIMEOUT) {
1407 error.PrintErrorTrace();
1466 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)