Exemple #1
0
    def read_events(self):
        """ A simple function that reads spikes from dynapse """
        packetContainer = libcaer.caerDeviceDataGet(self.handle)
        packetNum = libcaer.caerEventPacketContainerGetEventPacketsNumber(
            packetContainer)
        for i in range(packetNum):
            packetHeader = libcaer.caerEventPacketContainerGetEventPacket(
                packetContainer, i)
            if packetHeader == None:
                continue
            packetType = libcaer.caerEventPacketHeaderGetEventType(
                packetHeader)

            #get only polarity and special events
            if packetType == libcaer.SPIKE_EVENT:
                #loop over all events
                nEvents = libcaer.caerEventPacketHeaderGetEventNumber(
                    packetHeader)
                for this_e in range(nEvents):
                    spike = libcaer.caerSpikeEventPacketFromPacketHeader(
                        packetHeader)
                    event = libcaer.caerSpikeEventPacketGetEvent(spike, this_e)
                    self.neuid.append(libcaer.caerSpikeEventGetNeuronID(event))
                    self.coreid.append(
                        libcaer.caerSpikeEventGetSourceCoreID(event))
                    self.chipid.append(libcaer.caerSpikeEventGetChipID(event))
                    self.ts.append(libcaer.caerSpikeEventGetTimestamp(event))
Exemple #2
0
    def read_events(self):
        """ A simple function that reads events from DVS128 sensors: polarity, special"""
        polarity = None
        special = None

        packetContainer = libcaer.caerDeviceDataGet(self.handle)

        if packetContainer != None:
            packetNum = libcaer.caerEventPacketContainerGetEventPacketsNumber(packetContainer)

            for i in range(packetNum):
                packetHeader = libcaer.caerEventPacketContainerGetEventPacketConst(packetContainer, i)

                if packetHeader == None:
                    continue

                packetType = libcaer.caerEventPacketHeaderGetEventType(packetHeader)
                eventNum = libcaer.caerEventPacketHeaderGetEventNumber(packetHeader)

                if packetType == libcaer.POLARITY_EVENT:
                    # loop over all polarity events
                    polarityPacket = libcaer.caerPolarityEventPacketFromPacketHeaderConst(packetHeader)

                    polarity_ts = numpy.empty(eventNum, dtype=numpy.int32)
                    polarity_x = numpy.empty(eventNum, dtype=numpy.uint16)
                    polarity_y = numpy.empty(eventNum, dtype=numpy.uint16)
                    polarity_pol = numpy.empty(eventNum, dtype=numpy.bool)

                    for e in range(eventNum):
                        polarityEvent = libcaer.caerPolarityEventPacketGetEventConst(polarityPacket, e)

                        polarity_ts[e] = libcaer.caerPolarityEventGetTimestamp(polarityEvent)
                        polarity_x[e] = libcaer.caerPolarityEventGetX(polarityEvent)
                        polarity_y[e] = libcaer.caerPolarityEventGetY(polarityEvent)
                        polarity_pol[e] = libcaer.caerPolarityEventGetPolarity(polarityEvent)

                    polarity = (polarity_ts, polarity_x, polarity_y, polarity_pol)

                elif packetType == libcaer.SPECIAL_EVENT:
                    # loop over all special events
                    specialPacket = libcaer.caerSpecialEventPacketFromPacketHeaderConst(packetHeader)

                    special_ts = numpy.empty(eventNum, dtype=numpy.int32)
                    special_type = numpy.empty(eventNum, dtype=numpy.uint8)
                    special_data = numpy.empty(eventNum, dtype=numpy.uint32)

                    for e in range(eventNum):
                        specialEvent = libcaer.caerSpecialEventPacketGetEventConst(specialPacket, e)

                        special_ts[e] = libcaer.caerSpecialEventGetTimestamp(specialEvent)
                        special_type[e] = libcaer.caerSpecialEventGetType(specialEvent)
                        special_data[e] = libcaer.caerSpecialEventGetData(specialEvent)

                    special = (special_ts, special_type, special_data)

        return polarity, special
Exemple #3
0
    def read_events(self):
        """ A simple function that reads events from DAVIS sensors: polarity, frame, imu, special"""
        polarity = None
        frame = None
        imu = None
        special = None

        packetContainer = libcaer.caerDeviceDataGet(self.handle)

        if packetContainer != None:
            packetNum = libcaer.caerEventPacketContainerGetEventPacketsNumber(
                packetContainer)

            for i in range(packetNum):
                packetHeader = libcaer.caerEventPacketContainerGetEventPacketConst(
                    packetContainer, i)

                if packetHeader == None:
                    continue

                packetType = libcaer.caerEventPacketHeaderGetEventType(
                    packetHeader)
                eventNum = libcaer.caerEventPacketHeaderGetEventNumber(
                    packetHeader)

                if packetType == libcaer.POLARITY_EVENT:
                    # loop over all polarity events
                    polarityPacket = libcaer.caerPolarityEventPacketFromPacketHeaderConst(
                        packetHeader)

                    polarity_ts = numpy.empty(eventNum, dtype=numpy.int32)
                    polarity_x = numpy.empty(eventNum, dtype=numpy.uint16)
                    polarity_y = numpy.empty(eventNum, dtype=numpy.uint16)
                    polarity_pol = numpy.empty(eventNum, dtype=numpy.bool)

                    for e in range(eventNum):
                        polarityEvent = libcaer.caerPolarityEventPacketGetEventConst(
                            polarityPacket, e)

                        polarity_ts[e] = libcaer.caerPolarityEventGetTimestamp(
                            polarityEvent)
                        polarity_x[e] = libcaer.caerPolarityEventGetX(
                            polarityEvent)
                        polarity_y[e] = libcaer.caerPolarityEventGetY(
                            polarityEvent)
                        polarity_pol[e] = libcaer.caerPolarityEventGetPolarity(
                            polarityEvent)

                    polarity = (polarity_ts, polarity_x, polarity_y,
                                polarity_pol)

                elif packetType == libcaer.SPECIAL_EVENT:
                    # loop over all special events
                    specialPacket = libcaer.caerSpecialEventPacketFromPacketHeaderConst(
                        packetHeader)

                    special_ts = numpy.empty(eventNum, dtype=numpy.int32)
                    special_type = numpy.empty(eventNum, dtype=numpy.uint8)
                    special_data = numpy.empty(eventNum, dtype=numpy.uint32)

                    for e in range(eventNum):
                        specialEvent = libcaer.caerSpecialEventPacketGetEventConst(
                            specialPacket, e)

                        special_ts[e] = libcaer.caerSpecialEventGetTimestamp(
                            specialEvent)
                        special_type[e] = libcaer.caerSpecialEventGetType(
                            specialEvent)
                        special_data[e] = libcaer.caerSpecialEventGetData(
                            specialEvent)

                    special = (special_ts, special_type, special_data)

                elif packetType == libcaer.FRAME_EVENT:
                    # only get first frame event in packet
                    framePacket = libcaer.caerFrameEventPacketFromPacketHeaderConst(
                        packetHeader)

                    frameEvent = libcaer.caerFrameEventPacketGetEventConst(
                        framePacket, 0)

                    frame_numpy = numpy.empty((self.apsSizeY, self.apsSizeX),
                                              dtype=numpy.uint16)

                    # read pixels values
                    for y in range(
                            libcaer.caerFrameEventGetLengthY(frameEvent)):
                        for x in range(
                                libcaer.caerFrameEventGetLengthX(frameEvent)):
                            frame_numpy[y, x] = libcaer.caerFrameEventGetPixel(
                                frameEvent, x, y)

                    frame_ts = libcaer.caerFrameEventGetTimestamp(frameEvent)

                    frame = (frame_ts, frame_numpy)

                elif packetType == libcaer.IMU6_EVENT:
                    # loop over all IMU 6-axis events
                    imuPacket = libcaer.caerIMU6EventPacketFromPacketHeaderConst(
                        packetHeader)

                    imu_ts = numpy.empty(eventNum, dtype=numpy.int32)
                    imu_acc = numpy.empty((eventNum, 3), dtype=numpy.float32)
                    imu_gyro = numpy.empty((eventNum, 3), dtype=numpy.float32)
                    imu_temp = numpy.empty(eventNum, dtype=numpy.float32)

                    for e in range(eventNum):
                        imuEvent = libcaer.caerIMU6EventPacketGetEventConst(
                            imuPacket, e)

                        imu_ts[e] = libcaer.caerIMU6EventGetTimestamp(imuEvent)
                        imu_acc[e,
                                0] = libcaer.caerIMU6EventGetAccelX(imuEvent)
                        imu_acc[e,
                                1] = libcaer.caerIMU6EventGetAccelY(imuEvent)
                        imu_acc[e,
                                2] = libcaer.caerIMU6EventGetAccelZ(imuEvent)
                        imu_gyro[e,
                                 0] = libcaer.caerIMU6EventGetGyroX(imuEvent)
                        imu_gyro[e,
                                 1] = libcaer.caerIMU6EventGetGyroY(imuEvent)
                        imu_gyro[e,
                                 2] = libcaer.caerIMU6EventGetGyroZ(imuEvent)
                        imu_temp[e] = libcaer.caerIMU6EventGetTemp(imuEvent)

                    imu = (imu_ts, imu_acc, imu_gyro, imu_temp)

        return polarity, frame, imu, special