ImagePRO-Python 0.2.0__tar.gz → 0.3.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 (30) hide show
  1. {imagepro_python-0.2.0/src/ImagePRO_Python.egg-info → imagepro_python-0.3.0}/PKG-INFO +1 -1
  2. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/pyproject.toml +1 -1
  3. imagepro_python-0.3.0/src/ImagePRO/pre_processing/dataset_generator.py +178 -0
  4. {imagepro_python-0.2.0 → imagepro_python-0.3.0/src/ImagePRO_Python.egg-info}/PKG-INFO +1 -1
  5. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO_Python.egg-info/SOURCES.txt +1 -0
  6. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/LICENSE +0 -0
  7. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/setup.cfg +0 -0
  8. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/__init__.py +0 -0
  9. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/human_analysis/__init__.py +0 -0
  10. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/human_analysis/body_analysis/__init__.py +0 -0
  11. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/human_analysis/body_analysis/body_pose_estimation.py +0 -0
  12. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/human_analysis/body_analysis/hand_tracking.py +0 -0
  13. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/human_analysis/face_analysis/__init__.py +0 -0
  14. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/human_analysis/face_analysis/eye_status_analysis.py +0 -0
  15. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/human_analysis/face_analysis/face_detection.py +0 -0
  16. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/human_analysis/face_analysis/face_mesh_analysis.py +0 -0
  17. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/human_analysis/face_analysis/head_pose_estimation.py +0 -0
  18. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/pre_processing/__init__.py +0 -0
  19. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/pre_processing/blur.py +0 -0
  20. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/pre_processing/contrast.py +0 -0
  21. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/pre_processing/crop.py +0 -0
  22. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/pre_processing/grayscale.py +0 -0
  23. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/pre_processing/resize.py +0 -0
  24. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/pre_processing/rotate.py +0 -0
  25. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/pre_processing/sharpen.py +0 -0
  26. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/utils/__init__.py +0 -0
  27. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO/utils/io_handler.py +0 -0
  28. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO_Python.egg-info/dependency_links.txt +0 -0
  29. {imagepro_python-0.2.0 → imagepro_python-0.3.0}/src/ImagePRO_Python.egg-info/requires.txt +0 -0
  30. {imagepro_python-0.2.0 → imagepro_python-0.3.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.3.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
@@ -7,7 +7,7 @@ where = ["src"]
7
7
 
8
8
  [project]
9
9
  name = "ImagePRO-Python"
10
- version = "0.2.0"
10
+ version = "0.3.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.*"
@@ -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.3.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,6 +14,7 @@ src/ImagePRO/pre_processing/__init__.py
14
14
  src/ImagePRO/pre_processing/blur.py
15
15
  src/ImagePRO/pre_processing/contrast.py
16
16
  src/ImagePRO/pre_processing/crop.py
17
+ src/ImagePRO/pre_processing/dataset_generator.py
17
18
  src/ImagePRO/pre_processing/grayscale.py
18
19
  src/ImagePRO/pre_processing/resize.py
19
20
  src/ImagePRO/pre_processing/rotate.py
File without changes