-
Notifications
You must be signed in to change notification settings - Fork 0
/
Classify_Data.py
50 lines (37 loc) · 1.38 KB
/
Classify_Data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import requests
import json
import math
def length_width_ratio(x, y, z, angle):
# Calculate length and width based on the orientation angle
length = max(x, y) # Assuming the object's length is along the maximum dimension
width = min(x, y) # Assuming the object's width is along the minimum dimension
# If the angle is not 0
if angle != 0:
cos_angle = abs(math.cos(angle))
sin_angle = abs(math.sin(angle))
# Calculate rotated length and width
length = length * cos_angle + width * sin_angle
width = width * cos_angle + length * sin_angle
return length / width
def classify_objects(data):
objects = data["response"]["grasps"]
for obj in objects:
x = obj["pose"]["position"]["x"]
y = obj["pose"]["position"]["y"]
z = obj["pose"]["position"]["z"]
angle = obj["pose"]["orientation"]["z"]
# Calculate the length-to-width ratio
ratio = length_width_ratio(x, y, z, angle)
if ratio < 1.2:
obj["classification"] = "Circular"
else:
obj["classification"] = "Elongated"
return objects
file_path = "test.json"
with open(file_path, "r") as file:
data = json.load(file)
classified_objects = classify_objects(data)
for obj in classified_objects:
print("Object UUID:", obj["uuid"])
print("Classification:", obj["classification"])
print()