ImagePRO-Python 1.2.0__py3-none-any.whl → 1.2.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.
@@ -45,9 +45,12 @@ def capture_bulk_pictures(
45
45
  ) -> None:
46
46
  """Generate a dataset by capturing faces from webcam.
47
47
 
48
- Captures frames and saves preprocessed face images.
48
+ Captures frames from the webcam, detects faces, applies optional preprocessing,
49
+ and saves cropped face images to disk. This function is useful for creating
50
+ face recognition datasets with data augmentation.
51
+
49
52
  Processing pipeline (if enabled):
50
- median blur → laplacian sharpen → grayscale → resize → random rotate
53
+ average blur → laplacian sharpen → grayscale → resize → random rotate
51
54
 
52
55
  Args:
53
56
  folder_path: Base directory for dataset.
@@ -80,7 +83,7 @@ def capture_bulk_pictures(
80
83
  FileExistsError: If output folder exists
81
84
  RuntimeError: If camera access fails
82
85
  """
83
- # Validate numeric parameters
86
+ # Validate numeric parameters to ensure safe operation
84
87
  if not isinstance(num_images, int) or num_images <= 0:
85
88
  raise ValueError("'num_images' must be a positive integer")
86
89
 
@@ -93,20 +96,23 @@ def capture_bulk_pictures(
93
96
  if not isinstance(delay, (int, float)) or delay < 0:
94
97
  raise ValueError("'delay' must be a non-negative number")
95
98
 
96
- # Setup output directory
99
+ # Setup output directory structure
97
100
  base_dir = Path(folder_path)
98
101
  face_folder = base_dir / str(face_id)
99
102
 
103
+ # Create output folder (fail if exists to prevent accidental overwrites)
100
104
  try:
101
105
  face_folder.mkdir(parents=True, exist_ok=False)
102
106
  except FileExistsError as e:
103
107
  raise FileExistsError(f"Output folder already exists: {face_folder}") from e
104
108
 
105
- # Initialize camera and face detector
109
+ # Initialize camera capture
106
110
  cap = cv2.VideoCapture(camera_index)
107
111
  if not cap.isOpened():
108
112
  raise RuntimeError(f"Cannot access camera (index={camera_index})")
109
113
 
114
+ # Initialize MediaPipe face mesh detector for face detection
115
+ # Using face_mesh instead of face_detection for better accuracy
110
116
  face_mesh = mp.solutions.face_mesh.FaceMesh(
111
117
  max_num_faces=1,
112
118
  min_detection_confidence=min_confidence,
@@ -123,36 +129,40 @@ def capture_bulk_pictures(
123
129
  print("Failed to capture frame, skipping...")
124
130
  continue
125
131
 
126
- # Apply preprocessing pipeline
132
+ # Apply preprocessing pipeline in sequence
133
+ # Each step transforms the image and passes it to the next step
127
134
  processed = frame
128
135
 
129
136
  if apply_blur:
130
- # Reduce noise while keeping facial features
137
+ # Reduce noise while preserving facial features
131
138
  processed = blur.apply_average_blur(
132
139
  image=Image.from_array(processed),
133
140
  filter_size=3
134
141
  ).image
135
142
 
136
143
  if apply_sharpen:
137
- # Enhance edges with gentle sharpening
144
+ # Enhance edges with gentle sharpening for better feature detection
138
145
  processed = sharpen.apply_laplacian_sharpening(
139
146
  image=Image.from_array(processed),
140
147
  coefficient=1.0
141
148
  ).image
142
149
 
143
150
  if apply_grayscale:
151
+ # Convert to single-channel for reduced storage and faster processing
144
152
  processed = grayscale.convert_to_grayscale(
145
153
  image=Image.from_array(processed)
146
154
  ).image
147
155
 
148
156
  if apply_resize is not False:
157
+ # Resize to consistent dimensions (e.g., 224x224 for ML models)
149
158
  processed = resize.resize_image(
150
159
  image=Image.from_array(processed),
151
160
  new_size=apply_resize
152
161
  ).image
153
162
 
154
163
  if apply_rotate:
155
- # Apply random rotation with scaling
164
+ # Apply random rotation with scaling for data augmentation
165
+ # Rotation range: -45° to +45° with random scale factors
156
166
  angle = float(random.randint(-45, 45))
157
167
  scale = random.choice([1.0, 1.1, 1.2, 1.3])
158
168
  processed = rotate.rotate_image_custom(
@@ -161,11 +171,12 @@ def capture_bulk_pictures(
161
171
  scale=scale
162
172
  ).image
163
173
 
164
- # Save processed face image
174
+ # Detect and crop face from processed frame
165
175
  filename = f"{start_index + saved_count:04d}.jpg"
166
176
  output_path = face_folder / filename
167
177
 
168
178
  try:
179
+ # Detect face and crop to face region only
169
180
  result = detect_faces(
170
181
  image=Image.from_array(processed),
171
182
  max_faces=1,
@@ -173,18 +184,20 @@ def capture_bulk_pictures(
173
184
  face_mesh_obj=face_mesh
174
185
  )
175
186
 
187
+ # Save cropped face image
176
188
  result.save_as_img(str(output_path))
177
189
  saved_count += 1
178
190
 
191
+ # Add delay between captures to allow subject movement
179
192
  if delay > 0:
180
193
  time.sleep(delay)
181
194
 
182
195
  except ValueError:
183
- # Skip frames with no detected faces
196
+ # Skip frames with no detected faces (silent failure)
184
197
  continue
185
198
 
186
199
  finally:
187
- # Clean up resources
200
+ # Clean up resources: release camera and close OpenCV windows
188
201
  cap.release()
189
202
  cv2.destroyAllWindows()
190
203
 
ImagePRO/utils/result.py CHANGED
@@ -144,7 +144,22 @@ class Result:
144
144
  return self
145
145
 
146
146
  def flatten_rows(data):
147
- """Flatten any nested lists/tuples into rows suitable for CSV writing."""
147
+ """
148
+ Flatten nested lists/tuples into rows suitable for CSV writing.
149
+
150
+ Recursively processes nested data structures to create a flat list of rows
151
+ that can be written to a CSV file. Handles mixed nesting levels gracefully.
152
+
153
+ Args:
154
+ data: Nested list/tuple structure containing data to flatten.
155
+
156
+ Returns:
157
+ list[list[Any]]: Flattened list of rows, where each row is a list of values.
158
+
159
+ Example:
160
+ >>> flatten_rows([[1, 2], [3, [4, 5]]])
161
+ [[1, 2], [3, 4, 5]]
162
+ """
148
163
  rows = []
149
164
  for item in data:
150
165
  if isinstance(item, (list, tuple)):
@@ -0,0 +1,200 @@
1
+ Metadata-Version: 2.4
2
+ Name: ImagePRO-Python
3
+ Version: 1.2.1
4
+ Summary: Professional & modular image processing library with OpenCV, MediaPipe, and YOLO integration.
5
+ Author-email: Parsa Safaie <parsasafaie.2568@proton.me>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/parsasafaie/ImagePRO
8
+ Project-URL: Repository, https://github.com/parsasafaie/ImagePRO.git
9
+ Project-URL: Documentation, https://github.com/parsasafaie/ImagePRO#readme
10
+ Project-URL: Issues, https://github.com/parsasafaie/ImagePRO/issues
11
+ Keywords: opencv,mediapipe,computer-vision,face,pose,yolo,image-processing
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: License :: OSI Approved :: MIT License
21
+ Classifier: Operating System :: OS Independent
22
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Requires-Python: <3.13,>=3.9
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: numpy<2.1.0,>=1.24
29
+ Requires-Dist: opencv-python<5.0,>=4.8
30
+ Requires-Dist: matplotlib<4.0,>=3.7
31
+ Provides-Extra: yolo
32
+ Requires-Dist: ultralytics<9.0,>=8.2; extra == "yolo"
33
+ Provides-Extra: mediapipe
34
+ Requires-Dist: mediapipe<=0.10.11,>=0.10.0; extra == "mediapipe"
35
+ Provides-Extra: insightface
36
+ Requires-Dist: insightface<0.8,>=0.7; extra == "insightface"
37
+ Requires-Dist: onnxruntime<2.0,>=1.16; extra == "insightface"
38
+ Provides-Extra: full
39
+ Requires-Dist: mediapipe<=0.10.11,>=0.10.0; extra == "full"
40
+ Requires-Dist: ultralytics<9.0,>=8.2; extra == "full"
41
+ Requires-Dist: insightface<0.8,>=0.7; extra == "full"
42
+ Requires-Dist: onnxruntime<2.0,>=1.16; extra == "full"
43
+ Dynamic: license-file
44
+
45
+ # ImagePRO
46
+
47
+ > **Professional & Modular Image Processing Library in Python**
48
+
49
+ **ImagePRO** is a clean, modular, and easy-to-use Python library for image processing tasks, built with OpenCV, MediaPipe, YOLO, and InsightFace. Designed to be extensible for developers, ImagePRO provides a consistent API across all modules with comprehensive error handling and professional-grade documentation.
50
+
51
+ Whether you're working on computer vision pipelines, preprocessing images for AI models, or simply automating batch image edits — **ImagePRO** gives you powerful tools with minimal effort.
52
+
53
+ ## ✨ Features
54
+
55
+ ### **Image I/O & Management**
56
+ - Flexible input/output handling (file paths or numpy arrays)
57
+ - Batch processing capabilities
58
+ - Multiple format support (JPEG, PNG, CSV, etc.)
59
+
60
+ ### **Pre-processing & Enhancement**
61
+ - **Basic Operations**: Resize, crop, rotate (90°, 180°, 270°, custom angles), grayscale conversion
62
+ - **Filtering**: Blur filters (average, Gaussian, median, bilateral), sharpening filters (Laplacian, Unsharp Masking)
63
+ - **Enhancement**: Contrast enhancement (CLAHE, GHE, stretching)
64
+ - **Dataset Generation**: Automated image capture with preprocessing pipeline
65
+
66
+ ### **Human Analysis**
67
+ - **Face Analysis**: 468-point mesh, head pose estimation, eye status detection, face comparison, face cropping
68
+ - **Body Analysis**: Pose estimation, hand tracking (21 landmarks)
69
+ - **Real-time Processing**: Live webcam analysis for all modules
70
+
71
+ ### **Object Detection**
72
+ - **YOLO Integration**: Multiple accuracy levels (nano to extra-large)
73
+ - **Flexible Models**: Pre-trained or custom model support
74
+ - **Batch Processing**: Efficient handling of multiple images
75
+
76
+ ## 🚀 Installation
77
+
78
+ ### From PyPI
79
+ ```bash
80
+ pip install ImagePRO-Python
81
+ ```
82
+
83
+ ### From Source
84
+ ```bash
85
+ git clone https://github.com/parsasafaie/ImagePRO.git
86
+ cd ImagePRO
87
+
88
+ python -m venv .venv
89
+
90
+ source .venv/bin/activate # macOS/Linux
91
+ .venv\Scripts\activate # Windows
92
+
93
+ # Base dependencies
94
+ pip install -r requirements/base.txt
95
+
96
+ # Optional dependencies
97
+ # For YOLO object detection
98
+ pip install -r requirements/yolo.txt
99
+
100
+ # For MediaPipe human analysis
101
+ pip install -r requirements/mediapipe.txt
102
+
103
+ # For InsightFace advanced face analysis
104
+ pip install -r requirements/insightface.txt
105
+
106
+ # Or install everything
107
+ pip install -r requirements/full.txt
108
+ ```
109
+
110
+ See the [Directory Structure](/PROJECT_STRUCTURE.md#directory-structure) section in [PROJECT_STRUCTURE.md](/PROJECT_STRUCTURE.md) for details on which modules need which requirements.
111
+
112
+ ## 📖 Quick Start
113
+
114
+ ```python
115
+ from ImagePRO.pre_processing.blur import apply_average_blur
116
+ from ImagePRO.human_analysis.face_analysis.face_mesh_analysis import analyze_face_mesh
117
+ from ImagePRO.human_analysis.body_analysis.body_pose_estimation import detect_body_pose
118
+ from ImagePRO.object_analysis.object_detection import detect_objects
119
+ from ImagePRO.utils.image import Image
120
+
121
+ # Load an image
122
+ image = Image.from_path("person_and_objects.jpg")
123
+ # Or from numpy array: image = Image.from_array(np_array)
124
+
125
+ # Apply average blur
126
+ blur_result = apply_average_blur(image=image)
127
+ blur_result.save_as_img("blurred_output.jpg")
128
+
129
+ # Analyze face mesh (468 landmarks)
130
+ face_mesh_result = analyze_face_mesh(image=image)
131
+ print(f"Detected {len(face_mesh_result.data)} face landmarks")
132
+ face_mesh_result.save_as_csv("face_landmarks.csv")
133
+
134
+ # Detect body pose (33 landmarks)
135
+ body_pose_result = detect_body_pose(image=image)
136
+ print(f"Body pose data: {body_pose_result.data}")
137
+
138
+ # Detect objects with YOLO
139
+ object_detection_result = detect_objects(
140
+ image=image,
141
+ accuracy_level=3, # 1=nano, 2=small, 3=medium, 4=large, 5=extra-large
142
+ confidence=0.5
143
+ )
144
+ print(f"Detected {len(object_detection_result.data)} objects")
145
+ object_detection_result.save_as_img("detections.jpg")
146
+ ```
147
+
148
+ > **Note**: These are basic examples. Each module contains many more functions with extensive customization options. Explore the module-specific README files for detailed documentation.
149
+
150
+ ## 📚 Documentation
151
+
152
+ Each module includes comprehensive documentation with detailed examples:
153
+
154
+ - **[Pre-processing](src/ImagePRO/pre_processing/README.md)**: Image manipulation, filtering, and enhancement
155
+ - **[Human Analysis](src/ImagePRO/human_analysis/README.md)**: Face and body analysis tools
156
+ - [Face Analysis](src/ImagePRO/human_analysis/face_analysis/README.md): Face mesh, pose estimation, eye status, comparison
157
+ - [Body Analysis](src/ImagePRO/human_analysis/body_analysis/README.md): Body pose and hand tracking
158
+ - **[Object Analysis](src/ImagePRO/object_analysis/README.md)**: YOLO-based object detection
159
+ - **[Utils](src/ImagePRO/utils/README.md)**: Shared utilities and I/O handling
160
+
161
+ For detailed project structure and development guidelines, see [PROJECT_STRUCTURE.md](PROJECT_STRUCTURE.md).
162
+
163
+ ## 🏗️ Architecture
164
+
165
+ ImagePRO is built with a modular architecture designed for extensibility and maintainability:
166
+
167
+ - **Clean Separation of Concerns**: Each module handles a specific domain
168
+ - **Consistent API Patterns**: All functions follow the same input/output conventions
169
+ - **Shared Utilities**: Common `Image` and `Result` classes for unified I/O
170
+ - **Professional Error Handling**: Comprehensive validation with clear error messages
171
+ - **Type Safety**: Full type hints throughout the codebase
172
+ - **Documentation**: Google-style docstrings for all functions
173
+
174
+ ### Key Design Principles
175
+ - **Immutable Design**: Image objects are immutable, operations return new instances
176
+ - **Functional Style**: Stateless functions that can be easily composed
177
+ - **Result Objects**: Unified return type containing image, data, and metadata
178
+ - **Keyword Arguments**: All optional parameters use keyword-only syntax
179
+
180
+ ## 🤝 Contributing
181
+
182
+ Contributions are welcome! Please feel free to submit a Pull Request.
183
+
184
+ ### Development Setup
185
+ 1. Fork the repository
186
+ 2. Create a virtual environment: `python -m venv .venv`
187
+ 3. Install dependencies: `pip install -r requirements/full.txt`
188
+ 4. Follow the coding standards outlined in [PROJECT_STRUCTURE.md](PROJECT_STRUCTURE.md)
189
+ 5. Add tests for new features
190
+ 6. Update documentation as needed
191
+
192
+ ### Reporting Issues
193
+ If you encounter any bugs or have feature requests, please open an issue on the GitHub repository with:
194
+ - Description of the problem or feature request
195
+ - Steps to reproduce (for bugs)
196
+ - Expected vs. actual behavior
197
+ - Environment details (OS, Python version, etc.)
198
+
199
+ ## 📄 License
200
+ This project is licensed under the MIT License – see the [LICENSE](LICENSE) file for details.
@@ -15,7 +15,7 @@ ImagePRO/pre_processing/__init__.py,sha256=nXUhE8RnDyW7T93fKsSDPfqzGHIW50OvgQvzn
15
15
  ImagePRO/pre_processing/blur.py,sha256=zPWUKLEoKiL6kYwnZOtGRWBHM-dgEQ8WWdDt8_wGc0s,7961
16
16
  ImagePRO/pre_processing/contrast.py,sha256=XG69VsX3EKWIPDcQYm4D9qT7sA_BSP-sppSAa8qRUhA,5247
17
17
  ImagePRO/pre_processing/crop.py,sha256=p0esuZcn4-YsqcniDUmsVfPoWasxVH1OqzNBra8Pw4M,2442
18
- ImagePRO/pre_processing/dataset_generator.py,sha256=Vf21SwzsKRBHespvAY6N7Ozq_G0GrL7T5sAk0FOyEk0,6625
18
+ ImagePRO/pre_processing/dataset_generator.py,sha256=ekd_TnyflWKjJ6sYCiWc3vN2Q14cKiwZ1InOCslxoFM,7653
19
19
  ImagePRO/pre_processing/grayscale.py,sha256=MRCsFRIaL45sYVHzhuNyZBXsP7PF-yorn0Wt7xONvpY,1781
20
20
  ImagePRO/pre_processing/histogram.py,sha256=t1ykGUwB9ZbvO6J3bGPh4fDvrk4AJua1dN2BWzHIRIQ,2888
21
21
  ImagePRO/pre_processing/resize.py,sha256=GH3ObPe67ypPQG3a7ncrNR5WNDqGibXebAiuRXr6L10,1760
@@ -23,9 +23,9 @@ ImagePRO/pre_processing/rotate.py,sha256=wqV2Qm7mIyvKTSFdwzr1tNAGnMG7rl5M3BRqC5m
23
23
  ImagePRO/pre_processing/sharpen.py,sha256=C5AOxQNBL80JenkztlyRBV7yuCHqxG5dTGbRhtVRT9M,3544
24
24
  ImagePRO/utils/__init__.py,sha256=McVd-o9KtKOpAVYbLi19KxsatPPFFF-Qbt0gdgY3Ln8,170
25
25
  ImagePRO/utils/image.py,sha256=x93cBNycNOgET20a__TxZ9ZQo_2G84uB7QjXjBo9f8M,3973
26
- ImagePRO/utils/result.py,sha256=DAFaFZ5jZZ7C2YrhRs6h2PAei6Mbv1Mu8xX_2NQ7c6Y,5605
27
- imagepro_python-1.2.0.dist-info/licenses/LICENSE,sha256=sehkHN7dbe5umrINZJyJjIf9VTemZSgTfJlq6iIsbJQ,1069
28
- imagepro_python-1.2.0.dist-info/METADATA,sha256=qxax-bzhfBbcMHNP4nbRKHBVMJO2MSkTDyIQiWcmMGA,2095
29
- imagepro_python-1.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
30
- imagepro_python-1.2.0.dist-info/top_level.txt,sha256=UOuPzsoWrVKXgUupOSI96shJ6wE8Fhz-8bm8oMlLC3s,9
31
- imagepro_python-1.2.0.dist-info/RECORD,,
26
+ ImagePRO/utils/result.py,sha256=rGZX0FJ-dpA4v_m_GUO6ni0kCfcNJRnOjztbyRX9d88,6065
27
+ imagepro_python-1.2.1.dist-info/licenses/LICENSE,sha256=sehkHN7dbe5umrINZJyJjIf9VTemZSgTfJlq6iIsbJQ,1069
28
+ imagepro_python-1.2.1.dist-info/METADATA,sha256=KVaRtAoER1Ss2HS1R8w6YrIrfwt8zH5bw5u_29sMjGA,8513
29
+ imagepro_python-1.2.1.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
30
+ imagepro_python-1.2.1.dist-info/top_level.txt,sha256=UOuPzsoWrVKXgUupOSI96shJ6wE8Fhz-8bm8oMlLC3s,9
31
+ imagepro_python-1.2.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (82.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,44 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: ImagePRO-Python
3
- Version: 1.2.0
4
- Summary: Professional & modular image processing library with OpenCV, MediaPipe, and YOLO integration.
5
- Author-email: Parsa Safaie <parsasafaie.2568@proton.me>
6
- License: MIT
7
- Project-URL: Homepage, https://github.com/parsasafaie/ImagePRO
8
- Project-URL: Repository, https://github.com/parsasafaie/ImagePRO.git
9
- Project-URL: Documentation, https://github.com/parsasafaie/ImagePRO#readme
10
- Project-URL: Issues, https://github.com/parsasafaie/ImagePRO/issues
11
- Keywords: opencv,mediapipe,computer-vision,face,pose,yolo,image-processing
12
- Classifier: Development Status :: 4 - Beta
13
- Classifier: Intended Audience :: Developers
14
- Classifier: Intended Audience :: Science/Research
15
- Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3.9
17
- Classifier: Programming Language :: Python :: 3.10
18
- Classifier: Programming Language :: Python :: 3.11
19
- Classifier: Programming Language :: Python :: 3.12
20
- Classifier: Programming Language :: Python :: 3.13
21
- Classifier: License :: OSI Approved :: MIT License
22
- Classifier: Operating System :: OS Independent
23
- Classifier: Topic :: Scientific/Engineering :: Image Processing
24
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
- Requires-Python: <3.13,>=3.9
27
- Description-Content-Type: text/markdown
28
- License-File: LICENSE
29
- Requires-Dist: numpy<3.0,>=1.24
30
- Requires-Dist: opencv-python<6.0,>=4.8
31
- Requires-Dist: matplotlib<4.0,>=3.7
32
- Provides-Extra: yolo
33
- Requires-Dist: ultralytics<10.0,>=8.2; extra == "yolo"
34
- Provides-Extra: mediapipe
35
- Requires-Dist: mediapipe<1.0,>=0.10; extra == "mediapipe"
36
- Provides-Extra: insightface
37
- Requires-Dist: insightface<1.0,>=0.7; extra == "insightface"
38
- Requires-Dist: onnxruntime<3.0,>=1.16; extra == "insightface"
39
- Provides-Extra: full
40
- Requires-Dist: mediapipe<1.0,>=0.10; extra == "full"
41
- Requires-Dist: ultralytics<10.0,>=8.2; extra == "full"
42
- Requires-Dist: insightface<1.0,>=0.7; extra == "full"
43
- Requires-Dist: onnxruntime<3.0,>=1.16; extra == "full"
44
- Dynamic: license-file