I have a function which takes all the points in particle flow and computes the difference. This is using openCV to track the way an object is moving within a video frame.
I am wanting to compute the angle at which the elements are moving within the frame. my following code is like so:
# Direction function.
def direction(Dx, Dy):
if (Dx > 0 and Dy > 0):
theta=math.atan(Dy/Dx)
elif (Dx < 0 and Dy > 0):
theta=math.atan(abs(Dx/Dy))+90*math.pi/180
print("Q2")
elif (Dx < 0 and Dy < 0):
theta=math.atan(abs(Dx/Dy))+180*math.pi/180
print("Q3")
elif (Dx > 0 and Dy < 0):
theta=math.atan(abs(Dx/Dy))+270*math.pi/180
print("Q4")
return theta*180/math.pi
I have a set of say 20 instances where the data is coming in like so in a 20x2 matrix. What i want to do is filter out any points which are heading in a direction not within 2 degrees of 0 or 180 degrees.
[[0.15859985 2.9615479 ]
[0.23764038 2.784729 ]
[0.22644043 2.9856567 ]
[0.2416687 2.7503052 ]
[0.21459961 2.9693756 ]
[0.18655396 2.986145 ]
[0.21240234 2.935913 ]
[0.17762756 2.9857788 ]
[0.20748901 2.8974915 ]
[0.2079773 2.9221497 ]
[0.27464294 2.7923584 ]
[0.22880554 2.981659 ]
[0.25639343 3.0173035 ]
[0.19406128 2.9276123 ]
[0.21862793 2.9695435 ]
[0.24038696 2.7330017 ]
[0.26013184 2.8272705 ]
[0.2579422 3.0002136 ]
[0.2731285 3.0145264 ]
[0.17489624 2.989685 ]
[0.31740952 3.005249 ]
[0.20376587 3.0024414 ]
[0.20892334 2.7820435 ]
[0.22192383 2.7878723 ]
[0.25608826 2.9936218 ]
[0.23474121 2.8941154 ]
[0.22346497 2.9910889 ]
[0.24715424 3.0131226 ]
[0.21356201 2.9688568 ]
[0.21009064 3.0111084 ]
[0.2687378 2.8110352 ]
[0.3083496 2.744812 ]
[0.32640076 2.929657 ]
[0.17825317 2.978836 ]
[0.20071411 2.7944946 ]
[0.23487854 3.0315552 ]
[0.22006226 2.9369202 ]
[0.24085999 2.7827759 ]
[0.24176025 2.8339844 ]
[0.18780518 2.822998 ]
[0.29027557 2.9614258 ]
[0.20407104 2.8983154 ]
[0.24299622 2.9848633 ]
[0.24712372 3.0074768 ]
[0.26487732 2.9702759 ]
[0.20198059 3.0663452 ]
[0.24079895 2.8884888 ]
[0.19445801 2.7364197 ]
[0.21140099 3.043457 ]]
this is to purely track horizontal direction within the frame. the biggest issue I am having here is getting the function to perform row wise on each data set so I can filter the data. I am fairly new to python and would appreciate any help i can get.