samannot 0.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ import tkinter as tk
2
+ from tkinter import ttk
3
+ class EditableListbox(tk.Listbox):
4
+ def __init__(self, master, edit_fn, check_edit, **kwargs):
5
+ super().__init__(master, **kwargs)
6
+ self.entry = None
7
+ self.edit_index = None
8
+ self.bind("<Double-1>", self.start_edit)
9
+ self.bind("<MouseWheel>", self.on_scroll)
10
+ self.bind("<Button-4>", self.on_scroll)
11
+ self.bind("<Button-5>", self.on_scroll)
12
+ self.edit_fn = edit_fn
13
+ self.check_edit = check_edit
14
+ def start_edit(self, event):
15
+ index = self.curselection()
16
+ if not index:
17
+ return
18
+ self.edit_index = index[0]
19
+ bbox = self.bbox(self.edit_index)
20
+ if not bbox:
21
+ return
22
+ _, y, _, h = bbox
23
+ full_width = self.winfo_width()
24
+ if self.entry:
25
+ self.entry.destroy()
26
+ self.entry = tk.Entry(self.master)
27
+ self.entry.insert(0, self.get(self.edit_index))
28
+ self.entry.place(x=self.winfo_x(), y=self.winfo_y()+y, width=full_width, height=h)
29
+
30
+ self.entry.focus()
31
+ self.entry.bind("<Return>", self.save_edit)
32
+ self.entry.bind("<FocusOut>", self.save_edit)
33
+ def save_edit(self, event=None):
34
+ if self.entry and self.edit_index is not None:
35
+ editable = True
36
+ if self.check_edit is not None:
37
+ editable = self.check_edit(self)
38
+ if editable:
39
+ item_bg = self.itemcget(self.edit_index, "bg")
40
+ item_fg = self.itemcget(self.edit_index, "fg")
41
+ self.delete(self.edit_index)
42
+ self.insert(self.edit_index, self.entry.get())
43
+ self.itemconfig(self.edit_index, bg=item_bg, fg=item_fg)
44
+ if self.edit_fn is not None:
45
+ self.edit_fn(self)
46
+ self.cancel_edit()
47
+
48
+ def cancel_edit(self):
49
+ if self.entry:
50
+ self.entry.destroy()
51
+ self.entry = None
52
+ self.edit_index = None
53
+
54
+ def on_scroll(self, event):
55
+ self.update_idletasks()
56
+ if self.entry and self.edit_index is not None:
57
+ bbox = self.bbox(self.edit_index)
58
+ if bbox:
59
+ _, y, _, h = bbox
60
+ full_width = self.winfo_width()
61
+ self.entry.place(x=self.winfo_x(), y=self.winfo_y()+y, width=full_width, height=h)
62
+ else:
63
+ self.cancel_edit()
@@ -0,0 +1,55 @@
1
+ {
2
+ "A": 38,
3
+ "B": 56,
4
+ "C": 54,
5
+ "D": 40,
6
+ "E": 26,
7
+ "F": 41,
8
+ "G": 42,
9
+ "H": 43,
10
+ "I": 31,
11
+ "J": 44,
12
+ "K": 45,
13
+ "L": 46,
14
+ "M": 58,
15
+ "N": 57,
16
+ "O": 32,
17
+ "P": 33,
18
+ "Q": 24,
19
+ "R": 27,
20
+ "S": 39,
21
+ "T": 28,
22
+ "U": 30,
23
+ "V": 55,
24
+ "W": 25,
25
+ "X": 53,
26
+ "Y": 29,
27
+ "Z": 52,
28
+
29
+ "1": 10,
30
+ "2": 11,
31
+ "3": 12,
32
+ "4": 13,
33
+ "5": 14,
34
+ "6": 15,
35
+ "7": 16,
36
+ "8": 17,
37
+ "9": 18,
38
+ "0": 19,
39
+
40
+ "SPACE": 65,
41
+ "RETURN": 36,
42
+ "TAB": 23,
43
+ "ESCAPE": 9,
44
+ "BACKSPACE": 22,
45
+ "DELETE": 119,
46
+ "INSERT": 118,
47
+ "HOME": 110,
48
+ "END": 115,
49
+ "PAGE_UP": 112,
50
+ "PAGE_DOWN": 117,
51
+ "LEFT": 113,
52
+ "UP": 111,
53
+ "RIGHT": 114,
54
+ "DOWN": 116
55
+ }
@@ -0,0 +1,55 @@
1
+ {
2
+ "A": 65,
3
+ "B": 66,
4
+ "C": 67,
5
+ "D": 68,
6
+ "E": 69,
7
+ "F": 70,
8
+ "G": 71,
9
+ "H": 72,
10
+ "I": 73,
11
+ "J": 74,
12
+ "K": 75,
13
+ "L": 76,
14
+ "M": 77,
15
+ "N": 78,
16
+ "O": 79,
17
+ "P": 80,
18
+ "Q": 81,
19
+ "R": 82,
20
+ "S": 83,
21
+ "T": 84,
22
+ "U": 85,
23
+ "V": 86,
24
+ "W": 87,
25
+ "X": 88,
26
+ "Y": 89,
27
+ "Z": 90,
28
+
29
+ "1": 49,
30
+ "2": 50,
31
+ "3": 51,
32
+ "4": 52,
33
+ "5": 53,
34
+ "6": 54,
35
+ "7": 55,
36
+ "8": 56,
37
+ "9": 57,
38
+ "0": 48,
39
+
40
+ "SPACE": 32,
41
+ "RETURN": 13,
42
+ "TAB": 9,
43
+ "ESCAPE": 27,
44
+ "BACKSPACE": 8,
45
+ "DELETE": 46,
46
+ "INSERT": 45,
47
+ "HOME": 36,
48
+ "END": 35,
49
+ "PAGE_UP": 33,
50
+ "PAGE_DOWN": 34,
51
+ "LEFT": 37,
52
+ "UP": 38,
53
+ "RIGHT": 39,
54
+ "DOWN": 40
55
+ }
samannot/label.py ADDED
@@ -0,0 +1,83 @@
1
+ import numpy as np
2
+ class PPoint:
3
+ def __init__(self,x,y,pt_type,idx):
4
+ self.x = x
5
+ self.y = y
6
+ self.pt_type = pt_type
7
+ self.idx = idx
8
+ class PBox:
9
+ def __init__(self,fx,fy,x,y,pt_type,idx):
10
+ self.fx = fx
11
+ self.fy = fy
12
+ self.x = x
13
+ self.y = y
14
+ self.pt_type = pt_type
15
+ self.idx = idx
16
+ class Label:
17
+ def __init__(self, name, col=None):
18
+ self.name = name
19
+ self.col = col
20
+ self.pts = {}
21
+ self.boxes = {}
22
+ self.features = []
23
+ self.prop_frames = {}
24
+ def find_most_recent_feature(self, idx, img_idx):
25
+ if not self.features[idx]:
26
+ return ""
27
+ most_recent_idx = -1
28
+ feature_id = -1
29
+ for i, modification in enumerate(self.features[idx]):
30
+ if modification[1] <= img_idx:
31
+ if modification[1] > most_recent_idx:
32
+ most_recent_idx = modification[1]
33
+ feature_id = i
34
+ if feature_id != -1:
35
+ return self.features[idx][feature_id][0]
36
+ # Fallback to the earliest defined value instead of returning empty space
37
+ return self.features[idx][0][0]
38
+ def modify_feature(self, feature_idx, feature_value, frame_idx):
39
+ self.features[feature_idx].append((feature_value, frame_idx))
40
+ def add_pt(self, x,y, pt_type,idx,block_idx):
41
+ if block_idx not in self.pts:
42
+ self.pts[block_idx] = []
43
+ self.pts[block_idx].append(PPoint(x,y,pt_type,idx))
44
+ return len(self.pts)-1
45
+ def add_box(self,fx, fy, x, y, pt_type,idx,block_idx):
46
+ if block_idx not in self.boxes:
47
+ self.boxes[block_idx] = []
48
+ self.boxes[block_idx].append(PBox(fx,fy,x,y,pt_type,idx))
49
+ return len(self.pts)-1
50
+ def remove_pt(self, idx, block_idx):
51
+ if 0 <= idx < len(self.pts[block_idx]):
52
+ del self.pts[block_idx][idx]
53
+ def remove_box(self, idx, block_idx):
54
+ if 0 <= idx < len(self.boxes[block_idx]):
55
+ del self.boxes[block_idx][idx]
56
+ def clear_pts(self,block_idx):
57
+ self.pts[block_idx] = []
58
+ def to_dict(self):
59
+ return { 'name': self.name, 'color': self.col,'pts': self.pts,'features': self.features,}
60
+ class Label_Handler:
61
+ def __init__(self):
62
+ self.colour_map = self.generate_color_map()
63
+ self.current_label_idx = 0
64
+ def generate_color_map(self,N=256): # PASCAL VOC
65
+ def bitget(byteval, idx):
66
+ return ((byteval & (1 << idx)) != 0)
67
+ cmap = np.zeros((N, 3), dtype=np.uint8)
68
+ for i in range(N):
69
+ r = g = b = 0
70
+ c = i
71
+ for j in range(8):
72
+ r = r | (bitget(c, 0) << 7-j)
73
+ g = g | (bitget(c, 1) << 7-j)
74
+ b = b | (bitget(c, 2) << 7-j)
75
+ c = c >> 3
76
+ cmap[i] = np.array([b, g, r])
77
+ return cmap[1:]
78
+ def convert_to_hexadecimal(self,colour):
79
+ return f'#{colour[2]:02x}{colour[1]:02x}{colour[0]:02x}'
80
+ def create_new_label(self,name):
81
+ label_colour = self.convert_to_hexadecimal(self.colour_map[self.current_label_idx%len(self.colour_map)])
82
+ self.current_label_idx += 1
83
+ return Label(name,label_colour)
samannot/main.py ADDED
@@ -0,0 +1,12 @@
1
+ from ttkthemes import ThemedTk
2
+ from .main_window import MainWindow
3
+
4
+
5
+ def main():
6
+ root = ThemedTk(theme='yaru')
7
+ app = MainWindow(root)
8
+ root.mainloop()
9
+
10
+
11
+ if __name__ == "__main__":
12
+ main()