2022-06-27 21:06:14 +08:00
# include "Header_Files/irisximeaimager.h"
void Iris : : IrisXimeaImager : : setGainOffset ( float gain , float offset )
{
m_fGain = gain ;
m_fOffset = offset ;
}
bool Iris : : IrisXimeaImager : : setSpectralBin ( int spectralBin )
{
2022-10-30 23:56:17 +08:00
// CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_SELECTOR, XI_BIN_SELECT_HOST_CPU));//用: XI_BIN_SELECT_HOST_CPU; 默认为XI_BIN_SELECT_SENSOR(会报错), 不可用: XI_BIN_SELECT_DEVICE_FPGA
// CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_VERTICAL_MODE, XI_BIN_MODE_SUM));
// CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_VERTICAL, spectralBin));//***********************************
CE ( xiSetParamInt ( m_xiH , XI_PRM_DECIMATION_SELECTOR , XI_DEC_SELECT_SENSOR ) ) ;
CE ( xiSetParamInt ( m_xiH , XI_PRM_DECIMATION_VERTICAL , spectralBin ) ) ;
2022-06-27 21:06:14 +08:00
2022-08-23 10:20:04 +08:00
m_iSpectralBin = spectralBin ;
2022-06-27 21:06:14 +08:00
return true ;
}
bool Iris : : IrisXimeaImager : : setSpatialBin ( int spatialBin )
{
2022-10-30 23:56:17 +08:00
// CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_SELECTOR, XI_BIN_SELECT_HOST_CPU));//用: XI_BIN_SELECT_HOST_CPU; 默认为XI_BIN_SELECT_SENSOR(会报错), 不可用: XI_BIN_SELECT_DEVICE_FPGA
//
// CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL_MODE, XI_BIN_MODE_SUM));
// CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL, spatialBin));
2022-06-27 21:06:14 +08:00
2022-10-30 23:56:17 +08:00
CE ( xiSetParamInt ( m_xiH , XI_PRM_DECIMATION_SELECTOR , XI_DEC_SELECT_SENSOR ) ) ;
CE ( xiSetParamInt ( m_xiH , XI_PRM_DECIMATION_HORIZONTAL , spatialBin ) ) ;
2022-06-27 21:06:14 +08:00
2022-08-23 10:20:04 +08:00
m_iSpatialBin = spatialBin ;
2022-06-27 21:06:14 +08:00
return true ;
}
int Iris : : IrisXimeaImager : : getSpectralBin ( )
{
int spectralBin = 0 ;
2022-10-30 23:56:17 +08:00
// CE(xiGetParamInt(m_xiH, XI_PRM_BINNING_VERTICAL, &spectralBin));
CE ( xiGetParamInt ( m_xiH , XI_PRM_DECIMATION_VERTICAL , & spectralBin ) ) ;
2022-06-27 21:06:14 +08:00
return spectralBin ;
}
int Iris : : IrisXimeaImager : : getSpatialBin ( )
{
int spatialBin = 0 ;
2022-10-30 23:56:17 +08:00
// CE(xiGetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL, &spatialBin));
CE ( xiGetParamInt ( m_xiH , XI_PRM_DECIMATION_HORIZONTAL , & spatialBin ) ) ;
2022-06-27 21:06:14 +08:00
return spatialBin ;
}
2022-08-23 10:20:04 +08:00
void Iris : : IrisXimeaImager : : setEffectiveWindow ( int OffsetX , int width , int OffsetY , int height )
2022-06-27 21:06:14 +08:00
{
CE ( xiSetParamInt ( m_xiH , XI_PRM_WIDTH , width ) ) ;
CE ( xiSetParamInt ( m_xiH , XI_PRM_OFFSET_X , OffsetX ) ) ;
CE ( xiSetParamInt ( m_xiH , XI_PRM_HEIGHT , height ) ) ;
CE ( xiSetParamInt ( m_xiH , XI_PRM_OFFSET_Y , OffsetY ) ) ;
2022-08-23 10:20:04 +08:00
m_iEffectiveWindow_OffsetX = OffsetX ;
m_iEffectiveWindow_width = width ;
m_iEffectiveWindow_OffsetY = OffsetY ;
m_iEffectiveWindow_height = height ;
2022-06-27 21:06:14 +08:00
}
2022-08-23 10:20:04 +08:00
void Iris : : IrisXimeaImager : : setEffectiveWindowRoi ( int OffsetX , int width )
2022-06-27 21:06:14 +08:00
{
2022-08-23 10:20:04 +08:00
m_iEffectiveWindowRoi_OffsetX = OffsetX ;
m_iEffectiveWindowRoi_width = width ;
}
2022-06-27 21:06:14 +08:00
2022-08-23 10:20:04 +08:00
int Iris : : IrisXimeaImager : : getBufferSizeOfOneFrame ( )
{
// if(m_xiH==NULL)
// return 0;
//
// start();
//
// //清空image缓存
// memset(&m_image, 0, sizeof(m_image));
// m_image.size = sizeof(XI_IMG);
//
// CE(xiGetImage(m_xiH, 5000, &m_image)); // getting next image from the camera opened
//
// stop();
//
// return static_cast<int>(m_image.bp_size);
2022-06-27 21:06:14 +08:00
2022-10-30 23:56:17 +08:00
return m_iEffectiveWindow_height * m_iEffectiveWindowRoi_width * 2 ;
2022-06-27 21:06:14 +08:00
}
2022-08-05 10:27:59 +08:00
float Iris : : IrisXimeaImager : : getTemperature ( )
{
float temperature = 0.0 ;
CE ( xiGetParamFloat ( m_xiH , XI_PRM_TEMP , & temperature ) ) ;
return temperature ;
}
2022-06-27 21:06:14 +08:00
Iris : : IrisXimeaImager : : IrisXimeaImager ( )
{
m_xiH = NULL ;
}
Iris : : IrisXimeaImager : : ~ IrisXimeaImager ( )
{
}
void Iris : : IrisXimeaImager : : connect ( const char * camera_serial_number )
{
printf ( " Iris::IrisXimeaImager::connect----1 打开相机(xiOpenDevice) \n " ) ;
CE ( xiOpenDevice ( 0 , & m_xiH ) ) ; //没有插上ximea相机,这句代码都过不去
2022-08-23 10:20:04 +08:00
int NUM_THREADS = 0 ;
xiGetParamInt ( m_xiH , XI_PRM_PROC_NUM_THREADS , & NUM_THREADS ) ;
printf ( " Iris::IrisXimeaImager::connect---- XI_PRM_PROC_NUM_THREADS默认值为%d \n " , NUM_THREADS ) ;
xiSetParamInt ( m_xiH , XI_PRM_PROC_NUM_THREADS , 8 ) ;
2022-06-27 21:06:14 +08:00
//设置数据格式
printf ( " Iris::IrisXimeaImager::connect----2 设置数据格式(xiSetParamInt) \n " ) ;
CE ( xiSetParamInt ( m_xiH , XI_PRM_IMAGE_DATA_FORMAT , XI_RAW16 ) ) ; //Default value: XI_MONO8
// //设置packing, 使用xiGetImage接收影像时不执行unpacking
// CE(xiSetParamInt(m_xiH, XI_PRM_OUTPUT_DATA_BIT_DEPTH, 12));//set 12 bit transport data width
// CE(xiSetParamInt(m_xiH, XI_PRM_OUTPUT_DATA_PACKING, XI_ON));//enable packing
// //使用xiGetImage接收影像时不执行unpacking
// CE(xiSetParamInt(m_xiH, XI_PRM_IMAGE_DATA_FORMAT, XI_FRM_TRANSPORT_DATA));//in this case, the function xiGetImage just set pointer to transport-buffer without any processing
//判断数据格式设置是否成功
int dataFortmat ;
CE ( xiGetParamInt ( m_xiH , XI_PRM_IMAGE_DATA_FORMAT , & dataFortmat ) ) ;
if ( dataFortmat = = XI_RAW16 )
{
printf ( " Iris::IrisXimeaImager::connect----当前数据格式设置成功, 设置为: XI_RAW16 \n " ) ;
}
else if ( dataFortmat = = XI_FRM_TRANSPORT_DATA )
{
printf ( " Iris::IrisXimeaImager::connect----当前数据格式设置成功, 设置为: XI_FRM_TRANSPORT_DATA \n " ) ;
}
else
{
printf ( " Iris::IrisXimeaImager::connect----2 数据格式设置失败! \n " ) ;
printf ( " Iris::IrisXimeaImager::connect----当前数据格式为:%d \n " , dataFortmat ) ;
}
2022-10-30 23:56:17 +08:00
2022-06-27 21:06:14 +08:00
}
void Iris : : IrisXimeaImager : : disconnect ( )
{
printf ( " Closing camera... \n " ) ;
CE ( xiCloseDevice ( m_xiH ) ) ;
2022-10-30 23:56:17 +08:00
m_xiH = NULL ;
2022-06-27 21:06:14 +08:00
}
void Iris : : IrisXimeaImager : : start ( )
{
CE ( xiStartAcquisition ( m_xiH ) ) ;
}
void Iris : : IrisXimeaImager : : stop ( )
{
//printf("Stopping acquisition...\n");
CE ( xiStopAcquisition ( m_xiH ) ) ;
}
void Iris : : IrisXimeaImager : : get_imager_type ( char * buffer , int buffer_size )
{
}
void Iris : : IrisXimeaImager : : get_serial_number ( char * buffer , int buffer_size )
{
}
void Iris : : IrisXimeaImager : : get_camera_serial_number ( char * buffer , int buffer_size )
{
}
void Iris : : IrisXimeaImager : : generate_configuration_report ( char * buffer , int buffer_size )
{
}
float Iris : : IrisXimeaImager : : get_coeff_a ( )
{
return 0 ;
}
float Iris : : IrisXimeaImager : : get_coeff_b ( )
{
return 0 ;
}
float Iris : : IrisXimeaImager : : get_coeff_c ( )
{
return 0 ;
}
double Iris : : IrisXimeaImager : : get_wavelength_at_band ( const int band )
{
//sn008
float a = 1.999564 ;
float b = - 279.893 ;
//
float wavelength = band * m_fGain + m_fOffset ;
return wavelength ;
}
int Iris : : IrisXimeaImager : : get_frame_buffer_size_in_bytes ( )
{
return 0 ;
}
unsigned short * Iris : : IrisXimeaImager : : get_frame ( unsigned short * buffer )
{
//清空image缓存
memset ( & m_image , 0 , sizeof ( m_image ) ) ;
m_image . size = sizeof ( XI_IMG ) ;
CE ( xiGetImage ( m_xiH , 5000 , & m_image ) ) ; // getting next image from the camera opened
//方法1:memcpy
2022-08-23 10:20:04 +08:00
// memcpy(buffer,m_image.bp,m_image.bp_size);
2022-06-27 21:06:14 +08:00
// //方法2:此做法是错误的,虽然是指针,也是传值!
// buffer = (unsigned short *)m_image.bp;
2022-08-23 10:20:04 +08:00
for ( int i = 0 ; i < m_iEffectiveWindow_height ; i + + )
{
memcpy ( buffer + i * m_iEffectiveWindowRoi_width , ( unsigned short * ) m_image . bp + i * m_iEffectiveWindow_width + m_iEffectiveWindowRoi_OffsetX , m_iEffectiveWindowRoi_width * 2 ) ;
}
2022-06-27 21:06:14 +08:00
//强制将指针从高精度( uint64_t*) 转换到低精度( unsigned short *),会有精度降低的问题???????????????????????????????????????????????????
return ( unsigned short * ) & m_timestampOfCamera ;
}
uint64_t Iris : : IrisXimeaImager : : get_last_timestamp ( )
{
return 0 ;
}
uint64_t Iris : : IrisXimeaImager : : ticks_per_second ( )
{
return 0 ;
}
void Iris : : IrisXimeaImager : : set_spectral_bin ( int new_spectral_bin )
{
CE ( xiSetParamInt ( m_xiH , XI_PRM_BINNING_SELECTOR , XI_BIN_SELECT_HOST_CPU ) ) ; //用: XI_BIN_SELECT_HOST_CPU; 默认为XI_BIN_SELECT_SENSOR(会报错), 不可用: XI_BIN_SELECT_DEVICE_FPGA
CE ( xiSetParamInt ( m_xiH , XI_PRM_BINNING_VERTICAL_MODE , XI_BIN_MODE_SUM ) ) ;
CE ( xiSetParamInt ( m_xiH , XI_PRM_BINNING_VERTICAL , new_spectral_bin ) ) ;
// CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL_MODE, XI_BIN_MODE_SUM));
// CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL, x));
}
int Iris : : IrisXimeaImager : : get_spectral_bin ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_min_spectral_bin ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_max_spectral_bin ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_band_count ( )
{
2022-08-23 10:20:04 +08:00
return m_iEffectiveWindow_height ;
2022-06-27 21:06:14 +08:00
}
int Iris : : IrisXimeaImager : : get_start_band ( )
{
int WindowStartLine ;
CE ( xiGetParamInt ( m_xiH , XI_PRM_OFFSET_Y , & WindowStartLine ) ) ;
return WindowStartLine ;
}
void Iris : : IrisXimeaImager : : set_start_band ( int band )
{
}
int Iris : : IrisXimeaImager : : get_min_start_band ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_max_start_band ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_inc_start_band ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_end_band ( )
{
int height ;
CE ( xiGetParamInt ( m_xiH , XI_PRM_HEIGHT , & height ) ) ;
return get_start_band ( ) + height ;
}
void Iris : : IrisXimeaImager : : set_end_band ( int band )
{
}
int Iris : : IrisXimeaImager : : get_min_end_band ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_max_end_band ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_inc_end_band ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_sample_count ( )
{
2022-10-30 23:56:17 +08:00
return m_iEffectiveWindowRoi_width ;
2022-06-27 21:06:14 +08:00
}
int Iris : : IrisXimeaImager : : get_start_sample ( )
{
return 0 ;
}
void Iris : : IrisXimeaImager : : set_start_sample ( int sample )
{
}
int Iris : : IrisXimeaImager : : get_min_start_sample ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_max_start_sample ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_inc_start_sample ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_end_sample ( )
{
return 0 ;
}
void Iris : : IrisXimeaImager : : set_end_sample ( int sample )
{
}
int Iris : : IrisXimeaImager : : get_min_end_sample ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_max_end_sample ( )
{
return 0 ;
}
int Iris : : IrisXimeaImager : : get_inc_end_sample ( )
{
return 0 ;
}
void Iris : : IrisXimeaImager : : set_framerate ( const double frames_per_second )
{
CE ( xiSetParamInt ( m_xiH , XI_PRM_ACQ_TIMING_MODE , XI_ACQ_TIMING_MODE_FRAME_RATE_LIMIT ) ) ;
CE ( xiSetParamFloat ( m_xiH , XI_PRM_FRAMERATE , frames_per_second ) ) ;
}
double Iris : : IrisXimeaImager : : get_framerate ( )
{
float framerate ;
CE ( xiGetParamFloat ( m_xiH , XI_PRM_FRAMERATE , & framerate ) ) ;
return framerate ;
}
double Iris : : IrisXimeaImager : : get_min_framerate ( )
{
return 0 ;
}
double Iris : : IrisXimeaImager : : get_max_framerate ( )
{
return 0 ;
}
double Iris : : IrisXimeaImager : : get_min_integration_time ( )
{
return 0 ;
}
double Iris : : IrisXimeaImager : : get_max_integration_time ( )
{
return 0 ;
}
void Iris : : IrisXimeaImager : : set_integration_time ( const double microsecond )
{
CE ( xiSetParamInt ( m_xiH , XI_PRM_EXPOSURE , microsecond ) ) ; //time_in_us(microseconds)
}
double Iris : : IrisXimeaImager : : get_integration_time ( )
{
float exposureTime ;
CE ( xiGetParamFloat ( m_xiH , XI_PRM_EXPOSURE , & exposureTime ) ) ; //time_in_us(microseconds)
return exposureTime ;
}
void Iris : : IrisXimeaImager : : set_gain ( const double gain )
{
CE ( xiSetParamFloat ( m_xiH , XI_PRM_GAIN , gain ) ) ; //gain_in_db
}
double Iris : : IrisXimeaImager : : get_gain ( )
{
float gain ;
CE ( xiGetParamFloat ( m_xiH , XI_PRM_GAIN , & gain ) ) ;
return gain ;
}
double Iris : : IrisXimeaImager : : get_min_gain ( )
{
return 0 ;
}
double Iris : : IrisXimeaImager : : get_max_gain ( )
{
return 0 ;
}
void Iris : : IrisXimeaImager : : set_internal_trigger ( )
{
}
void Iris : : IrisXimeaImager : : set_external_trigger ( unsigned int signal_line , bool rising_edge )
{
}
bool Iris : : IrisXimeaImager : : is_trigger_external ( )
{
return 0 ;
}