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;
208 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::FRAME_RATE);
209 return prop.absValue;
228 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHUTTER);
229 return prop.absValue;
248 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::GAIN);
249 return prop.absValue;
268 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::BRIGHTNESS);
269 return prop.absValue;
288 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHARPNESS);
308 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::AUTO_EXPOSURE);
309 return prop.absValue;
346 if (index >= num_cameras) {
348 index, num_cameras));
350 unsigned int serial_id;
351 FlyCapture2::BusManager busMgr;
352 FlyCapture2::Error error;
353 error = busMgr.GetCameraSerialNumberFromIndex(index, &serial_id);
354 if (error != FlyCapture2::PGRERROR_OK) {
355 error.PrintErrorTrace();
417 FlyCapture2::BusManager busMgr;
418 FlyCapture2::Error error;
443 FlyCapture2::PropertyInfo propInfo;
446 if (propInfo.present) {
447 FlyCapture2::Property prop;
448 prop.type = prop_type;
449 prop.onOff = on && propInfo.onOffSupported;
450 prop.autoManualMode = auto_on && propInfo.autoSupported;
451 prop.absControl = propInfo.absValSupported;
452 switch (prop_value) {
454 float value_ = (std::max)((std::min)((float)value, (
float)propInfo.absMax), (
float)propInfo.absMin);
455 prop.absValue = value_;
459 unsigned int value_ =
460 (std::max)((std::min)((
unsigned int)value, (
unsigned int)propInfo.max), (
unsigned int)propInfo.min);
461 prop.valueA = value_;
466 FlyCapture2::Error error;
467 error =
m_camera.SetProperty(&prop);
468 if (error != FlyCapture2::PGRERROR_OK) {
469 error.PrintErrorTrace();
511 this->
setProperty(FlyCapture2::FRAME_RATE,
true,
false, frame_rate);
512 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::FRAME_RATE);
513 return prop.absValue;
554 this->
setProperty(FlyCapture2::SHUTTER,
true, auto_shutter, shutter_ms);
555 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHUTTER);
556 return prop.absValue;
598 this->
setProperty(FlyCapture2::GAIN,
true, gain_auto, gain_value);
599 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::GAIN);
600 return prop.absValue;
642 this->
setProperty(FlyCapture2::BRIGHTNESS,
true, brightness_auto, brightness_value);
643 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::BRIGHTNESS);
644 return prop.absValue;
695 this->
setProperty(FlyCapture2::AUTO_EXPOSURE, exposure_on, exposure_auto, exposure_value);
696 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::AUTO_EXPOSURE);
697 return prop.absValue;
742 this->
setProperty(FlyCapture2::SHARPNESS, sharpness_on, sharpness_auto, (
float)sharpness_value,
VALUE_A);
743 FlyCapture2::Property prop = this->
getProperty(FlyCapture2::SHARPNESS);
755 FlyCapture2::Property prop;
756 prop.type = prop_type;
757 FlyCapture2::Error error;
758 error =
m_camera.GetProperty(&prop);
759 if (error != FlyCapture2::PGRERROR_OK) {
760 error.PrintErrorTrace();
775 FlyCapture2::PropertyInfo propInfo;
776 propInfo.type = prop_type;
778 FlyCapture2::Error error;
779 error =
m_camera.GetPropertyInfo(&propInfo);
780 if (error != FlyCapture2::PGRERROR_OK) {
781 error.PrintErrorTrace();
821 FlyCapture2::Error error;
822 error =
m_camera.SetVideoModeAndFrameRate(video_mode, frame_rate);
823 if (error != FlyCapture2::PGRERROR_OK) {
824 error.PrintErrorTrace();
833 FlyCapture2::FrameRate frame_rate)
837 FlyCapture2::Error error;
838 bool supported =
false;
839 error =
m_camera.GetVideoModeAndFrameRateInfo(video_mode, frame_rate, &supported);
840 if (error != FlyCapture2::PGRERROR_OK) {
841 error.PrintErrorTrace();
855 if (size == 0 || size > max_size)
858 size = size / step * step;
859 const unsigned int offset = (max_size - size) / 2;
861 return std::make_pair(size, offset);
898 unsigned int w,
unsigned int h)
902 FlyCapture2::Format7Info fmt7_info;
904 FlyCapture2::Error error;
906 fmt7_info.mode = format7_mode;
907 error =
m_camera.GetFormat7Info(&fmt7_info, &fmt7_supported);
908 if (error != FlyCapture2::PGRERROR_OK) {
909 error.PrintErrorTrace();
912 if (!fmt7_supported) {
916 FlyCapture2::Format7ImageSettings fmt7_settings;
917 fmt7_settings.mode = format7_mode;
918 fmt7_settings.pixelFormat = pixel_format;
920 std::pair<unsigned int, unsigned int> roi_w = this->
centerRoi(w, fmt7_info.maxWidth, fmt7_info.imageHStepSize);
921 std::pair<unsigned int, unsigned int> roi_h = this->
centerRoi(h, fmt7_info.maxHeight, fmt7_info.imageVStepSize);
922 fmt7_settings.width = roi_w.first;
923 fmt7_settings.offsetX = roi_w.second;
924 fmt7_settings.height = roi_h.first;
925 fmt7_settings.offsetY = roi_h.second;
928 FlyCapture2::Format7PacketInfo fmt7_packet_info;
930 error =
m_camera.ValidateFormat7Settings(&fmt7_settings, &valid, &fmt7_packet_info);
931 if (error != FlyCapture2::PGRERROR_OK) {
932 error.PrintErrorTrace();
938 error =
m_camera.SetFormat7Configuration(&fmt7_settings, fmt7_packet_info.recommendedBytesPerPacket);
939 if (error != FlyCapture2::PGRERROR_OK) {
940 error.PrintErrorTrace();
952 FlyCapture2::Format7Info fmt7_info;
953 bool supported =
false;
954 FlyCapture2::Error error;
956 fmt7_info.mode = format7_mode;
957 error =
m_camera.GetFormat7Info(&fmt7_info, &supported);
958 if (error != FlyCapture2::PGRERROR_OK) {
959 error.PrintErrorTrace();
976 FlyCapture2::Error error;
978 if (error != FlyCapture2::PGRERROR_OK) {
979 error.PrintErrorTrace();
1000 FlyCapture2::Error error;
1002 if (error != FlyCapture2::PGRERROR_OK) {
1003 error.PrintErrorTrace();
1022 FlyCapture2::Error error;
1028 FlyCapture2::BusManager busMgr;
1031 if (error != FlyCapture2::PGRERROR_OK) {
1032 error.PrintErrorTrace();
1037 if (error != FlyCapture2::PGRERROR_OK) {
1038 error.PrintErrorTrace();
1058 FlyCapture2::Error error;
1060 if (error != FlyCapture2::PGRERROR_OK) {
1061 error.PrintErrorTrace();
1099 FlyCapture2::TimeStamp timestamp;
1114 FlyCapture2::Error error;
1117 if (error != FlyCapture2::PGRERROR_OK) {
1118 error.PrintErrorTrace();
1132 sizeof(
unsigned char) * I.
getSize(), FlyCapture2::PIXEL_FORMAT_MONO8);
1135 error =
m_rawImage.Convert(FlyCapture2::PIXEL_FORMAT_MONO8, &convertedImage);
1136 if (error != FlyCapture2::PGRERROR_OK) {
1137 error.PrintErrorTrace();
1150 FlyCapture2::TimeStamp timestamp;
1165 FlyCapture2::Error error;
1168 if (error != FlyCapture2::PGRERROR_OK) {
1169 error.PrintErrorTrace();
1175 FlyCapture2::Image convertedImage;
1178 error =
m_rawImage.Convert(FlyCapture2::PIXEL_FORMAT_RGBU, &convertedImage);
1179 if (error != FlyCapture2::PGRERROR_OK) {
1180 error.PrintErrorTrace();
1184 height = convertedImage.GetRows();
1185 width = convertedImage.GetCols();
1188 unsigned char *data = convertedImage.GetData();
1189 unsigned int stride = convertedImage.GetStride();
1190 unsigned int Bps = convertedImage.GetBitsPerPixel() / 8;
1194 for (
unsigned int i = 0; i <
height; ++i) {
1195 for (
unsigned int j = 0; j <
width; ++j) {
1196 unsigned char *pp = data + i * stride + j * Bps;
1251 const unsigned int powerReg = 0x400;
1252 unsigned int powerRegVal = 0;
1254 FlyCapture2::Error error;
1255 error =
m_camera.ReadRegister(powerReg, &powerRegVal);
1256 if (error != FlyCapture2::PGRERROR_OK) {
1260 return ((powerRegVal & 0x00008000) != 0);
1272 const unsigned int powerReg = 0x610;
1273 unsigned int powerRegVal = 0;
1275 FlyCapture2::Error error;
1276 error =
m_camera.ReadRegister(powerReg, &powerRegVal);
1277 if (error != FlyCapture2::PGRERROR_OK) {
1281 return ((powerRegVal & (0x1 << 31)) != 0);
1321 const unsigned int powerReg = 0x610;
1322 unsigned int powerRegVal = 0;
1324 powerRegVal = (on ==
true) ? 0x80000000 : 0x0;
1326 FlyCapture2::Error error;
1327 error =
m_camera.WriteRegister(powerReg, powerRegVal);
1328 if (error != FlyCapture2::PGRERROR_OK) {
1329 error.PrintErrorTrace();
1333 unsigned int millisecondsToSleep = 100;
1334 unsigned int regVal = 0;
1335 unsigned int retries = 10;
1340 error =
m_camera.ReadRegister(powerReg, ®Val);
1341 if (error == FlyCapture2::PGRERROR_TIMEOUT) {
1344 }
else if (error != FlyCapture2::PGRERROR_OK) {
1345 error.PrintErrorTrace();
1350 }
while ((regVal & powerRegVal) == 0 && retries > 0);
1353 if (error == FlyCapture2::PGRERROR_TIMEOUT) {
1354 error.PrintErrorTrace();
1406 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)