def write_event_to_acq(events, acq):
    """Writes events to a given acq. Usualy to save the file later on.
    Inputs :    - events : array of dictionnary containing "label", "context"
                    and "frame" key when each element of the array represents
                    a single event.
                - acq : the aquisition file writer to write to
    Outputs :   - acq : the updated acq given as entry argument
    """

    # Delete existing events
    n = acq.GetEventNumber()
    # print("Writing events to acq")
    # print("Previously had", n, "events")
    for i in reversed(range(n)):
        acq.RemoveEvent(i)

    # Write new events
    for event in events:
        newEvent = btk.btkEvent()  # build an empty event object
        newEvent.SetLabel(event["label"])  # set the label
        newEvent.SetContext(event["context"])
        # newEvent.SetFrame(event["frame"])
        newEvent.SetTime(event["frame"] / 100)
        acq.AppendEvent(
            newEvent)  # append the new event to the aquisition object

    # print("Now has", acq.GetEventNumber(), "events")
    return acq
Example #2
0
def addEvent(acq, label, context, frameNumber):
    newEvent = btk.btkEvent()  # Créer un nouvel évènement vide
    newEvent.SetLabel(label)  # Met un label
    newEvent.SetContext(context)  # Met un context
    newEvent.SetFrame(frameNumber)  # Met la positoin, la frame
    acq.AppendEvent(
        newEvent)  # Rajoute l'évènement parmi tous les autres évènements