smart-study 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.
- smart_study-0.1.0/PKG-INFO +66 -0
- smart_study-0.1.0/README.md +50 -0
- smart_study-0.1.0/pyproject.toml +30 -0
- smart_study-0.1.0/setup.cfg +4 -0
- smart_study-0.1.0/smart_study/__init__.py +5 -0
- smart_study-0.1.0/smart_study/assets/alarm.mp3 +0 -0
- smart_study-0.1.0/smart_study/assets/faudio.mp3 +0 -0
- smart_study-0.1.0/smart_study/assets/paudio.mp3 +0 -0
- smart_study-0.1.0/smart_study/assets/yolov8n.pt +0 -0
- smart_study-0.1.0/smart_study/study.py +99 -0
- smart_study-0.1.0/smart_study.egg-info/PKG-INFO +66 -0
- smart_study-0.1.0/smart_study.egg-info/SOURCES.txt +13 -0
- smart_study-0.1.0/smart_study.egg-info/dependency_links.txt +1 -0
- smart_study-0.1.0/smart_study.egg-info/requires.txt +5 -0
- smart_study-0.1.0/smart_study.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: smart-study
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Webcam-based study distraction monitor
|
|
5
|
+
Classifier: Programming Language :: Python :: 3
|
|
6
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
7
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
8
|
+
Classifier: Topic :: Education
|
|
9
|
+
Requires-Python: <3.13,>=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: opencv-python>=4.8
|
|
12
|
+
Requires-Dist: cvzone>=1.6
|
|
13
|
+
Requires-Dist: ultralytics>=8.0
|
|
14
|
+
Requires-Dist: pygame>=2.5
|
|
15
|
+
Requires-Dist: mediapipe>=0.10
|
|
16
|
+
|
|
17
|
+
# smart-study
|
|
18
|
+
|
|
19
|
+
Webcam-based study distraction monitor. It watches for prolonged eye closure, a missing/covered face, and cell phones, then displays a warning and plays an alert.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
Python 3.11 is recommended on Windows. The computer needs a webcam and audio output.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
python -m pip install smart-study
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Use as a Python module
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from smart_study import study
|
|
33
|
+
|
|
34
|
+
study() # Uses camera 0; press Q in the video window to stop.
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Choose another camera by passing its index:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
study(camera_index=1)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Importing `smart_study` does not start the webcam. The monitor starts only when `study()` is called.
|
|
44
|
+
|
|
45
|
+
## Run from a source checkout
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
python -m pip install -e .
|
|
49
|
+
python app.py
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The distribution includes the YOLO model and alert audio assets. Installation is relatively large because the computer-vision dependencies include PyTorch through Ultralytics. Python versions below 3.13 are currently declared because MediaPipe and the selected dependency set may not be available together on newer Python versions.
|
|
53
|
+
|
|
54
|
+
## Build and upload to PyPI
|
|
55
|
+
|
|
56
|
+
Update the version in `pyproject.toml` for each release, then:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
python -m pip install --upgrade build twine
|
|
60
|
+
python -m build
|
|
61
|
+
python -m twine check dist/*
|
|
62
|
+
python -m twine upload dist/*
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
PyPI distribution name: `smart-study`
|
|
66
|
+
Python import name: `smart_study`
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# smart-study
|
|
2
|
+
|
|
3
|
+
Webcam-based study distraction monitor. It watches for prolonged eye closure, a missing/covered face, and cell phones, then displays a warning and plays an alert.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Python 3.11 is recommended on Windows. The computer needs a webcam and audio output.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
python -m pip install smart-study
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use as a Python module
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from smart_study import study
|
|
17
|
+
|
|
18
|
+
study() # Uses camera 0; press Q in the video window to stop.
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Choose another camera by passing its index:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
study(camera_index=1)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Importing `smart_study` does not start the webcam. The monitor starts only when `study()` is called.
|
|
28
|
+
|
|
29
|
+
## Run from a source checkout
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
python -m pip install -e .
|
|
33
|
+
python app.py
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The distribution includes the YOLO model and alert audio assets. Installation is relatively large because the computer-vision dependencies include PyTorch through Ultralytics. Python versions below 3.13 are currently declared because MediaPipe and the selected dependency set may not be available together on newer Python versions.
|
|
37
|
+
|
|
38
|
+
## Build and upload to PyPI
|
|
39
|
+
|
|
40
|
+
Update the version in `pyproject.toml` for each release, then:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
python -m pip install --upgrade build twine
|
|
44
|
+
python -m build
|
|
45
|
+
python -m twine check dist/*
|
|
46
|
+
python -m twine upload dist/*
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
PyPI distribution name: `smart-study`
|
|
50
|
+
Python import name: `smart_study`
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "smart-study"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Webcam-based study distraction monitor"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9,<3.13"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"opencv-python>=4.8",
|
|
13
|
+
"cvzone>=1.6",
|
|
14
|
+
"ultralytics>=8.0",
|
|
15
|
+
"pygame>=2.5",
|
|
16
|
+
"mediapipe>=0.10",
|
|
17
|
+
]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Operating System :: Microsoft :: Windows",
|
|
22
|
+
"Topic :: Education",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[tool.setuptools]
|
|
26
|
+
packages = ["smart_study"]
|
|
27
|
+
include-package-data = true
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.package-data]
|
|
30
|
+
smart_study = ["assets/*.mp3", "assets/*.pt"]
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Run the webcam-based Smart Study distraction monitor."""
|
|
2
|
+
|
|
3
|
+
from importlib.resources import files
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def study(camera_index: int = 0) -> None:
|
|
7
|
+
"""Start monitoring with the selected camera; press Q in the window to stop."""
|
|
8
|
+
import cv2
|
|
9
|
+
import cvzone
|
|
10
|
+
import pygame
|
|
11
|
+
from cvzone.FaceMeshModule import FaceMeshDetector
|
|
12
|
+
from ultralytics import YOLO
|
|
13
|
+
|
|
14
|
+
assets = files("smart_study").joinpath("assets")
|
|
15
|
+
# importlib.resources paths are ordinary filesystem paths for a normal wheel install.
|
|
16
|
+
pygame.mixer.init()
|
|
17
|
+
alarm_sleep = pygame.mixer.Sound(str(assets.joinpath("alarm.mp3")))
|
|
18
|
+
alarm_facehide = pygame.mixer.Sound(str(assets.joinpath("faudio.mp3")))
|
|
19
|
+
alarm_phone = pygame.mixer.Sound(str(assets.joinpath("paudio.mp3")))
|
|
20
|
+
cap = cv2.VideoCapture(camera_index)
|
|
21
|
+
face_detector = FaceMeshDetector(maxFaces=1)
|
|
22
|
+
model_path = assets.joinpath("yolov8n.pt")
|
|
23
|
+
with model_path.open("rb") as model_file:
|
|
24
|
+
model_header = model_file.read(128)
|
|
25
|
+
if model_header.startswith(b"version https://git-lfs.github.com/spec/v1"):
|
|
26
|
+
raise RuntimeError("YOLO weights are a Git LFS pointer. Download the actual yolov8n.pt weights before installing the package.")
|
|
27
|
+
phone_detector = YOLO(str(model_path))
|
|
28
|
+
class_names = phone_detector.names
|
|
29
|
+
|
|
30
|
+
left_eye_top, left_eye_bottom = 159, 145
|
|
31
|
+
face_left, face_right = 130, 243
|
|
32
|
+
closed_frames = covered_frames = 0
|
|
33
|
+
current_playing = None
|
|
34
|
+
try:
|
|
35
|
+
while True:
|
|
36
|
+
success, img = cap.read()
|
|
37
|
+
if not success:
|
|
38
|
+
break
|
|
39
|
+
|
|
40
|
+
is_audio_busy = pygame.mixer.get_busy()
|
|
41
|
+
if not is_audio_busy:
|
|
42
|
+
current_playing = None
|
|
43
|
+
|
|
44
|
+
img, faces = face_detector.findFaceMesh(img, draw=False)
|
|
45
|
+
is_sleepy = is_face_covered = False
|
|
46
|
+
if faces:
|
|
47
|
+
covered_frames = 0
|
|
48
|
+
face = faces[0]
|
|
49
|
+
eye_dist, _ = face_detector.findDistance(face[left_eye_top], face[left_eye_bottom])
|
|
50
|
+
face_dist, _ = face_detector.findDistance(face[face_left], face[face_right])
|
|
51
|
+
ratio = (eye_dist / face_dist) * 100
|
|
52
|
+
closed_frames = closed_frames + 1 if ratio < 11.0 else 0
|
|
53
|
+
is_sleepy = closed_frames >= 15
|
|
54
|
+
cvzone.putTextRect(img, f"Eye Ratio: {int(ratio)}", (30, 40), scale=1, thickness=1)
|
|
55
|
+
else:
|
|
56
|
+
closed_frames = 0
|
|
57
|
+
covered_frames += 1
|
|
58
|
+
is_face_covered = covered_frames >= 20
|
|
59
|
+
|
|
60
|
+
phone_detected = False
|
|
61
|
+
for result in phone_detector.predict(img, stream=True, verbose=False):
|
|
62
|
+
for box in result.boxes:
|
|
63
|
+
cls_id, conf = int(box.cls[0]), float(box.conf[0])
|
|
64
|
+
if class_names[cls_id] == "cell phone" and conf > 0.5:
|
|
65
|
+
phone_detected = True
|
|
66
|
+
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
|
67
|
+
cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 255), 2)
|
|
68
|
+
cvzone.putTextRect(img, f"Phone detected! {int(conf * 100)}%", (x1, max(y1 - 10, 30)), scale=1, thickness=1, colorR=(255, 0, 255))
|
|
69
|
+
|
|
70
|
+
if is_face_covered:
|
|
71
|
+
message, color, alarm, state = "DONT COVER YOUR FACE!", (0, 0, 255), alarm_facehide, "facehide"
|
|
72
|
+
elif is_sleepy:
|
|
73
|
+
message, color, alarm, state = "WAKE UP & STUDY!", (0, 0, 255), alarm_sleep, "sleep"
|
|
74
|
+
elif phone_detected:
|
|
75
|
+
message, color, alarm, state = "PUT THE PHONE AWAY!", (0, 165, 255), alarm_phone, "phone"
|
|
76
|
+
else:
|
|
77
|
+
message = None
|
|
78
|
+
|
|
79
|
+
if message:
|
|
80
|
+
cvzone.putTextRect(img, message, (50, 100), scale=2, thickness=3, colorR=color)
|
|
81
|
+
if not is_audio_busy:
|
|
82
|
+
alarm.play(0)
|
|
83
|
+
current_playing = state
|
|
84
|
+
elif is_audio_busy:
|
|
85
|
+
previous = {
|
|
86
|
+
"facehide": ("DONT COVER YOUR FACE!", (0, 0, 255)),
|
|
87
|
+
"sleep": ("WAKE UP & STUDY!", (0, 0, 255)),
|
|
88
|
+
"phone": ("PUT THE PHONE AWAY!", (0, 165, 255)),
|
|
89
|
+
}.get(current_playing)
|
|
90
|
+
if previous:
|
|
91
|
+
cvzone.putTextRect(img, previous[0], (50, 100), scale=2, thickness=3, colorR=previous[1])
|
|
92
|
+
|
|
93
|
+
cv2.imshow("Smart Study Monitor", img)
|
|
94
|
+
if cv2.waitKey(1) & 0xFF == ord("q"):
|
|
95
|
+
break
|
|
96
|
+
finally:
|
|
97
|
+
cap.release()
|
|
98
|
+
cv2.destroyAllWindows()
|
|
99
|
+
pygame.mixer.quit()
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: smart-study
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Webcam-based study distraction monitor
|
|
5
|
+
Classifier: Programming Language :: Python :: 3
|
|
6
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
7
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
8
|
+
Classifier: Topic :: Education
|
|
9
|
+
Requires-Python: <3.13,>=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: opencv-python>=4.8
|
|
12
|
+
Requires-Dist: cvzone>=1.6
|
|
13
|
+
Requires-Dist: ultralytics>=8.0
|
|
14
|
+
Requires-Dist: pygame>=2.5
|
|
15
|
+
Requires-Dist: mediapipe>=0.10
|
|
16
|
+
|
|
17
|
+
# smart-study
|
|
18
|
+
|
|
19
|
+
Webcam-based study distraction monitor. It watches for prolonged eye closure, a missing/covered face, and cell phones, then displays a warning and plays an alert.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
Python 3.11 is recommended on Windows. The computer needs a webcam and audio output.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
python -m pip install smart-study
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Use as a Python module
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from smart_study import study
|
|
33
|
+
|
|
34
|
+
study() # Uses camera 0; press Q in the video window to stop.
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Choose another camera by passing its index:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
study(camera_index=1)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Importing `smart_study` does not start the webcam. The monitor starts only when `study()` is called.
|
|
44
|
+
|
|
45
|
+
## Run from a source checkout
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
python -m pip install -e .
|
|
49
|
+
python app.py
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The distribution includes the YOLO model and alert audio assets. Installation is relatively large because the computer-vision dependencies include PyTorch through Ultralytics. Python versions below 3.13 are currently declared because MediaPipe and the selected dependency set may not be available together on newer Python versions.
|
|
53
|
+
|
|
54
|
+
## Build and upload to PyPI
|
|
55
|
+
|
|
56
|
+
Update the version in `pyproject.toml` for each release, then:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
python -m pip install --upgrade build twine
|
|
60
|
+
python -m build
|
|
61
|
+
python -m twine check dist/*
|
|
62
|
+
python -m twine upload dist/*
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
PyPI distribution name: `smart-study`
|
|
66
|
+
Python import name: `smart_study`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
smart_study/__init__.py
|
|
4
|
+
smart_study/study.py
|
|
5
|
+
smart_study.egg-info/PKG-INFO
|
|
6
|
+
smart_study.egg-info/SOURCES.txt
|
|
7
|
+
smart_study.egg-info/dependency_links.txt
|
|
8
|
+
smart_study.egg-info/requires.txt
|
|
9
|
+
smart_study.egg-info/top_level.txt
|
|
10
|
+
smart_study/assets/alarm.mp3
|
|
11
|
+
smart_study/assets/faudio.mp3
|
|
12
|
+
smart_study/assets/paudio.mp3
|
|
13
|
+
smart_study/assets/yolov8n.pt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
smart_study
|