Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added VolumeSimulator
Binary file not shown.
44 changes: 44 additions & 0 deletions VolumeSimulator.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- mode: python ; coding: utf-8 -*-


a = Analysis(
['volume.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='VolumeSimulator',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
app = BUNDLE(
exe,
name='VolumeSimulator.app',
icon=None,
bundle_identifier=None,
)
3 changes: 3 additions & 0 deletions YashGupta_VolumeSimulator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This simulator is used to control volume by using camera of the system.

Just take something blue in your hand and when you will move up the volume will get up and when you will move down
49 changes: 49 additions & 0 deletions volume.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import cv2
import numpy as np
import os


lower_color = np.array([94, 80, 2])
upper_color = np.array([126, 255, 255])

cap = cv2.VideoCapture(0)
initial_y = None

while True:
ret, frame = cap.read()
if not ret:
break

frame = cv2.flip(frame, 1)
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

mask = cv2.inRange(hsv, lower_color, upper_color)
mask = cv2.erode(mask, None, iterations=2)
mask = cv2.dilate(mask, None, iterations=2)

contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

if contours:
c = max(contours, key=cv2.contourArea)
(x, y), radius = cv2.minEnclosingCircle(c)

if radius > 5:
cv2.circle(frame, (int(x), int(y)), int(radius), (255, 0, 0), 2)

if initial_y is None:
initial_y = y

if y < initial_y - 40:
os.system("osascript -e 'set volume output volume ((output volume of (get volume settings)) + 5)'")
initial_y = y
elif y > initial_y + 40:
os.system("osascript -e 'set volume output volume ((output volume of (get volume settings)) - 5)'")
initial_y = y

cv2.imshow("Mac Volume Control (Blue Marker)", frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()