diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..1bbb26a Binary files /dev/null and b/.DS_Store differ diff --git a/VolumeSimulator b/VolumeSimulator new file mode 100755 index 0000000..5385f1d Binary files /dev/null and b/VolumeSimulator differ diff --git a/VolumeSimulator.spec b/VolumeSimulator.spec new file mode 100644 index 0000000..e231b0e --- /dev/null +++ b/VolumeSimulator.spec @@ -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, +) diff --git a/YashGupta_VolumeSimulator.md b/YashGupta_VolumeSimulator.md new file mode 100644 index 0000000..d29ef22 --- /dev/null +++ b/YashGupta_VolumeSimulator.md @@ -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 \ No newline at end of file diff --git a/volume.py b/volume.py new file mode 100644 index 0000000..76d9f32 --- /dev/null +++ b/volume.py @@ -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()