mardi 22 septembre 2020

UFuncTypeError: ufunc 'absolute' did not contain a loop with signature matching types dtype('

The below code loops over a set of points stored in a dequeue (double ended queue).

import numpy as np

pts1_blue=[(230,50),(100,200),.....] #this is just example values of the centroids

for i in range(1, len(pts1_blue)):
  
    # if either of the tracked points are None, ignore
    # them
  if pts1_blue[i - 1] is None or pts1_blue[i] is None:
    
      continue
 #  # otherwise, compute the thickness of the line and
    # draw the connecting lines
  if len(pts1_blue)>=10: 
   if counter_blue_1 >= 10 and i == 1 and pts1_blue[-10] is not None:
        
        # compute the difference between the x and y
        # coordinates and re-initialize the direction
        # text variables
        dX_blue = pts1_blue[-10][0] - pts1_blue[i][0]
        dY_blue = pts1_blue[-10][1] - pts1_blue[i][1]
        
        
       # print('DXX',dX_blue)
        (dirX_blue, dirY_blue) = ("", "")
        # ensure there is significant movement in the
        # x-direction
        if np.abs(dX_blue) > 20:
           #   print('DXXXX_blue',dX_blue)
              dirX_blue = "North" if np.sign(dX_blue) == 1 else "South"
        # ensure there is significant movement in the
        # y-direction
        if np.abs(dY_blue) > 20:
              dirY_blue = "East" if np.sign(dY_blue) == 1 else "West"
        # handle when both directions are non-empty
        if dirX_blue != "" and dirY_blue != "":
            # direction_blue = "{}-{}".format(dirY_blue, dirX_blue)
        # otherwise, only one direction is non-empty
       # else:
         direction_blue = dirX_blue if np.abs(dirX_blue) > np.abs(dirY_blue) else dirY_blue

These points represent the centroid of a detected small car fom different frames. I'm using these centroide coordinates to calculate the difference between a y and y coordinates of a current frame and a frame at the back of the buffer (10 frame distance between them) and accoording to the sign of the delta i classifies the direction. However, i need my code to handle when both dx and dy are not zero by choosing the delta that is larger than the other. when i run the code it returns the follwing error:

 direction_blue = dirX_blue if np.abs(dirX_blue) > np.abs(dirY_blue) else dirY_blue

 UFuncTypeError: ufunc 'absolute' did not contain a loop with signature matching types dtype('<U5') - 
 > dtype('<U5')

I found the same error on ther post, however couldn't interpret them on my case So i would be grateful for someone's help.

Note: Directions are North south west and east. The case in which both dx and dy are not zero is when the car drives diagonal, however i want to classify this direction according to the largest delta

Thanks in advance Khaled

Aucun commentaire:

Enregistrer un commentaire