@@ -21,39 +21,42 @@ pip install retailtree
2121# Usage
2222
2323```
24+ # Import necessary modules and functions
2425from retailtree import RetailTree, Annotation
2526from retailtree.utils.dist_func import manhattan, euclidean
27+ import json
2628
27- # Create annotation object
28- ann1 = Annotation(id=1, x_min=2, y_min=1, x_max=3, y_max=2)
29- ann2 = Annotation(id=2, x_min=1, y_min=2, x_max=2, y_max=3)
30- ann3 = Annotation(id=3, x_min=2, y_min=2, x_max=3, y_max=3)
31- ann4 = Annotation(id=4, x_min=3, y_min=2, x_max=4, y_max=3)
32- ann5 = Annotation(id=5, x_min=2, y_min=3, x_max=3, y_max=4)
29+ # Define the path to the JSON file containing annotations
30+ file_path = './tests/test_data/test_data.json'
3331
34- annotations = [ann1, ann2, ann3, ann4, ann5]
32+ # Open and load the JSON file
33+ with open(file_path, 'r') as file:
34+ annotations = json.load(file)
3535
36- # Create retailtree object
36+ # Initialize a RetailTree object
3737rt = RetailTree()
3838
39- # Adding annotations to retailtree
39+ # Iterate over the loaded annotations and create Annotation objects
4040for ann in annotations:
41- rt.add_annotation(ann)
41+ # Create an Annotation object with the required properties
42+ ann_obj = Annotation(id=ann['id'], x_min=ann['x_min'], y_min=ann['y_min'], x_max=ann['x_max'], y_max=ann['y_max'])
43+ # Add the created Annotation object to the RetailTree
44+ rt.add_annotation(ann_obj)
4245
43-
44- # Build tree
46+ # Build the spatial tree structure using the euclidean distance function
4547rt.build_tree(dist_func=euclidean)
4648
47- # Get neighbors- annotations within radius
49+ # Retrieve and print annotations within a radius of 1 from the annotation with id=3
4850print(rt.neighbors(id=3, radius=1))
4951
50- # Get Top, Bottom, Right, Left annotations
52+ # Retrieve and print the Top, Bottom, Left, and Right neighboring annotations
53+ # of the annotation with id=3 within a radius of 1 and a minimum overlap of 0.5
5154print(rt.TBLR(id=3, radius=1, overlap=0.5))
5255
53- # Get neighboring annotations within a particular angle range
56+ # Retrieve and print neighboring annotations of the annotation with id=3
57+ # within a radius of 1 and angle range from 0 to 180 degrees
5458print(rt.neighbors_wa(id=3, radius=1, amin=0, amax=180))
5559
56- # Get annotation properties
60+ # Retrieve and print the coordinates of the annotation with id=3
5761print(rt.get(id=3).get_coords())
58-
5962```
0 commit comments