datasetforge 0.1.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shruti Shirpurkar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: datasetforge
3
+ Version: 0.1.0
4
+ Summary: Computer Vision Dataset Creation Tool
5
+ Author: Shruti Shirpurkar
6
+ Requires-Python: >=3.8
7
+ License-File: LICENSE
8
+ Requires-Dist: opencv-python
9
+ Requires-Dist: numpy
10
+ Dynamic: author
11
+ Dynamic: license-file
12
+ Dynamic: requires-dist
13
+ Dynamic: requires-python
14
+ Dynamic: summary
@@ -0,0 +1,33 @@
1
+ # DatasetForge
2
+
3
+ DatasetForge is a Python library for creating, annotating, and managing image datasets from videos and webcams.
4
+
5
+ ## Features
6
+ - Convert videos into frame datasets
7
+ - Annotate images with bounding boxes
8
+ - Count objects in images
9
+ - Preview datasets in grids
10
+ - Capture images from webcam
11
+ - Generate dataset statistics
12
+
13
+ ## Installation
14
+ ```bash
15
+ pip install datasetforge
16
+
17
+ ##EXAMPLE USAGE
18
+ import datasetforge as df
19
+
20
+ # Convert video to dataset
21
+ df.video_to_dataset("dataset/video.mp4", "dataset/video_frames")
22
+
23
+ # View dataset stats
24
+ df.dataset_stats("dataset/video_frames")
25
+
26
+ # Annotate a single image
27
+ df.annotate("dataset/video_frames/frame_0.jpg", save_folder="dataset/annotated")
28
+
29
+ # Count objects
30
+ df.count_objects("dataset/video_frames/frame_0.jpg")
31
+
32
+ # Preview first 9 images
33
+ df.preview("dataset/video_frames", max_images=9)
@@ -0,0 +1,3 @@
1
+ from .video_dataset import video_to_dataset
2
+ from .object_counter import dataset_stats
3
+ from .annotator import annotate_frames
@@ -0,0 +1,49 @@
1
+ import cv2
2
+ import os
3
+ import glob
4
+
5
+ def annotate(image_path, save_folder="dataset/annotated"):
6
+ os.makedirs(save_folder, exist_ok=True)
7
+ save_path = os.path.join(save_folder, os.path.basename(image_path))
8
+
9
+ if os.path.exists(save_path):
10
+ img = cv2.imread(image_path)
11
+ cv2.putText(img, "Already annotated", (10, 30),
12
+ cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
13
+ cv2.imshow("Annotation", img)
14
+ cv2.waitKey(500)
15
+ cv2.destroyAllWindows()
16
+ print(f"Skipping {image_path}, already annotated.")
17
+ return
18
+
19
+ img = cv2.imread(image_path)
20
+ if img is None:
21
+ print(f"Cannot read image: {image_path}")
22
+ return
23
+
24
+ while True:
25
+ r = cv2.selectROI("Select ROI (SPACE=OK, s=Skip, q=Quit)", img, False, False)
26
+
27
+ if cv2.waitKey(1) & 0xFF == ord('q'):
28
+ cv2.destroyAllWindows()
29
+ print("Quitting annotation.")
30
+ exit(0)
31
+ elif cv2.waitKey(1) & 0xFF == ord('s'):
32
+ cv2.destroyAllWindows()
33
+ print(f"Skipped {image_path}")
34
+ return
35
+ elif r[2] > 0 and r[3] > 0:
36
+ x, y, w, h = r
37
+ crop_img = img[y:y+h, x:x+w]
38
+ cv2.imwrite(save_path, crop_img)
39
+ cv2.destroyAllWindows()
40
+ print(f"Annotated saved: {save_path}")
41
+ return
42
+ else:
43
+ print(f"No ROI selected for {image_path}")
44
+ cv2.destroyAllWindows()
45
+ return
46
+
47
+ def annotate_frames(frame_folder="dataset/video_frames", save_folder="dataset/annotated"):
48
+ for img_path in sorted(glob.glob(f"{frame_folder}/*.jpg")):
49
+ annotate(img_path, save_folder)
@@ -0,0 +1,36 @@
1
+ from ultralytics import YOLO
2
+ import cv2
3
+ import os
4
+
5
+ model = YOLO("yolov8n.pt")
6
+
7
+ def auto_annotate(image_path, label_folder="dataset/labels"):
8
+ os.makedirs(label_folder, exist_ok=True)
9
+
10
+ results = model(image_path)
11
+ img = cv2.imread(image_path)
12
+ h, w = img.shape[:2]
13
+
14
+ base = os.path.splitext(os.path.basename(image_path))[0]
15
+ label_file = os.path.join(label_folder, base + ".txt")
16
+
17
+ lines = []
18
+
19
+ for r in results:
20
+ boxes = r.boxes.xyxy
21
+ for box in boxes:
22
+ x1, y1, x2, y2 = box
23
+ bw = x2 - x1
24
+ bh = y2 - y1
25
+ xc = (x1 + bw/2)/w
26
+ yc = (y1 + bh/2)/h
27
+ bw /= w
28
+ bh /= h
29
+ lines.append(f"0 {xc} {yc} {bw} {bh}")
30
+
31
+ if lines:
32
+ with open(label_file, "w") as f:
33
+ for l in lines:
34
+ f.write(l+"\n")
35
+
36
+ print("Auto annotated:", image_path)
@@ -0,0 +1,30 @@
1
+ import os
2
+ import random
3
+ import shutil
4
+
5
+ def split_dataset(frame_folder="dataset/annotated",
6
+ train_folder="dataset/train",
7
+ val_folder="dataset/val",
8
+ split=0.8):
9
+
10
+ os.makedirs(train_folder, exist_ok=True)
11
+ os.makedirs(val_folder, exist_ok=True)
12
+
13
+ images = [i for i in os.listdir(frame_folder) if i.endswith(".jpg")]
14
+ random.shuffle(images)
15
+
16
+ split_index = int(len(images) * split)
17
+ train = images[:split_index]
18
+ val = images[split_index:]
19
+
20
+ for img in train:
21
+ shutil.copy(os.path.join(frame_folder, img),
22
+ os.path.join(train_folder, img))
23
+
24
+ for img in val:
25
+ shutil.copy(os.path.join(frame_folder, img),
26
+ os.path.join(val_folder, img))
27
+
28
+ print("Dataset Split Complete")
29
+ print("Train:", len(train))
30
+ print("Val:", len(val))
@@ -0,0 +1,23 @@
1
+ import cv2
2
+ import os
3
+ import numpy as np
4
+
5
+ def preview(folder, cols=4):
6
+ files = os.listdir(folder)[:cols*cols]
7
+ imgs = []
8
+
9
+ for f in files:
10
+ img = cv2.imread(os.path.join(folder, f))
11
+ if img is None:
12
+ continue
13
+ img = cv2.resize(img, (200,200))
14
+ imgs.append(img)
15
+
16
+ rows = []
17
+ for i in range(0, len(imgs), cols):
18
+ rows.append(np.hstack(imgs[i:i+cols]))
19
+ if rows:
20
+ grid = np.vstack(rows)
21
+ cv2.imshow("Preview", grid)
22
+ cv2.waitKey(0)
23
+ cv2.destroyAllWindows()
@@ -0,0 +1,23 @@
1
+ import cv2
2
+ import os
3
+ import numpy as np
4
+
5
+ def dataset_stats(folder):
6
+ """Show basic stats of dataset"""
7
+ files = os.listdir(folder)
8
+ total = 0
9
+ widths = []
10
+ heights = []
11
+
12
+ for f in files:
13
+ img = cv2.imread(os.path.join(folder, f))
14
+ if img is None:
15
+ continue
16
+ h, w, _ = img.shape
17
+ widths.append(w)
18
+ heights.append(h)
19
+ total += 1
20
+
21
+ print(f"Images: {total}")
22
+ print(f"Average width: {int(np.mean(widths))}")
23
+ print(f"Average height: {int(np.mean(heights))}")
@@ -0,0 +1,24 @@
1
+ import os
2
+ import cv2
3
+
4
+ def dataset_stats(folder_path):
5
+ images = [f for f in os.listdir(folder_path) if f.endswith(('.png', '.jpg', '.jpeg'))]
6
+ print(f"Images: {len(images)}")
7
+ if not images:
8
+ return
9
+ widths, heights = [], []
10
+ for img_name in images:
11
+ img = cv2.imread(os.path.join(folder_path, img_name))
12
+ h, w = img.shape[:2]
13
+ widths.append(w)
14
+ heights.append(h)
15
+ print(f"Average width: {sum(widths)//len(widths)}")
16
+ print(f"Average height: {sum(heights)//len(heights)}")
17
+
18
+ def preview_dataset(folder_path, num_images=5):
19
+ images = [f for f in os.listdir(folder_path) if f.endswith(('.png', '.jpg', '.jpeg'))][:num_images]
20
+ for img_name in images:
21
+ img = cv2.imread(os.path.join(folder_path, img_name))
22
+ cv2.imshow("Preview", img)
23
+ cv2.waitKey(500)
24
+ cv2.destroyAllWindows()
@@ -0,0 +1,9 @@
1
+ import os
2
+
3
+ def dataset_stats(folder="dataset/annotated"):
4
+ files = [f for f in os.listdir(folder) if f.endswith(".jpg")]
5
+ print("\nDATASET STATISTICS")
6
+ print("-------------------")
7
+ print(f"Annotated Images: {len(files)}")
8
+ # You can extend to count objects if needed
9
+ print(f"Total Objects: 0")
@@ -0,0 +1,22 @@
1
+ import cv2
2
+ import os
3
+
4
+ def video_to_dataset(video_path="dataset/video.mp4", output_folder="dataset/video_frames"):
5
+ if not os.path.exists(video_path):
6
+ print("No video found. Put video.mp4 in project folder.")
7
+ return
8
+
9
+ os.makedirs(output_folder, exist_ok=True)
10
+ cap = cv2.VideoCapture(video_path)
11
+ count = 0
12
+
13
+ while True:
14
+ ret, frame = cap.read()
15
+ if not ret:
16
+ break
17
+ frame_path = os.path.join(output_folder, f"frame_{count:04d}.jpg")
18
+ cv2.imwrite(frame_path, frame)
19
+ count += 1
20
+
21
+ cap.release()
22
+ print(f"Extracted {count} frames to {output_folder}")
@@ -0,0 +1,35 @@
1
+ # datasetforge/webcam_dataset.py
2
+ import cv2
3
+ import os
4
+
5
+ def webcam_to_dataset(output_folder="dataset/video_frames"):
6
+ """
7
+ Capture frames from webcam and save as images.
8
+
9
+ Args:
10
+ output_folder (str): Folder to save captured frames.
11
+ """
12
+ os.makedirs(output_folder, exist_ok=True)
13
+ cap = cv2.VideoCapture(0)
14
+ count = 0
15
+
16
+ print("Press 'SPACE' to capture frame, 'q' to quit")
17
+
18
+ while True:
19
+ ret, frame = cap.read()
20
+ if not ret:
21
+ break
22
+ cv2.imshow("Webcam", frame)
23
+ key = cv2.waitKey(1) & 0xFF
24
+
25
+ if key == ord(" "):
26
+ filename = os.path.join(output_folder, f"frame_{count:04d}.jpg")
27
+ cv2.imwrite(filename, frame)
28
+ print(f"Saved: {filename}")
29
+ count += 1
30
+ elif key == ord("q"):
31
+ break
32
+
33
+ cap.release()
34
+ cv2.destroyAllWindows()
35
+ print(f"Captured {count} frames to {output_folder}")
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: datasetforge
3
+ Version: 0.1.0
4
+ Summary: Computer Vision Dataset Creation Tool
5
+ Author: Shruti Shirpurkar
6
+ Requires-Python: >=3.8
7
+ License-File: LICENSE
8
+ Requires-Dist: opencv-python
9
+ Requires-Dist: numpy
10
+ Dynamic: author
11
+ Dynamic: license-file
12
+ Dynamic: requires-dist
13
+ Dynamic: requires-python
14
+ Dynamic: summary
@@ -0,0 +1,19 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ datasetforge/__init__.py
6
+ datasetforge/annotator.py
7
+ datasetforge/auto_annotate.py
8
+ datasetforge/autosplit.py
9
+ datasetforge/dataset_preview.py
10
+ datasetforge/dataset_stats.py
11
+ datasetforge/dataset_viewer.py
12
+ datasetforge/object_counter.py
13
+ datasetforge/video_dataset.py
14
+ datasetforge/webcam_dataset.py
15
+ datasetforge.egg-info/PKG-INFO
16
+ datasetforge.egg-info/SOURCES.txt
17
+ datasetforge.egg-info/dependency_links.txt
18
+ datasetforge.egg-info/requires.txt
19
+ datasetforge.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ opencv-python
2
+ numpy
@@ -0,0 +1 @@
1
+ datasetforge
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,14 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="datasetforge",
5
+ version="0.1.0",
6
+ author="Shruti Shirpurkar",
7
+ description="Computer Vision Dataset Creation Tool",
8
+ packages=find_packages(),
9
+ install_requires=[
10
+ "opencv-python",
11
+ "numpy"
12
+ ],
13
+ python_requires=">=3.8",
14
+ )