第一次提交:
1、继承resonon相机库虚类(imager_base.h),实现了控制ximea相机的控制类库; 2、在ximea相机控制类(irisximeaimager.h)中,加入了定制的7个函数(setGainOffset、setRoi等等);
This commit is contained in:
462
Source_Files/irisximeaimager.cpp
Normal file
462
Source_Files/irisximeaimager.cpp
Normal file
@ -0,0 +1,462 @@
|
||||
#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)
|
||||
{
|
||||
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));//***********************************
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Iris::IrisXimeaImager::setSpatialBin(int spatialBin)
|
||||
{
|
||||
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));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::getSpectralBin()
|
||||
{
|
||||
int spectralBin = 0;
|
||||
CE(xiGetParamInt(m_xiH, XI_PRM_BINNING_VERTICAL, &spectralBin));
|
||||
|
||||
return spectralBin;
|
||||
}
|
||||
|
||||
int Iris::IrisXimeaImager::getSpatialBin()
|
||||
{
|
||||
int spatialBin = 0;
|
||||
CE(xiGetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL, &spatialBin));
|
||||
|
||||
return spatialBin;
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::setRoi(int OffsetX, int width, int OffsetY, int height)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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相机,这句代码都过不去
|
||||
|
||||
//设置数据格式
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Iris::IrisXimeaImager::disconnect()
|
||||
{
|
||||
printf("Closing camera...\n");
|
||||
CE(xiCloseDevice(m_xiH));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// //Reads the current timestamp value from camera in nanoseconds.
|
||||
// m_timestampOfCamera=0;
|
||||
// DWORD size=sizeof(m_timestampOfCamera);
|
||||
// XI_PRM_TYPE type=xiTypeInteger64;
|
||||
// xiGetParam(m_xiH, XI_PRM_TIMESTAMP,&m_timestampOfCamera,&size,&type);
|
||||
|
||||
CE(xiGetImage(m_xiH, 5000, &m_image)); // getting next image from the camera opened
|
||||
|
||||
|
||||
// int buffer_policy=0;//
|
||||
// xiGetParamInt(m_xiH, XI_PRM_BUFFER_POLICY,&buffer_policy);
|
||||
//// XI_BP_UNSAFE =0, // User gets pointer to internally allocated circle buffer and data may be overwritten by device.
|
||||
//// XI_BP_SAFE =1, // Data from device will be copied to user allocated buffer or xiApi allocated memory.
|
||||
//
|
||||
//
|
||||
// int b1=m_image.width*m_image.height*2;
|
||||
// int b2=m_image.size;//结构体XI_IMG的大小
|
||||
int b3=m_image.bp_size;//一般b1==b3
|
||||
// int b4=0;
|
||||
// xiGetParamInt(m_xiH, XI_PRM_IMAGE_PAYLOAD_SIZE,&b4);
|
||||
|
||||
|
||||
// std::cout<<"b1="<<b1<<std::endl;
|
||||
// std::cout<<"b2="<<b2<<std::endl;
|
||||
// std::cout<<"b3="<<b3<<std::endl;
|
||||
// std::cout<<"b4="<<b4<<std::endl;
|
||||
// std::cout<<"buffer_policy="<<buffer_policy<<std::endl;
|
||||
|
||||
|
||||
//方法1:memcpy
|
||||
memcpy(buffer,m_image.bp,b3);//*2是因为memcpy拷贝的单位是字节数
|
||||
// //方法2:此做法是错误的,虽然是指针,也是传值!
|
||||
// buffer = (unsigned short *)m_image.bp;
|
||||
|
||||
//强制将指针从高精度(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()
|
||||
{
|
||||
int height;
|
||||
CE(xiGetParamInt(m_xiH, XI_PRM_HEIGHT, &height));
|
||||
return height;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
int width;
|
||||
CE(xiGetParamInt(m_xiH, XI_PRM_WIDTH, &width));
|
||||
return width;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user