eye-cv 1.0.0__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.
Files changed (94) hide show
  1. eye/__init__.py +115 -0
  2. eye/__init___supervision_original.py +120 -0
  3. eye/annotators/__init__.py +0 -0
  4. eye/annotators/base.py +22 -0
  5. eye/annotators/core.py +2699 -0
  6. eye/annotators/line.py +107 -0
  7. eye/annotators/modern.py +529 -0
  8. eye/annotators/trace.py +142 -0
  9. eye/annotators/utils.py +177 -0
  10. eye/assets/__init__.py +2 -0
  11. eye/assets/downloader.py +95 -0
  12. eye/assets/list.py +83 -0
  13. eye/classification/__init__.py +0 -0
  14. eye/classification/core.py +188 -0
  15. eye/config.py +2 -0
  16. eye/core/__init__.py +0 -0
  17. eye/core/trackers/__init__.py +1 -0
  18. eye/core/trackers/botsort_tracker.py +336 -0
  19. eye/core/trackers/bytetrack_tracker.py +284 -0
  20. eye/core/trackers/sort_tracker.py +200 -0
  21. eye/core/tracking.py +146 -0
  22. eye/dataset/__init__.py +0 -0
  23. eye/dataset/core.py +919 -0
  24. eye/dataset/formats/__init__.py +0 -0
  25. eye/dataset/formats/coco.py +258 -0
  26. eye/dataset/formats/pascal_voc.py +279 -0
  27. eye/dataset/formats/yolo.py +272 -0
  28. eye/dataset/utils.py +259 -0
  29. eye/detection/__init__.py +0 -0
  30. eye/detection/auto_convert.py +155 -0
  31. eye/detection/core.py +1529 -0
  32. eye/detection/detections_enhanced.py +392 -0
  33. eye/detection/line_zone.py +859 -0
  34. eye/detection/lmm.py +184 -0
  35. eye/detection/overlap_filter.py +270 -0
  36. eye/detection/tools/__init__.py +0 -0
  37. eye/detection/tools/csv_sink.py +181 -0
  38. eye/detection/tools/inference_slicer.py +288 -0
  39. eye/detection/tools/json_sink.py +142 -0
  40. eye/detection/tools/polygon_zone.py +202 -0
  41. eye/detection/tools/smoother.py +123 -0
  42. eye/detection/tools/smoothing.py +179 -0
  43. eye/detection/tools/smoothing_config.py +202 -0
  44. eye/detection/tools/transformers.py +247 -0
  45. eye/detection/utils.py +1175 -0
  46. eye/draw/__init__.py +0 -0
  47. eye/draw/color.py +154 -0
  48. eye/draw/utils.py +374 -0
  49. eye/filters.py +112 -0
  50. eye/geometry/__init__.py +0 -0
  51. eye/geometry/core.py +128 -0
  52. eye/geometry/utils.py +47 -0
  53. eye/keypoint/__init__.py +0 -0
  54. eye/keypoint/annotators.py +442 -0
  55. eye/keypoint/core.py +687 -0
  56. eye/keypoint/skeletons.py +2647 -0
  57. eye/metrics/__init__.py +21 -0
  58. eye/metrics/core.py +72 -0
  59. eye/metrics/detection.py +843 -0
  60. eye/metrics/f1_score.py +648 -0
  61. eye/metrics/mean_average_precision.py +628 -0
  62. eye/metrics/mean_average_recall.py +697 -0
  63. eye/metrics/precision.py +653 -0
  64. eye/metrics/recall.py +652 -0
  65. eye/metrics/utils/__init__.py +0 -0
  66. eye/metrics/utils/object_size.py +158 -0
  67. eye/metrics/utils/utils.py +9 -0
  68. eye/py.typed +0 -0
  69. eye/quick.py +104 -0
  70. eye/tracker/__init__.py +0 -0
  71. eye/tracker/byte_tracker/__init__.py +0 -0
  72. eye/tracker/byte_tracker/core.py +386 -0
  73. eye/tracker/byte_tracker/kalman_filter.py +205 -0
  74. eye/tracker/byte_tracker/matching.py +69 -0
  75. eye/tracker/byte_tracker/single_object_track.py +178 -0
  76. eye/tracker/byte_tracker/utils.py +18 -0
  77. eye/utils/__init__.py +0 -0
  78. eye/utils/conversion.py +132 -0
  79. eye/utils/file.py +159 -0
  80. eye/utils/image.py +794 -0
  81. eye/utils/internal.py +200 -0
  82. eye/utils/iterables.py +84 -0
  83. eye/utils/notebook.py +114 -0
  84. eye/utils/video.py +307 -0
  85. eye/utils_eye/__init__.py +1 -0
  86. eye/utils_eye/geometry.py +71 -0
  87. eye/utils_eye/nms.py +55 -0
  88. eye/validators/__init__.py +140 -0
  89. eye/web.py +271 -0
  90. eye_cv-1.0.0.dist-info/METADATA +319 -0
  91. eye_cv-1.0.0.dist-info/RECORD +94 -0
  92. eye_cv-1.0.0.dist-info/WHEEL +5 -0
  93. eye_cv-1.0.0.dist-info/licenses/LICENSE +21 -0
  94. eye_cv-1.0.0.dist-info/top_level.txt +1 -0
eye/utils/file.py ADDED
@@ -0,0 +1,159 @@
1
+ import json
2
+ from pathlib import Path
3
+ from typing import Dict, List, Optional, Union
4
+
5
+ import numpy as np
6
+ try:
7
+ import yaml # type: ignore
8
+ except ModuleNotFoundError: # pragma: no cover
9
+ yaml = None
10
+
11
+
12
+ class NumpyJsonEncoder(json.JSONEncoder):
13
+ def default(self, obj):
14
+ if isinstance(obj, np.integer):
15
+ return int(obj)
16
+ if isinstance(obj, np.floating):
17
+ return float(obj)
18
+ if isinstance(obj, np.ndarray):
19
+ return obj.tolist()
20
+ return super(NumpyJsonEncoder, self).default(obj)
21
+
22
+
23
+ def list_files_with_extensions(
24
+ directory: Union[str, Path], extensions: Optional[List[str]] = None
25
+ ) -> List[Path]:
26
+ """
27
+ List files in a directory with specified extensions or
28
+ all files if no extensions are provided.
29
+
30
+ Args:
31
+ directory (Union[str, Path]): The directory path as a string or Path object.
32
+ extensions (Optional[List[str]]): A list of file extensions to filter.
33
+ Default is None, which lists all files.
34
+
35
+ Returns:
36
+ (List[Path]): A list of Path objects for the matching files.
37
+
38
+ Examples:
39
+ ```python
40
+ import eye as sv
41
+
42
+ # List all files in the directory
43
+ files = sv.list_files_with_extensions(directory='my_directory')
44
+
45
+ # List only files with '.txt' and '.md' extensions
46
+ files = sv.list_files_with_extensions(
47
+ directory='my_directory', extensions=['txt', 'md'])
48
+ ```
49
+ """
50
+
51
+ directory = Path(directory)
52
+ files_with_extensions = []
53
+
54
+ if extensions is not None:
55
+ for ext in extensions:
56
+ files_with_extensions.extend(directory.glob(f"*.{ext}"))
57
+ else:
58
+ files_with_extensions.extend(directory.glob("*"))
59
+
60
+ return files_with_extensions
61
+
62
+
63
+ def read_txt_file(file_path: Union[str, Path], skip_empty: bool = False) -> List[str]:
64
+ """
65
+ Read a text file and return a list of strings without newline characters.
66
+ Optionally skip empty lines.
67
+
68
+ Args:
69
+ file_path (Union[str, Path]): The file path as a string or Path object.
70
+ skip_empty (bool): If True, skip lines that are empty or contain only
71
+ whitespace. Default is False.
72
+
73
+ Returns:
74
+ List[str]: A list of strings representing the lines in the text file.
75
+ """
76
+ with open(str(file_path), "r") as file:
77
+ if skip_empty:
78
+ lines = [line.rstrip("\n") for line in file if line.strip()]
79
+ else:
80
+ lines = [line.rstrip("\n") for line in file]
81
+
82
+ return lines
83
+
84
+
85
+ def save_text_file(lines: List[str], file_path: Union[str, Path]) -> None:
86
+ """
87
+ Write a list of strings to a text file, each string on a new line.
88
+
89
+ Args:
90
+ lines (List[str]): The list of strings to be written to the file.
91
+ file_path (Union[str, Path]): The file path as a string or Path object.
92
+ """
93
+ with open(str(file_path), "w") as file:
94
+ for line in lines:
95
+ file.write(line + "\n")
96
+
97
+
98
+ def read_json_file(file_path: Union[str, Path]) -> Dict:
99
+ """
100
+ Read a json file and return a dict.
101
+
102
+ Args:
103
+ file_path (Union[str, Path]): The file path as a string or Path object.
104
+
105
+ Returns:
106
+ dict: A dict of annotations information
107
+ """
108
+ with open(str(file_path), "r") as file:
109
+ data = json.load(file)
110
+ return data
111
+
112
+
113
+ def save_json_file(data: dict, file_path: Union[str, Path], indent: int = 3) -> None:
114
+ """
115
+ Write a dict to a json file.
116
+
117
+ Args:
118
+ indent:
119
+ data (dict): dict with unique keys and value as pair.
120
+ file_path (Union[str, Path]): The file path as a string or Path object.
121
+ """
122
+ with open(str(file_path), "w") as fp:
123
+ json.dump(data, fp, cls=NumpyJsonEncoder, indent=indent)
124
+
125
+
126
+ def read_yaml_file(file_path: Union[str, Path]) -> Dict:
127
+ """
128
+ Read a yaml file and return a dict.
129
+
130
+ Args:
131
+ file_path (Union[str, Path]): The file path as a string or Path object.
132
+
133
+ Returns:
134
+ dict: A dict of content information
135
+ """
136
+ if yaml is None:
137
+ raise ImportError(
138
+ "PyYAML is required for YAML support. Install it with: pip install \"eye-cv[all]\" or pip install pyyaml"
139
+ )
140
+ with open(str(file_path), "r") as file:
141
+ data = yaml.safe_load(file)
142
+ return data
143
+
144
+
145
+ def save_yaml_file(data: dict, file_path: Union[str, Path]) -> None:
146
+ """
147
+ Save a dict to a json file.
148
+
149
+ Args:
150
+ indent:
151
+ data (dict): dict with unique keys and value as pair.
152
+ file_path (Union[str, Path]): The file path as a string or Path object.
153
+ """
154
+ if yaml is None:
155
+ raise ImportError(
156
+ "PyYAML is required for YAML support. Install it with: pip install \"eye-cv[all]\" or pip install pyyaml"
157
+ )
158
+ with open(str(file_path), "w") as outfile:
159
+ yaml.dump(data, outfile, sort_keys=False, default_flow_style=None)