目录

python 计算两点角度 正北方向为0度

python求向量角度

图像中根据斜率计算角度

图像中,跌倒检测用人体角度

图像中,求向量角度

opencv polylines划线


python 计算两点角度 正北方向为0度
 

import glob
import os
import math
if __name__ == '__main__':

    point2=[30,20]
    point1=[20,10]
    dy1 = point2[1]-point1[1]
    dx1 = point2[0]-point1[0]
    angle1 = math.atan2(dy1, dx1)
    angle1 = int(angle1 * 180 / math.pi)

    print(90-angle1)

    point2=[20,20]
    point1=[20,10]
    dy1 = point2[1]-point1[1]
    dx1 = point2[0]-point1[0]
    angle1 = math.atan2(dy1, dx1)
    angle1 = int(angle1 * 180 / math.pi)

    print(90-angle1)

    point2=[10,20]
    point1=[20,10]
    dy1 = point2[1]-point1[1]
    dx1 = point2[0]-point1[0]
    angle1 = math.atan2(dy1, dx1)
    angle1 = int(angle1 * 180 / math.pi)

    print(90-angle1)

python求向量角度

标准坐标系中,返回0-360度。

angle1 = math.atan2(dy1, dx1)
    angle1 = -int(angle1 * 180 /math.pi)
    if angle1<0:
        angle1=360+angle1

图像中根据斜率计算角度

import math

if __name__ == '__main__':

    dy1=1
    dx1=2
    angle1 = math.atan2(-dy1, dx1)
    angle1 = int(angle1 * 180 / math.pi)

    print(angle1)

图像中,跌倒检测用人体角度

因为向左倒,向右倒是一样的,脚在上面,说明也是不正常的,

import math


def get_angle(dy1,dx1):
    angle1 = math.atan2(-dy1, dx1)
    angle1 = abs(int(angle1 * 180 / math.pi))
    if angle1>90:
        angle1=180-angle1
    return angle1

if __name__ == '__main__':

    dy1=2
    dx1=-10
    angle=get_angle(dy1,dx1)
    print(angle)

图像中,求向量角度

y轴方向相反,返回0-360度。

import math
def get_angle(dx1,dy1):
    angle1 = math.atan2(-dy1, dx1)
    angle1 = -int(angle1 * 180 / math.pi)
    if angle1 < 0:
        angle1 = 360 + angle1
    return angle1

if __name__ == '__main__':
    dx1 = -40
    dy1 = -40

    angle= get_angle(dx1,dy1)
    print(angle)

opencv polylines划线

# -*- coding: UTF-8 -*-
import cv2
import numpy as np
import os

img = np.zeros([512, 512, 3])

pts = np.array([[50, 190], [380, 420], [255, 50], [120, 420], [450, 190]])
# 第三个参数指的是是否封口,这里注意第二个参数外面必须再加一层中括号
cv2.polylines(img, [pts], True, (255, 255, 0), 15)
cv2.imshow('Image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# -*- coding: UTF-8 -*-
import math

import cv2
import numpy as np
import os

# img = np.zeros([512, 512, 3])
img = cv2.imread("123.jpg")



aaa=1-math.tan(15/180*math.pi)
print("tan",aaa)
pts = np.array([[0, 200], [200, int(200*aaa)], [200, 200]])#(x,y)
# 第三个参数指的是是否封口,这里注意第二个参数外面必须再加一层中括号
cv2.polylines(img, [pts], True, (0, 255, 0), 1)


angle= math.asin(0.64)

print(angle/math.pi*180)

cv2.imshow('Image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()