-
Notifications
You must be signed in to change notification settings - Fork 0
/
assigngrid.py
50 lines (24 loc) · 1.3 KB
/
assigngrid.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
# coding: utf-8
def _get_center(bb_x_min, bb_y_min, bb_x_max, bb_y_max):
x_bb_center = (bb_x_min + bb_x_max) / 2
y_bb_center = (bb_y_min + bb_y_max) / 2
box_center = (x_bb_center, y_bb_center)
return box_center
def _get_grid_position(image_width, image_height, x_num_grids, y_num_grids, box_center_tuple):
width_cell = image_width / x_num_grids
height_cell = image_height / y_num_grids
grid_col_num = box_center_tuple[0] // width_cell
grid_row_num = box_center_tuple[1] // height_cell
return int(grid_row_num), int(grid_col_num)
def assign_grid(image_dict, object_dict, x_num_grids, y_num_grids):
bb_x_min = object_dict['xmin']
bb_y_min = object_dict['ymin']
bb_x_max = object_dict['xmax']
bb_y_max = object_dict['ymax']
image_width = image_dict['width']
image_height = image_dict['height']
box_center_tuple = _get_center(bb_x_min, bb_y_min, bb_x_max, bb_y_max)
return _get_grid_position(image_width, image_height, x_num_grids, y_num_grids, box_center_tuple)
if __name__ == '__main__':
imageDict,objectList = parseXMLtoDict("C:/Users/ntihish/Documents/IUB/Deep Learning/Project/Git Repo/product-recognition/twoObjectsCorrect.xml")
gridRow,gridCol = assign_grid(imageDict, objectList[0], 3,3)