Exemplo n.º 1
0
    def loadDetection(self, start=None, end=None, lightLoad = False ):
        '''
        lightLoad only loads massX and massY to speed up the load. Then one can only compute basic features such as global speed of the animals
        '''
        print ( self.__str__(), ": Loading detection.")
        chrono = Chronometer("Load detection")

        self.detectionDictionnary.clear()

        cursor = self.conn.cursor()
        query =""
        if lightLoad == True :
            query = "SELECT FRAMENUMBER, MASS_X, MASS_Y FROM DETECTION WHERE ANIMALID={}".format( self.baseId )
        else:
            query = "SELECT FRAMENUMBER, MASS_X, MASS_Y, MASS_Z, FRONT_X, FRONT_Y, FRONT_Z, BACK_X, BACK_Y, BACK_Z,REARING,LOOK_UP,LOOK_DOWN FROM DETECTION WHERE ANIMALID={}".format( self.baseId )

        if ( start != None ):
            query += " AND FRAMENUMBER>={}".format(start )
        if ( end != None ):
            query += " AND FRAMENUMBER<={}".format(end )

        print( query )
        print( self.conn )
        cursor.execute( query )

        rows = cursor.fetchall()
        cursor.close()

        for row in rows:
            frameNumber = row[0]
            massX = row[1]
            massY = row[2]
            detection = None
            #filter detection at 0

            if ( massX < 10 ):
                continue

            if not lightLoad:
                massZ = row[3]

                frontX = row[4]
                frontY = row[5]
                frontZ = row[6]

                backX = row[7]
                backY = row[8]
                backZ = row[9]

                rearing = row[10]
                lookUp = row[11]
                lookDown = row[12]

                detection = Detection( massX, massY, massZ, frontX, frontY, frontZ, backX, backY, backZ, rearing, lookUp, lookDown )
            else:
                detection = Detection( massX, massY , lightLoad = True )

            self.detectionDictionnary[frameNumber] = detection

        print ( self.__str__(), " ", len( self.detectionDictionnary ) , " detections loaded in {} seconds.".format( chrono.getTimeInS( )) )
Exemplo n.º 2
0
def getPosition( t, animalA, animalB ):
    '''
    return mean position of available animals
    (0,0) if no detection available
    '''
    ad = animalA.detectionDictionnary
    bd = animalB.detectionDictionnary
    
    x = 0
    y = 0
    nb = 0

    if t in ad:
        x+=ad[t].massX
        y+=ad[t].massY
        nb+=1
        
    if t in bd:
        x+=bd[t].massX
        y+=bd[t].massY
        nb+=1

    if nb > 0:
        x /= nb
        y /= nb
        
    return Detection( x , y )
Exemplo n.º 3
0
    def loadAnonymousDetection(self, start=None, end=None):
        """
        Load the dictionary of anonymous detection.
        each entry get a list of detection
        clear previous anonymous detection dictionary
        """
        self.anonymousDetection = {}

        chrono = Chronometer("Load anonymous detection")
        cursor = self.conn.cursor()

        # query = "SELECT FRAMENUMBER, MASS_X, MASS_Y FROM DETECTION WHERE ANIMALID IS NULL"
        query = (
            "SELECT FRAMENUMBER, MASS_X, MASS_Y FROM DETECTION WHERE ANIMALID IS NULL"
        )

        if start != None:
            query += " AND FRAMENUMBER>={}".format(start)
        if end != None:
            query += " AND FRAMENUMBER<={}".format(end)

        print(query)
        cursor.execute(query)

        rows = cursor.fetchall()
        cursor.close()

        for row in rows:
            frameNumber = row[0]
            massX = row[1]
            massY = row[2]
            # data = row[3]
            detection = None
            # filter detection at 0
            if massX < 10:
                continue

            detection = Detection(massX, massY, lightLoad=True)
            # detection.setMask( Mask( data ) )

            if frameNumber not in self.anonymousDetection:
                self.anonymousDetection[frameNumber] = []

            self.anonymousDetection[frameNumber].append(detection)

        print(
            len(self.anonymousDetection),
            " frames containing anonymous detections loaded in {} seconds.".format(
                chrono.getTimeInS()
            ),
        )
Exemplo n.º 4
0
def getAveragePosition( animal , start, end ):
    
    x = 0
    y = 0
    count = 0
    
    aDic = animal.detectionDictionnary
    
    for t in range ( start, end+1 ):
        if t in aDic:
            
            x+= aDic[t].massX
            y+= aDic[t].massY
            count+=1
    
    if count > 0:
        x/=count
        y/=count
        
    return Detection( x , y )