Hello? I am serving as an undergraduate internship in my university. I am learning how to handle nuitrack through python, but the problem is that it is my first time handling python and having some troubles with it.
They gave me some tasks: for example, getting data from get.skletons and calculating angles between the shoulder, elbow, and wrist. I somehow completed it but the next task is really hard for me. It is to print angles simultaneously when tracking. They gave me two options. Printing angles in python and another option was printing angles on the tracking window.
Here is my code for computing left angle using the concept of outer product.
Ls_data=pd.read_csv(‘Left_shoulder.csv’, names=[“0”, “1”, “real”,“proj”,“orie”])
#data 저장 당시에 column에 이름 안붙여서 붙힘
Le_data=pd.read_csv(‘Left_elbow.csv’, names=[“0”, “1”, “real”,“proj”,“orie”])
Lw_data=pd.read_csv(‘Left_wrist.csv’, names=[“0”, “1”, “real”,“proj”,“orie”])
#리스트를 컴마로 구분하게 하는 함수
def extract_numbers(x):
numbers = re.findall(r"[\d.]+", x)
return [float(i) for i in numbers]
Ls_data[“proj”] = Ls_data[“proj”].apply(extract_numbers)
Le_data[“proj”] = Le_data[“proj”].apply(extract_numbers)
Lw_data[“proj”] = Lw_data[“proj”].apply(extract_numbers)
Ls_proj=Ls_data[“proj”]
Le_proj=Le_data[“proj”]
Lw_proj=Lw_data[“proj”]
x_se=[]
y_se=[]
z_se=[]
x_ew=[]
y_ew=[]
z_ew=[]
for i in range(len(Ls_proj)):
x_se.append(Ls_proj[i][0] - Le_proj[i][0])
y_se.append(Ls_proj[i][1] - Le_proj[i][1])
z_se.append(Ls_proj[i][2] - Le_proj[i][2])
x_ew.append(Le_proj[i][0] - Lw_proj[i][0])
y_ew.append(Le_proj[i][1] - Lw_proj[i][1])
z_ew.append(Le_proj[i][2] - Lw_proj[i][2])
#outer product(외적)의 개념 이용
x_o=[]
y_o=[]
z_o=[]
for i in range(len(x_se)):
x_o.append(y_se[i]*z_ew[i]-z_se[i]*y_ew[i])
y_o.append(z_se[i]*x_ew[i]-x_se[i]*z_ew[i])
z_o.append(x_se[i]*y_ew[i]-y_se[i]*x_ew[i])
len_se=[]
len_ew=[]
len_o=[]
for i in range(len(x_se)):
len_se.append((x_se[i]*x_se[i]+y_se[i]*y_se[i]+z_se[i]*z_se[i])(1/2))
len_ew.append((x_ew[i]*x_ew[i]+y_ew[i]*y_ew[i]+z_ew[i]*z_ew[i])(1/2))
len_o.append((x_o[i]*x_o[i]+y_o[i]*y_o[i]+z_o[i]*z_o[i])**(1/2))
sin=[]
for i in range(len(len_se)):
sin.append(len_o[i]/(len_se[i]*len_ew[i]))
theta=[]
for i in range(len(sin)):
theta.append(math.asin(sin[i]))
if sin[i] == 0: # 180도 일 경우 sin=0이 되므로 0도와 구분하기 위함
theta.append(3.14159)
print(theta)
f=open(“Left_elbow_angle”, “a”, newline=’’)
wr = csv.writer(f)
wr.writerow(theta)
oh, the problem was that getting data instantly from py.nuitrack and I solved it somehow. Thank you for your reply.