Skip to content

Commit

Permalink
modify README, add icons
Browse files Browse the repository at this point in the history
  • Loading branch information
kzaleskaa committed Jan 18, 2022
1 parent d75313a commit 1f38d1a
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 45 deletions.
2 changes: 2 additions & 0 deletions GUI/Authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from configparser import ConfigParser

from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QDialog

from Spotify import SpotifyAPI
Expand All @@ -14,6 +15,7 @@ def __init__(self):
super().__init__()
self.setupUi(self)
self._connect_buttons()
self.setWindowIcon(QIcon('pyui/icons/authorization.png'))

def _connect_buttons(self) -> None:
self.submit_btn.clicked.connect(self._on_login_button_clicked)
Expand Down
9 changes: 6 additions & 3 deletions GUI/DetectionWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WCY19IJ1S1

from PyQt5.QtCore import pyqtSlot, Qt
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtGui import QImage, QPixmap, QIcon
from PyQt5.QtWidgets import QDialog

from GestureRecognitionThread import GestureRecognitionThread
Expand All @@ -18,6 +18,7 @@ def __init__(self):
self.token = ""
self._connect_buttons()
self.detection = GestureRecognitionThread()
self.setWindowIcon(QIcon('pyui/icons/hand-recognition.png'))

def _connect_buttons(self) -> None:
"""Function connects button with its action."""
Expand Down Expand Up @@ -50,7 +51,8 @@ def update_confidence(self, confidence: str) -> None:
Args:
confidence (str): confidence of detected gesture
"""
self.detection_confidence.setText(f"Confidence: {confidence}%")
self.detection_confidence.setText(confidence)
self.detection_confidence.setAlignment(Qt.AlignCenter)

@pyqtSlot(str)
def update_gesture_name(self, gesture_name: str) -> None:
Expand All @@ -59,7 +61,8 @@ def update_gesture_name(self, gesture_name: str) -> None:
Args:
gesture_name (str): name of detected gesture
"""
self.detected_gesture_name.setText(f"Gesture name: {gesture_name}")
self.detected_gesture_name.setText(gesture_name)
self.detected_gesture_name.setAlignment(Qt.AlignCenter)

@pyqtSlot(QImage)
def update_image(self, image: QImage) -> None:
Expand Down
2 changes: 2 additions & 0 deletions GUI/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from configparser import ConfigParser
from typing import Any

from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMainWindow

from GUI.Authorization import AuthorizationWindow
Expand All @@ -24,6 +25,7 @@ def __init__(self):
self.login = None
self.detection_window = DetectionWindow()
self.auth_window = AuthorizationWindow()
self.setWindowIcon(QIcon('pyui/icons/sound-waves.png'))

def _connect_buttons(self) -> None:
"""Function connects button with its action."""
Expand Down
3 changes: 1 addition & 2 deletions GestureRecognitionThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ def run(self) -> None:
gesture = ACTIONS[max_prediction_index]
self.change_gesture_name.emit(gesture)
spotify.gesture_action(gesture)
self.change_confidence.emit(str(round(confidence*100, 2)))
self.change_confidence.emit(str(f"{round(confidence*100, 2)}%"))
landmarks_from_frame = []

cv2.waitKey(10)

self.cap.release()
cv2.destroyAllWindows()
self.clear_labels.emit()

45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,46 @@
<img src="https://user-images.githubusercontent.com/62251989/149663561-90e99712-58a9-40c6-9822-69a7092d582b.png" alt="Spotify Gesture Controller logo"/>
</div>

## Credits
- Heart photo created by nakaridore - [Freepik](www.freepik.com)


## 📝 Description
Spotify Gesture Controller is a project realised during "Programming in functional languages" course. The main goal was create the app, which can:

- play/pause current track
- skip to next/previous track
- add/remove song to saved
- volume up/down music

## 🏃‍ How to install and run it?
**Remember: to use this app you need to have premium version of Spotify.**

1. Download repository
```
git clone https://github.com/kzaleskaa/hand-gesture-recognition.git
cd hand-gesture-recognition
```
2. Create a new project at [Spotify Dashboard](https://developer.spotify.com/dashboard/) and edit settings - add ```http://localhost:9000``` in Redirect URLs.
3. Create your conda environment and install all requirements
```
$ conda create --name <env> --file <file with requirements>
```
5. Start app
```
python main.py
```
6. Make authorization (use client id and client secret from your Spotify Dashboard)
7. Open your spotify app, start play music and use this app to control it

## ✋ Gestures

![ezgif com-gif-maker (9)](https://user-images.githubusercontent.com/62251989/150003931-1bb5ec49-8f3a-4c2e-8ed4-a12f89ddafe2.gif)


## 🎶 Spotify API
>Based on simple REST principles, the Spotify Web API endpoints return JSON metadata about music artists, albums, and tracks, directly from the Spotify Data Catalogue.
If no action on Spotify is made, please open your app and start play music manually.

## 🖊 Credits
- Heart photo created by nakaridore - [Freepik](www.freepik.com)
- Icons - [Flaticon](Flaticon.com)
90 changes: 69 additions & 21 deletions pyui/DetectionWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,87 @@ def setupUi(self, DetectionWindow):
"color: #121212;\n"
"background-color: #1db954;\n"
"border: 2px solid #121212;\n"
"}\n"
"\n"
"QHBoxLayout {\n"
"border: 2px solid green;\n"
"}")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(DetectionWindow)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setContentsMargins(10, 25, 25, 25)
self.horizontalLayout.setObjectName("horizontalLayout")
self.horizontalLayout_9 = QtWidgets.QHBoxLayout()
self.horizontalLayout_9.setObjectName("horizontalLayout_9")
self.information = QtWidgets.QHBoxLayout()
self.information.setObjectName("information")
self.verticalLayout_4 = QtWidgets.QVBoxLayout()
self.verticalLayout_4.setContentsMargins(10, 0, 10, 20)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.detected_gesture_name = QtWidgets.QLabel(DetectionWindow)
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_4.addItem(spacerItem)
self.label_3 = QtWidgets.QLabel(DetectionWindow)
self.label_3.setMinimumSize(QtCore.QSize(0, 50))
self.label_3.setStyleSheet("color: white;\n"
"border: 2px solid #535353;\n"
"border-radius: 14px;\n"
"margin-bottom: 10px;\n"
"padding: 10px;\n"
"")
self.label_3.setObjectName("label_3")
self.verticalLayout_4.addWidget(self.label_3)
self.verticalWidget = QtWidgets.QWidget(DetectionWindow)
self.verticalWidget.setStyleSheet("border: 2px solid #535353;\n"
"border-radius: 14px;")
self.verticalWidget.setObjectName("verticalWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalWidget)
self.verticalLayout.setContentsMargins(-1, -1, -1, 20)
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(self.verticalWidget)
self.label.setStyleSheet("color: white;\n"
"border: 2px solid #535353;\n"
"border-radius: 14px;\n"
"padding: 10px;\n"
"margin: 10px;\n"
"")
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.detected_gesture_name = QtWidgets.QLabel(self.verticalWidget)
self.detected_gesture_name.setStyleSheet("color: #1db954;\n"
"border: none;")
self.detected_gesture_name.setObjectName("detected_gesture_name")
self.verticalLayout_4.addWidget(self.detected_gesture_name)
self.detection_confidence = QtWidgets.QLabel(DetectionWindow)
self.verticalLayout.addWidget(self.detected_gesture_name)
self.label_2 = QtWidgets.QLabel(self.verticalWidget)
self.label_2.setStyleSheet("color: white;\n"
"border: 2px solid #535353;\n"
"border-radius: 14px;\n"
"padding: 10px;\n"
"margin: 10px;\n"
"")
self.label_2.setObjectName("label_2")
self.verticalLayout.addWidget(self.label_2)
self.detection_confidence = QtWidgets.QLabel(self.verticalWidget)
self.detection_confidence.setStyleSheet("color: #1db954;\n"
"border: none;")
self.detection_confidence.setObjectName("detection_confidence")
self.verticalLayout_4.addWidget(self.detection_confidence)
self.horizontalLayout_9.addLayout(self.verticalLayout_4)
self.horizontalLayout.addLayout(self.horizontalLayout_9)
self.verticalLayout.addWidget(self.detection_confidence)
self.verticalLayout_4.addWidget(self.verticalWidget)
spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_4.addItem(spacerItem1)
self.information.addLayout(self.verticalLayout_4)
self.horizontalLayout.addLayout(self.information)
self.horizontalLayout_8 = QtWidgets.QHBoxLayout()
self.horizontalLayout_8.setObjectName("horizontalLayout_8")
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.detection_camera = QtWidgets.QLabel(DetectionWindow)
self.detection_camera.setText("")
self.detection_camera.setMinimumSize(QtCore.QSize(600, 400))
self.detection_camera.setStyleSheet("QLabel {\n"
"border-radius: 14px;\n"
"border: 2px solid #535353;\n"
"}")
self.detection_camera.setObjectName("detection_camera")
self.verticalLayout_3.addWidget(self.detection_camera)
self.horizontalLayout_10 = QtWidgets.QHBoxLayout()
self.horizontalLayout_10.setContentsMargins(-1, 20, -1, 20)
self.horizontalLayout_10.setObjectName("horizontalLayout_10")
self.pushButton_2 = QtWidgets.QPushButton(DetectionWindow)
self.pushButton_2.setMinimumSize(QtCore.QSize(150, 56))
Expand All @@ -84,16 +138,10 @@ def setupUi(self, DetectionWindow):
def retranslateUi(self, DetectionWindow):
_translate = QtCore.QCoreApplication.translate
DetectionWindow.setWindowTitle(_translate("DetectionWindow", "Detection"))
self.detected_gesture_name.setText(_translate("DetectionWindow", "<html><head/><body><p><br/></p></body></html>"))
self.detection_confidence.setText(_translate("DetectionWindow", "<html><head/><body><p><br/></p></body></html>"))
self.label_3.setText(_translate("DetectionWindow", "<html><head/><body><p align=\"center\"><span style=\" font-size:14pt;\">INFORMATION</span></p></body></html>"))
self.label.setText(_translate("DetectionWindow", "<html><head/><body><p align=\"center\"><span style=\" font-size:14pt;\">DETECTED GESTURE</span></p></body></html>"))
self.detected_gesture_name.setText(_translate("DetectionWindow", "<html><head/><body><p align=\"center\"><br/></p></body></html>"))
self.label_2.setText(_translate("DetectionWindow", "<html><head/><body><p align=\"center\"><span style=\" font-size:14pt;\">CONFIDENCE</span></p></body></html>"))
self.detection_confidence.setText(_translate("DetectionWindow", "<html><head/><body><p align=\"center\"><br/></p></body></html>"))
self.detection_camera.setText(_translate("DetectionWindow", "<html><head/><body><p align=\"center\"><span style=\" font-size:14pt;\">CLICK START, OPEN SPOTIFY AND START PLAY MUSIC </span></p></body></html>"))
self.pushButton_2.setText(_translate("DetectionWindow", "START"))


if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
DetectionWindow = QtWidgets.QDialog()
ui = Ui_DetectionWindow()
ui.setupUi(DetectionWindow)
DetectionWindow.show()
sys.exit(app.exec_())
Binary file added pyui/icons/authorization.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pyui/icons/hand-recognition.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pyui/icons/sound-waves.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1f38d1a

Please sign in to comment.