2022-06-27 21:06:14 +08:00
# include "Header_Files/irisximeaimager.h"
2023-04-01 21:25:09 +08:00
using namespace Iris ;
2022-06-27 21:06:14 +08:00
void Iris : : IrisXimeaImager : : setGainOffset ( float gain , float offset )
{
m_fGain = gain ;
m_fOffset = offset ;
}
bool Iris : : IrisXimeaImager : : setSpectralBin ( int spectralBin )
{
2023-06-26 19:00:48 +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_AVERAGE ) ) ;
CE ( xiSetParamInt ( m_xiH , XI_PRM_BINNING_VERTICAL , spectralBin ) ) ;
printf ( " Iris::IrisXimeaImager::setSpectralBin----2 设置bin模式为XI_PRM_BINNING_SELECTOR XI_BIN_MODE_AVERAGE ! \n " ) ;
2022-10-30 23:56:17 +08:00
2023-06-26 19:00:48 +08:00
// 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 )
{
2023-06-26 19:00:48 +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_AVERAGE ) ) ;
CE ( xiSetParamInt ( m_xiH , XI_PRM_BINNING_HORIZONTAL , spatialBin ) ) ;
printf ( " Iris::IrisXimeaImager::setSpatialBin----2 设置bin模式为XI_PRM_BINNING_SELECTOR XI_BIN_MODE_AVERAGE ! \n " ) ;
2022-10-30 23:56:17 +08:00
2022-06-27 21:06:14 +08:00
2023-06-26 19:00:48 +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 ;
2023-06-27 11:34:59 +08:00
CE ( xiGetParamInt ( m_xiH , XI_PRM_BINNING_VERTICAL , & spectralBin ) ) ;
2022-10-30 23:56:17 +08:00
2023-06-27 11:34:59 +08:00
// 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 ;
2023-06-27 11:34:59 +08:00
CE ( xiGetParamInt ( m_xiH , XI_PRM_BINNING_HORIZONTAL , & spatialBin ) ) ;
2022-10-30 23:56:17 +08:00
2023-06-27 11:34:59 +08:00
// 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
2023-06-26 15:59:26 +08:00
// //比实际大小( m_iEffectiveWindow_height * m_iEffectiveWindow_width * 2) 大, why?
// int value = 0;
// xiGetParamInt(m_xiH, XI_PRM_IMAGE_PAYLOAD_SIZE, &value);
2022-11-13 16:33:51 +08:00
return m_iEffectiveWindow_height * m_iEffectiveWindow_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 ;
}
2023-06-26 15:59:26 +08:00
void Iris : : IrisXimeaImager : : setBufferPolicy ( int bufferPolicy )
{
if ( bufferPolicy = = 0 )
{
xiSetParamInt ( m_xiH , XI_PRM_BUFFER_POLICY , XI_BP_UNSAFE ) ;
printf ( " Iris::IrisXimeaImager::connect---- XI_PRM_BUFFER_POLICY: XI_BP_UNSAFE \n " ) ;
}
else if ( bufferPolicy = = 1 )
{
xiSetParamInt ( m_xiH , XI_PRM_BUFFER_POLICY , XI_BP_SAFE ) ;
printf ( " Iris::IrisXimeaImager::connect---- XI_PRM_BUFFER_POLICY: XI_BP_SAFE \n " ) ;
}
}
void Iris : : IrisXimeaImager : : setAcqBufferSize ( int acqBufferSize )
{
XI_RETURN stat = XI_OK ;
// set unit to 1 MiB
xiSetParamInt ( m_xiH , XI_PRM_ACQ_BUFFER_SIZE_UNIT , 1024 * 1024 ) ;
int value = 0 ;
xiGetParamInt ( m_xiH , XI_PRM_ACQ_BUFFER_SIZE , & value ) ;
printf ( " Iris::IrisXimeaImager::connect---- XI_PRM_ACQ_BUFFER_SIZE: %d MiB. \n " , value ) ;
xiSetParamInt ( m_xiH , XI_PRM_ACQ_BUFFER_SIZE , acqBufferSize ) ;
xiGetParamInt ( m_xiH , XI_PRM_ACQ_BUFFER_SIZE , & value ) ;
printf ( " Iris::IrisXimeaImager::connect---- XI_PRM_ACQ_BUFFER_SIZE: %d MiB. \n " , value ) ;
// set maximum number of queue
int number_of_field_buffers = 0 ;
xiGetParamInt ( m_xiH , XI_PRM_BUFFERS_QUEUE_SIZE XI_PRM_INFO_MAX , & number_of_field_buffers ) ;
printf ( " Iris::IrisXimeaImager::connect---- XI_PRM_BUFFERS_QUEUE_SIZE XI_PRM_INFO_MAX: %d. \n " , number_of_field_buffers ) ;
HandleResult ( stat , " xiGetParam (number_of_field_buffers maximum) " ) ;
xiSetParamInt ( m_xiH , XI_PRM_BUFFERS_QUEUE_SIZE , number_of_field_buffers ) ;
HandleResult ( stat , " xiSetParam (number_of_field_buffers) " ) ;
}
2022-06-27 21:06:14 +08:00
Iris : : IrisXimeaImager : : IrisXimeaImager ( )
{
m_xiH = NULL ;
2023-07-04 21:20:43 +08:00
std : : cout < < " ximeaControlDll 版本: " < < " 21. " < < std : : endl ;
2022-06-27 21:06:14 +08:00
}
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相机,这句代码都过不去
2023-06-26 15:59:26 +08:00
//add-----------------------------------------------------------------------------------------------------------------------
XI_RETURN stat = XI_OK ;
int payload = 0 ;
stat = xiGetParamInt ( m_xiH , XI_PRM_IMAGE_PAYLOAD_SIZE , & payload ) ;
HandleResult ( stat , " xiGetParam (payload) " ) ;
int transport_buffer_size_default = 0 ;
int transport_buffer_size_increment = 0 ;
int transport_buffer_size_minimum = 0 ;
// get default transport buffer size - that should be OK on all controllers
stat = xiGetParamInt ( m_xiH , XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE , & transport_buffer_size_default ) ;
HandleResult ( stat , " xiGetParamInt (transport buffer size) " ) ;
stat = xiGetParamInt ( m_xiH , XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE XI_PRM_INFO_INCREMENT , & transport_buffer_size_increment ) ;
HandleResult ( stat , " xiGetParamInt (transport buffer size increment) " ) ;
stat = xiGetParamInt ( m_xiH , XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE XI_PRM_INFO_MIN , & transport_buffer_size_minimum ) ;
HandleResult ( stat , " xiGetParamInt (transport buffer size minimum) " ) ;
// check if payload size is less than default transport buffer size
if ( payload < transport_buffer_size_default + transport_buffer_size_increment )
{
// use optimized transport buffer size, as nearest increment to payload
int transport_buffer_size = payload ;
if ( transport_buffer_size_increment )
{
// round up to nearest increment
int remainder = transport_buffer_size % transport_buffer_size_increment ;
if ( remainder )
transport_buffer_size + = transport_buffer_size_increment - remainder ;
}
// check the minimum
if ( transport_buffer_size < transport_buffer_size_minimum )
transport_buffer_size = transport_buffer_size_minimum ;
stat = xiSetParamInt ( m_xiH , XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE , transport_buffer_size ) ;
HandleResult ( stat , " xiSetParam (transport buffer size) " ) ;
}
//add---------------------------------------------------------------------------------------------------------------------------------------------------------------
// set unit to 1 MiB
xiSetParamInt ( m_xiH , XI_PRM_ACQ_BUFFER_SIZE_UNIT , 1024 * 1024 ) ;
int value = 0 ;
xiGetParamInt ( m_xiH , XI_PRM_ACQ_BUFFER_SIZE , & value ) ;
printf ( " Iris::IrisXimeaImager::connect---- XI_PRM_ACQ_BUFFER_SIZE: %d MiB. \n " , value ) ;
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-11-13 16:33:51 +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-08-23 10:20:04 +08:00
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 )
{
}
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-11-13 16:33:51 +08:00
return m_iEffectiveWindow_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 ;
}