44 #include "vpPylonGrabberUsb.h"
46 #ifdef VISP_HAVE_PYLON
48 #include <visp3/core/vpException.h>
49 #include <visp3/core/vpTime.h>
71 Pylon::CTlFactory &TlFactory = Pylon::CTlFactory::GetInstance();
72 Pylon::DeviceInfoList_t lstDevices;
73 Pylon::DeviceInfoList_t filter;
74 Pylon::CBaslerUsbDeviceInfo usb_devinfo;
75 filter.push_back(usb_devinfo);
76 TlFactory.EnumerateDevices(lstDevices, filter);
78 m_numCameras = lstDevices.size();
91 Pylon::CDeviceInfo deviceInfo = m_camera.GetDeviceInfo();
93 GenApi::INodeMap &control = m_camera.GetNodeMap();
95 GenApi::CIntegerPtr widthMax = control.GetNode(
"WidthMax");
96 GenApi::CIntegerPtr heightMax = control.GetNode(
"HeightMax");
98 os <<
"Camera information: " << std::endl;
99 os <<
" Serial number : " << deviceInfo.GetSerialNumber() << std::endl;
100 os <<
" Camera model : " << deviceInfo.GetModelName() << std::endl;
101 os <<
" Camera vendor : " << deviceInfo.GetVendorName() << std::endl;
102 os <<
" Resolution : " << widthMax->GetValue() <<
"x" << heightMax->GetValue() << std::endl;
103 os <<
" Firmware version : " << deviceInfo.GetDeviceVersion() << std::endl;
118 if (m_connected ==
true) {
136 float frame_rate = m_camera.AcquisitionFrameRate.GetValue();
150 if (GenApi::IsReadable(m_camera.Gain))
151 return m_camera.Gain.GetValue();
171 if (GenApi::IsReadable(m_camera.BlackLevel))
172 return m_camera.BlackLevel.GetValue();
192 if (GenApi::IsReadable(m_camera.ExposureTime))
193 return m_camera.ExposureTime.GetValue() * 0.001;
208 float gamma = m_camera.Gamma.GetValue();
222 if (index >= m_numCameras) {
224 index, m_numCameras));
227 Pylon::CTlFactory &TlFactory = Pylon::CTlFactory::GetInstance();
228 Pylon::DeviceInfoList_t lstDevices;
229 Pylon::DeviceInfoList_t filter;
230 Pylon::CBaslerUsbDeviceInfo usb_devinfo;
231 filter.push_back(usb_devinfo);
232 TlFactory.EnumerateDevices(lstDevices, filter);
234 std::ostringstream os;
235 os << lstDevices[index].GetSerialNumber();
255 m_camera.UserSetLoad.Execute();
257 success = m_camera.UserSetLoad.IsDone();
273 Basler_UsbCameraParams::UserSetDefaultEnums user_set = m_camera.UserSetDefault.GetValue();
276 case Basler_UsbCameraParams::UserSetDefault_Default:
279 case Basler_UsbCameraParams::UserSetDefault_UserSet1:
282 case Basler_UsbCameraParams::UserSetDefault_UserSet2:
285 case Basler_UsbCameraParams::UserSetDefault_UserSet3:
311 if (index >= m_numCameras) {
313 index, m_numCameras));
328 for (
unsigned int i = 0; i < m_numCameras; i++) {
348 m_camera.AcquisitionFrameRate.SetValue(frame_rate);
350 return m_camera.AcquisitionFrameRate.GetValue();
371 m_camera.GainAuto.SetValue(Basler_UsbCameraParams::GainAuto_Continuous);
373 m_camera.GainAuto.SetValue(Basler_UsbCameraParams::GainAuto_Off);
375 if (GenApi::IsWritable(m_camera.Gain)) {
376 m_camera.Gain.SetValue(gain_value);
377 return m_camera.Gain.GetValue();
401 if (GenApi::IsWritable(m_camera.BlackLevel)) {
402 m_camera.BlackLevel.SetValue(blacklevel_value);
403 return m_camera.BlackLevel.GetValue();
431 m_camera.ExposureMode.SetValue(Basler_UsbCameraParams::ExposureMode_Timed);
433 m_camera.ExposureMode.SetValue(Basler_UsbCameraParams::ExposureMode_TriggerWidth);
436 m_camera.ExposureAuto.SetValue(Basler_UsbCameraParams::ExposureAuto_Continuous);
438 m_camera.ExposureAuto.SetValue(Basler_UsbCameraParams::ExposureAuto_Off);
440 if (GenApi::IsWritable(m_camera.ExposureTime)) {
441 m_camera.ExposureTime.SetValue(exposure_value * 1000);
442 return m_camera.ExposureTime.GetValue() * 0.001;
464 if (GenApi::IsWritable(m_camera.Gamma)) {
466 m_camera.Gamma.SetValue(gamma_value);
468 m_camera.Gamma.SetValue(1);
469 return m_camera.Gamma.GetValue();
493 m_camera.UserSetSave.Execute();
495 success = m_camera.UserSetSave.IsDone();
498 if (success && set_default)
519 m_camera.UserSetDefault.SetValue(Basler_UsbCameraParams::UserSetDefault_Default);
523 m_camera.UserSetDefault.SetValue(Basler_UsbCameraParams::UserSetDefault_UserSet1);
527 m_camera.UserSetDefault.SetValue(Basler_UsbCameraParams::UserSetDefault_UserSet2);
531 m_camera.UserSetDefault.SetValue(Basler_UsbCameraParams::UserSetDefault_UserSet3);
548 if (!m_camera.IsGrabbing()) {
549 m_camera.StartGrabbing(1);
551 if (m_connected && m_camera.IsGrabbing())
564 if (m_camera.IsGrabbing()) {
565 m_camera.StopGrabbing();
567 if (m_connected && m_camera.IsGrabbing())
580 if (m_connected ==
false) {
582 if (m_numCameras == 0) {
586 if (!m_camera.IsPylonDeviceAttached()) {
587 Pylon::CTlFactory &TlFactory = Pylon::CTlFactory::GetInstance();
588 Pylon::DeviceInfoList_t lstDevices;
589 Pylon::DeviceInfoList_t filter;
590 Pylon::CBaslerUsbDeviceInfo usb_devinfo;
591 filter.push_back(usb_devinfo);
592 TlFactory.EnumerateDevices(lstDevices, filter);
594 m_camera.Attach(TlFactory.CreateDevice(lstDevices[m_index]));
600 if (m_connected && m_camera.IsGrabbing())
613 if (m_connected ==
true) {
617 if (m_connected && m_camera.IsGrabbing())
646 Pylon::CGrabResultPtr grabResult;
648 if (!m_camera.RetrieveResult(2000, grabResult)) {
653 if (grabResult->GrabSucceeded()) {
654 height = grabResult->GetHeight();
655 width = grabResult->GetWidth();
658 Pylon::CImageFormatConverter imageConvert;
659 imageConvert.OutputPixelFormat = Pylon::PixelType_Mono8;
660 imageConvert.OutputPaddingX = 0;
662 imageConvert.Convert(I.
bitmap,
sizeof(
unsigned char) *
width *
height, (Pylon::IImage &)grabResult);
675 Pylon::CGrabResultPtr grabResult;
677 if (!m_camera.RetrieveResult(2000, grabResult)) {
682 if (grabResult->GrabSucceeded()) {
683 height = grabResult->GetHeight();
684 width = grabResult->GetWidth();
687 Pylon::CImageFormatConverter imageConvert;
688 imageConvert.OutputPixelFormat = Pylon::PixelType_BGRA8packed;
689 imageConvert.OutputPaddingX = 0;
691 Pylon::CPylonImage destImage;
692 imageConvert.Convert(destImage, (Pylon::IImage &)grabResult);
693 Pylon::SBGRA8Pixel *pixel = (Pylon::SBGRA8Pixel *)destImage.GetBuffer();
694 for (
unsigned int i = 0; i <
height; i++) {
695 for (
unsigned int j = 0; j <
width; j++) {
696 unsigned int p_index = i *
width + j;
697 I[i][j].R = pixel[p_index].R;
698 I[i][j].G = pixel[p_index].G;
699 I[i][j].B = pixel[p_index].B;
700 I[i][j].A = pixel[p_index].A;
757 m_camera.UserSetSelector.SetValue(Basler_UsbCameraParams::UserSetSelector_Default);
761 m_camera.UserSetSelector.SetValue(Basler_UsbCameraParams::UserSetSelector_UserSet1);
765 m_camera.UserSetSelector.SetValue(Basler_UsbCameraParams::UserSetSelector_UserSet2);
769 m_camera.UserSetSelector.SetValue(Basler_UsbCameraParams::UserSetSelector_UserSet3);
800 void dummy_vpPylonGrabberUsb() { };
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
@ notImplementedError
Not implemented.
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
Type * bitmap
points toward the bitmap
bool loadUserSet(UserSetName user_set)
Loads the selected configuration into the camera's volatile memory and makes it the active configurat...
vpPylonGrabber & operator>>(vpImage< unsigned char > &I)
unsigned int getNumCameras()
float setBlackLevel(float blacklevel_value=0)
Pylon::CInstantCamera * getCameraHandler()
std::ostream & getCameraInfo(std::ostream &os)
float setFrameRate(float frame_rate)
float setGamma(bool gamma_on, float gamma_value=1)
bool setUserSetDefault(UserSetName user_set)
Sets the configuration set to be used as the default startup set.
UserSetName getUserSetDefault()
Gets the configuration set being used as the default startup set.
void close()
Stop active camera capturing images and disconnect the active camera.
bool selectUserSet(UserSetName user_set)
Selects the configuration set to load, save, or configure.
void setCameraIndex(unsigned int index)
bool saveUserSet(UserSetName user_set, bool set_default=false)
Saves the current active configuration set into the selected user set.
std::string getCameraSerial(unsigned int index)
void acquire(vpImage< unsigned char > &I)
virtual ~vpPylonGrabberUsb()
float setExposure(bool exposure_on, bool exposure_auto, float exposure_value=0)
void setCameraSerial(const std::string &serial)
float setGain(bool gain_auto, float gain_value=0)
@ USERSET_DEFAULT
The default user set.
@ USERSET_UNKNOWN
User set not supported.
@ USERSET_USERSET1
User set 1.
@ USERSET_USERSET3
User set 3.
@ USERSET_USERSET2
User set 2.
VISP_EXPORT int wait(double t0, double t)