function detections = rok_ubisense_get_detections (ubisense, frame)
    % detections = ROK_UBISENSE_GET_DETECTIONS (ubisense, frame)
    %
    % Get detections from Ubisense.
    %
    % Input:
    %  - ubisense = an instance of @UbisenseDatabase
    %  - frame = frame for which to obtain detections
    %
    % Output:
    %  - detections = array of detection structures
    %
    % Copyright (C) 2012, Rok Mandeljc <rok.mandeljc@fe.uni-lj.si>
    
    % Get detections
    detections = [];
    count = 1;
    
    for t = 1:numel(ubisense.tags),
        tag = ubisense.tags{t};
        event = ubisense.get_event_by_frame(tag, frame, 'prev');
            
        if isempty(event),
            continue;
        end
    
        % Yeah, this is suboptimal, but we'll have to live with it...
        detections(count).x = event.x;
        detections(count).y = event.y;
        detections(count).id = t;      
        
        count = count+1;
    end
end