ImagePRO-Python 0.2.0__tar.gz → 0.4.0__tar.gz

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 (32) hide show
  1. {imagepro_python-0.2.0/src/ImagePRO_Python.egg-info → imagepro_python-0.4.0}/PKG-INFO +3 -1
  2. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/pyproject.toml +3 -1
  3. imagepro_python-0.4.0/src/ImagePRO/object_analysis/object_detection.py +98 -0
  4. imagepro_python-0.4.0/src/ImagePRO/pre_processing/dataset_generator.py +178 -0
  5. {imagepro_python-0.2.0 → imagepro_python-0.4.0/src/ImagePRO_Python.egg-info}/PKG-INFO +3 -1
  6. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO_Python.egg-info/SOURCES.txt +2 -0
  7. imagepro_python-0.4.0/src/ImagePRO_Python.egg-info/requires.txt +4 -0
  8. imagepro_python-0.2.0/src/ImagePRO_Python.egg-info/requires.txt +0 -2
  9. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/LICENSE +0 -0
  10. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/setup.cfg +0 -0
  11. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/__init__.py +0 -0
  12. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/human_analysis/__init__.py +0 -0
  13. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/human_analysis/body_analysis/__init__.py +0 -0
  14. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/human_analysis/body_analysis/body_pose_estimation.py +0 -0
  15. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/human_analysis/body_analysis/hand_tracking.py +0 -0
  16. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/human_analysis/face_analysis/__init__.py +0 -0
  17. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/human_analysis/face_analysis/eye_status_analysis.py +0 -0
  18. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/human_analysis/face_analysis/face_detection.py +0 -0
  19. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/human_analysis/face_analysis/face_mesh_analysis.py +0 -0
  20. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/human_analysis/face_analysis/head_pose_estimation.py +0 -0
  21. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/pre_processing/__init__.py +0 -0
  22. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/pre_processing/blur.py +0 -0
  23. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/pre_processing/contrast.py +0 -0
  24. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/pre_processing/crop.py +0 -0
  25. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/pre_processing/grayscale.py +0 -0
  26. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/pre_processing/resize.py +0 -0
  27. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/pre_processing/rotate.py +0 -0
  28. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/pre_processing/sharpen.py +0 -0
  29. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/utils/__init__.py +0 -0
  30. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO/utils/io_handler.py +0 -0
  31. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO_Python.egg-info/dependency_links.txt +0 -0
  32. {imagepro_python-0.2.0 → imagepro_python-0.4.0}/src/ImagePRO_Python.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ImagePRO-Python
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: clean, modular, and easy-to-use Python library for image processing tasks.
5
5
  Author-email: Parsa Safaie <parsasafaie.2568@proton.me>
6
6
  License: MIT
@@ -14,4 +14,6 @@ Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
15
  Requires-Dist: numpy<3.0,>=1.24
16
16
  Requires-Dist: opencv-python<5.0,>=4.8
17
+ Requires-Dist: ultralytics<9.0,>=8.2.0
18
+ Requires-Dist: mediapipe<1.0,>=0.10.0
17
19
  Dynamic: license-file
@@ -7,7 +7,7 @@ where = ["src"]
7
7
 
8
8
  [project]
9
9
  name = "ImagePRO-Python"
10
- version = "0.2.0"
10
+ version = "0.4.0"
11
11
  description = "clean, modular, and easy-to-use Python library for image processing tasks."
12
12
  readme = "README.md"
13
13
  requires-python = "==3.10.*"
@@ -24,6 +24,8 @@ classifiers = [
24
24
  dependencies = [
25
25
  "numpy>=1.24,<3.0",
26
26
  "opencv-python>=4.8,<5.0",
27
+ "ultralytics>=8.2.0,<9.0",
28
+ "mediapipe>=0.10.0,<1.0",
27
29
  ]
28
30
 
29
31
  [tool.hatch.build.targets.wheel]
@@ -0,0 +1,98 @@
1
+ from ultralytics import YOLO
2
+ import sys
3
+ from pathlib import Path
4
+
5
+ # Add parent directory to path for custom module imports
6
+ parent_dir = Path(__file__).resolve().parent.parent
7
+ sys.path.append(str(parent_dir))
8
+
9
+ from utils.io_handler import IOHandler
10
+
11
+
12
+ def detect_objects(
13
+ model=None,
14
+ accuracy_level=1,
15
+ src_image_path=None,
16
+ src_np_image=None,
17
+ output_image_path=None,
18
+ output_csv_path=None,
19
+ show_result=False
20
+ ):
21
+ """
22
+ Run object detection on a single image using Ultralytics YOLO.
23
+
24
+ Parameters
25
+ ----------
26
+ model : ultralytics.engine.model.YOLO | None, optional
27
+ A pre-loaded YOLO model instance. If provided, `accuracy_level` is ignored.
28
+ If None, a model is created based on `accuracy_level`.
29
+ accuracy_level : int, default=1
30
+ Model size preset in {1..5} mapping to:
31
+ 1 -> "yolo11n.pt", 2 -> "yolo11s.pt", 3 -> "yolo11m.pt",
32
+ 4 -> "yolo11l.pt", 5 -> "yolo11x.pt".
33
+ src_image_path : str | None, optional
34
+ Path to the input image on disk. Used by IOHandler if `src_np_image` is None.
35
+ src_np_image : np.ndarray | None, optional
36
+ Image array (BGR). If provided, it is preferred over `src_image_path`.
37
+ output_image_path : str | None, optional
38
+ If provided, saves the annotated image (result.plot()) to this path.
39
+ output_csv_path : str | None, optional
40
+ If provided, saves detections as rows of `[class_id, [x1n, y1n, x2n, y2n], confidence]`.
41
+ Note: coordinates are normalized in [0, 1].
42
+ show_result : bool, default=False
43
+ If True, shows the result window via `result.show()` (may require a GUI environment).
44
+
45
+ Returns
46
+ -------
47
+ tuple
48
+ (annotated_image: np.ndarray, lines: list[list])
49
+ where `annotated_image` is the result of `result.plot()` and
50
+ `lines` is a list of detection rows saved to CSV when requested.
51
+
52
+ Raises
53
+ ------
54
+ ValueError
55
+ If `accuracy_level` is not in {1..5}, or if image loading fails inside IOHandler.
56
+ """
57
+ # Create a model from preset if not provided by caller
58
+ if model is None:
59
+ if accuracy_level == 1:
60
+ model_name = "yolo11n.pt"
61
+ elif accuracy_level == 2:
62
+ model_name = "yolo11s.pt"
63
+ elif accuracy_level == 3:
64
+ model_name = "yolo11m.pt"
65
+ elif accuracy_level == 4:
66
+ model_name = "yolo11l.pt"
67
+ elif accuracy_level == 5:
68
+ model_name = "yolo11x.pt"
69
+ else:
70
+ raise ValueError('Unknown accuracy level.')
71
+
72
+ model = YOLO(model=model_name)
73
+
74
+ # Load image from path or ndarray using the shared IO helper
75
+ frame = IOHandler.load_image(image_path=src_image_path, np_image=src_np_image)
76
+
77
+ # Run inference (first result only)
78
+ result = model(frame)[0]
79
+ boxes = result.boxes
80
+
81
+ # Collect rows as: [class_id, [x1n, y1n, x2n, y2n], confidence]
82
+ lines = []
83
+ for box in boxes:
84
+ box_class = int(box.cls)
85
+ conf = float(box.conf)
86
+ x1, y1, x2, y2 = [float(c) for c in box.xyxyn.squeeze().tolist()]
87
+ lines.append([box_class, [x1, y1, x2, y2], conf])
88
+
89
+ # Optional visualization and saving
90
+ if show_result:
91
+ result.show()
92
+ if output_image_path:
93
+ IOHandler.save_image(np_image=result.plot(), result_path=output_image_path)
94
+ if output_csv_path:
95
+ IOHandler.save_csv(data=lines, result_path=output_csv_path)
96
+
97
+ # Return the plotted image and the CSV-friendly rows
98
+ return result.plot(), lines
@@ -0,0 +1,178 @@
1
+ import sys
2
+ import time
3
+ import random
4
+ from pathlib import Path
5
+
6
+ import cv2
7
+ import mediapipe as mp
8
+
9
+ # Add parent directory to sys.path for local imports
10
+ parent_dir = Path(__file__).resolve().parent.parent
11
+ sys.path.append(str(parent_dir))
12
+
13
+ from human_analysis.face_analysis.face_detection import detect_faces
14
+ from blur import apply_median_blur
15
+ from sharpen import apply_laplacian_sharpening
16
+ from rotate import rotate_image_custom
17
+ from grayscale import convert_to_grayscale
18
+ from resize import resize_image
19
+
20
+
21
+ def capture_bulk_pictures(
22
+ folder_path: str | Path,
23
+ face_id: str | int,
24
+ num_images: int = 200,
25
+ start_index: int = 0,
26
+ min_confidence: float = 0.7,
27
+ camera_index: int = 0,
28
+ apply_blur: bool = False,
29
+ apply_grayscale: bool = False,
30
+ apply_sharpen: bool = False,
31
+ apply_rotate: bool = False,
32
+ apply_resize: tuple = False,
33
+ delay: float = 0.1,
34
+ ) -> None:
35
+ """
36
+ Capture frames from webcam and save cropped face images, with optional preprocessing.
37
+
38
+ Processing order (if enabled):
39
+ median blur → laplacian sharpen → grayscale → resize → random rotate
40
+
41
+ Parameters
42
+ ----------
43
+ folder_path : str | Path
44
+ Base directory where the face-id folder will be created.
45
+ face_id : str | int
46
+ Subfolder name (e.g., user id). A new folder "<folder_path>/<face_id>" will be created.
47
+ num_images : int, default=200
48
+ Number of frames to capture/save.
49
+ start_index : int, default=0
50
+ Starting index for saved filenames (zero-padded).
51
+ min_confidence : float, default=0.7
52
+ Detection confidence for MediaPipe FaceMesh.
53
+ camera_index : int, default=0
54
+ OpenCV camera index.
55
+ apply_blur : bool, default=False
56
+ Apply median blur (filter_size=3) before other steps.
57
+ apply_grayscale : bool, default=False
58
+ Convert frame to single-channel grayscale.
59
+ apply_sharpen : bool, default=False
60
+ Apply Laplacian-based sharpening (coefficient=1.0).
61
+ apply_rotate : bool, default=False
62
+ Apply a random rotation in [-45°, +45°] with random scale {1.0, 1.1, 1.2, 1.3}.
63
+ apply_resize : tuple[int, int] | None, default=None
64
+ If provided, resize to (width, height) before rotation.
65
+ delay : float, default=0.1
66
+ Delay between each capture in seconds.
67
+
68
+ Raises
69
+ ------
70
+ ValueError
71
+ If arguments are invalid.
72
+ FileExistsError
73
+ If the destination folder already exists.
74
+ RuntimeError
75
+ If the webcam cannot be opened.
76
+ """
77
+ if not isinstance(num_images, int) or num_images <= 0:
78
+ raise ValueError("'num_images' must be a positive integer.")
79
+ if not isinstance(start_index, int) or start_index < 0:
80
+ raise ValueError("'start_index' must be a non-negative integer.")
81
+ if not isinstance(min_confidence, (int, float)) or not (0 <= min_confidence <= 1):
82
+ raise ValueError("'min_confidence' must be between 0 and 1.")
83
+ if not isinstance(delay, (int, float)) or delay < 0:
84
+ raise ValueError("'delay' must be a non-negative number.")
85
+
86
+ base_dir = Path(folder_path)
87
+ face_folder = base_dir / str(face_id)
88
+
89
+ # Create destination folder (fail if exists to avoid accidental overwrite)
90
+ try:
91
+ face_folder.mkdir(parents=True, exist_ok=False)
92
+ except FileExistsError as e:
93
+ raise FileExistsError(f"Destination already exists: {face_folder}") from e
94
+
95
+ # Open webcam
96
+ cap = cv2.VideoCapture(camera_index)
97
+ if not cap.isOpened():
98
+ raise RuntimeError(f"Failed to open webcam (index={camera_index}).")
99
+
100
+ # Initialize FaceMesh for live stream (tracking mode)
101
+ face_mesh = mp.solutions.face_mesh.FaceMesh(
102
+ max_num_faces=1,
103
+ min_detection_confidence=min_confidence,
104
+ refine_landmarks=True,
105
+ static_image_mode=False,
106
+ )
107
+
108
+ saved = 0
109
+ try:
110
+ while saved < num_images:
111
+ ok, frame = cap.read()
112
+ if not ok:
113
+ print("Skipping empty frame.")
114
+ continue
115
+
116
+ # Optional preprocessing steps
117
+ proc = frame
118
+
119
+ if apply_blur:
120
+ # Small kernel to keep facial details while reducing salt-and-pepper noise
121
+ proc = apply_median_blur(src_np_image=proc, filter_size=3)
122
+
123
+ if apply_sharpen:
124
+ # Gentle sharpening; adjust coefficient if needed
125
+ proc = apply_laplacian_sharpening(src_np_image=proc, coefficient=1.0)
126
+
127
+ if apply_grayscale:
128
+ proc = convert_to_grayscale(src_np_image=proc)
129
+
130
+ if apply_resize is not None:
131
+ proc = resize_image(new_size=apply_resize, src_np_image=proc)
132
+
133
+ if apply_rotate:
134
+ angle = float(random.randint(-45, 45))
135
+ scale = random.choice([1.0, 1.1, 1.2, 1.3])
136
+ proc = rotate_image_custom(src_np_image=proc, angle=angle, scale=scale)
137
+
138
+ # Zero-padded filenames for better ordering
139
+ filename = f"{start_index + saved:04d}.jpg"
140
+ out_path = face_folder / filename
141
+
142
+ try:
143
+ # Save cropped face image via standardized detect_faces
144
+ detect_faces(
145
+ max_faces=1,
146
+ min_confidence=min_confidence,
147
+ src_np_image=proc,
148
+ output_image_path=str(out_path),
149
+ face_mesh_obj=face_mesh,
150
+ )
151
+ saved += 1
152
+
153
+ if delay > 0:
154
+ time.sleep(delay)
155
+
156
+ except ValueError:
157
+ # No face detected; skip this frame
158
+ continue
159
+ finally:
160
+ cap.release()
161
+ cv2.destroyAllWindows()
162
+
163
+
164
+ if __name__ == "__main__":
165
+ capture_bulk_pictures(
166
+ folder_path=r"tmp",
167
+ face_id="0",
168
+ num_images=200,
169
+ start_index=0,
170
+ min_confidence=0.7,
171
+ camera_index=0,
172
+ apply_blur=True,
173
+ apply_sharpen=True,
174
+ apply_grayscale=True,
175
+ apply_resize=(224, 224),
176
+ apply_rotate=True,
177
+ delay=0.1
178
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ImagePRO-Python
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: clean, modular, and easy-to-use Python library for image processing tasks.
5
5
  Author-email: Parsa Safaie <parsasafaie.2568@proton.me>
6
6
  License: MIT
@@ -14,4 +14,6 @@ Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
15
  Requires-Dist: numpy<3.0,>=1.24
16
16
  Requires-Dist: opencv-python<5.0,>=4.8
17
+ Requires-Dist: ultralytics<9.0,>=8.2.0
18
+ Requires-Dist: mediapipe<1.0,>=0.10.0
17
19
  Dynamic: license-file
@@ -10,10 +10,12 @@ src/ImagePRO/human_analysis/face_analysis/eye_status_analysis.py
10
10
  src/ImagePRO/human_analysis/face_analysis/face_detection.py
11
11
  src/ImagePRO/human_analysis/face_analysis/face_mesh_analysis.py
12
12
  src/ImagePRO/human_analysis/face_analysis/head_pose_estimation.py
13
+ src/ImagePRO/object_analysis/object_detection.py
13
14
  src/ImagePRO/pre_processing/__init__.py
14
15
  src/ImagePRO/pre_processing/blur.py
15
16
  src/ImagePRO/pre_processing/contrast.py
16
17
  src/ImagePRO/pre_processing/crop.py
18
+ src/ImagePRO/pre_processing/dataset_generator.py
17
19
  src/ImagePRO/pre_processing/grayscale.py
18
20
  src/ImagePRO/pre_processing/resize.py
19
21
  src/ImagePRO/pre_processing/rotate.py
@@ -0,0 +1,4 @@
1
+ numpy<3.0,>=1.24
2
+ opencv-python<5.0,>=4.8
3
+ ultralytics<9.0,>=8.2.0
4
+ mediapipe<1.0,>=0.10.0
@@ -1,2 +0,0 @@
1
- numpy<3.0,>=1.24
2
- opencv-python<5.0,>=4.8
File without changes