Loading
 
Support Support Home » USB3 » Compatible hardware » High Performance Hardware » How to optimize software performance on high frame rates

How to optimize software performance on high frame rates?


In order to receive all images in case of high frame rate and/or small height of image (ROI) is used - it is necessary to:
  • increase value of XI_PRM_BUFFERS_QUEUE_SIZE
  • decrease value of XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE


See xiAPI Manual for details.

Simplified implementation example

Example of initialization code:

#define HandleResult(res,place) if (res!=XI_OK) {printf("Error after %s (%d)\n",place,res);goto finish;}
XI_RETURN stat = XI_OK;
stat = xiOpenDevice(0, &xiH);
HandleResult(stat,"xiOpenDevice");

// set ROI height
int height=200;
stat = xiSetParamInt(xiH, XI_PRM_HEIGHT, height);
HandleResult(stat,"xiSetParam (height)");
int payload=0;
stat = xiGetParamInt(xiH, XI_PRM_IMAGE_PAYLOAD_SIZE, &payload);
HandleResult(stat,"xiGetParam (payload)");

// ---------------------------------------------------
// select transport buffer size depending on 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(xiH, XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE, &transport_buffer_size_default);
HandleResult(stat,"xiGetParamInt (transport buffer size)");
stat = xiGetParamInt(xiH, XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE XI_PRM_INFO_INCREMENT, &transport_buffer_size_increment);
HandleResult(stat,"xiGetParamInt (transport buffer size increment)");
stat = xiGetParamInt(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(xiH, XI_PRM_ACQ_TRANSPORT_BUFFER_SIZE, transport_buffer_size);
    HandleResult(stat,"xiSetParam (transport buffer size)");
}

// ---------------------------------------------------
// set maximum number of queue
int number_of_field_buffers = 0;
xiGetParamInt(xiH, XI_PRM_BUFFERS_QUEUE_SIZE XI_PRM_INFO_MAX, &number_of_field_buffers);
HandleResult(stat,"xiGetParam (number_of_field_buffers maximum)");
xiSetParamInt(xiH, XI_PRM_BUFFERS_QUEUE_SIZE, number_of_field_buffers);
HandleResult(stat,"xiSetParam (number_of_field_buffers)");

xiStartAcquisition(xiH);

// getting images in loop