Skip to content

Commit c386c30

Browse files
authored
Merge pull request larymak#163 from Aditya-Tripuraneni/main
Added Finance Tracker to /PythonApps Added Virtual Hand Painter to /GAMES
2 parents 792e5b3 + 53c9303 commit c386c30

File tree

8 files changed

+1960
-0
lines changed

8 files changed

+1960
-0
lines changed

GAMES/VirtualHandPainter/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# HandPainter
2+
![Virtual_Hand_Painter](https://user-images.githubusercontent.com/59937191/170613993-6a08904e-e1cc-4032-9f52-6b9b5e4e662f.png)
3+
4+
## Installation
5+
There are a few things to install when using this program!
6+
````bash
7+
pip install opencv-python
8+
pip install pygame
9+
pip install pyautogui
10+
pip install mediapipe
11+
````
12+
13+
## Imports
14+
````Python
15+
import cv2 as cv
16+
import mediapipe as mp
17+
import pygame
18+
import math
19+
import pyautogui
20+
import os
21+
````
22+
23+
## What is this?
24+
Use your thumb and index finger to draw onto your computer screen. By bringing your index and thumb finger together, it will allow you to draw onto a whiteboard, displayed on screen. Users can take screen shots of their work by moving their index finger together beside their middle finger tip. Within a certain distance screen shots will be taken aswell as drawing.
25+
26+
27+
![visual](https://user-images.githubusercontent.com/59937191/170798233-c10752d2-6df0-4349-a9b5-fd96902c3489.png)
28+
29+
30+
## Inspiration
31+
This project was made integrating computer vision and pygame!
32+
I first got this idea, after I worked on a similar project called "Catch me if you can". The goal of catch me if you can was to mov a 2d square around your screen, by controlling it through your hand. This was a very interesting project I developed with my cousin, that eventually lead me to take on this new one. After learning open CV, I decided to create an application, where users could draw onto their computer screen, if they didn't have a mouse. This would finally allow users to have precise drawings all without having to spend money on a stylus or mouse!
33+
34+
## What I learned
35+
Through this project I learned more details about Pygame, and open CV. Aswell as enhancing my experience with Python, I was able to learn how to use generators effectively. This project taught me many applications of mathematical equations learned in school, such as the distance formula. Lastly, I was able to learn how to create screen shots through Python, through the windows machine. This project allowed me to become more comfortable using the "OS" module in Python, as I was able to experiment through grabbing the users directory, and allowing images to be saved on that pathway, if they want to take a screen shot.

GAMES/VirtualHandPainter/main.py

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import time
2+
3+
start = time.time()
4+
from cv2 import VideoCapture, flip, COLOR_BGR2RGB, cvtColor, circle, FILLED, destroyAllWindows, imshow, CAP_PROP_FRAME_WIDTH, CAP_PROP_FRAME_HEIGHT
5+
print("Importing cv stuff")
6+
import mediapipe.python.solutions.drawing_utils as mp_drawing
7+
print("Importing hand module stuff")
8+
9+
import mediapipe.python.solutions.hands as mp_hands
10+
print("Importing more hand module stuff")
11+
12+
import pygame
13+
print("Importing pygame")
14+
15+
from math import sqrt
16+
print("Importing math")
17+
18+
import pyautogui
19+
import os
20+
print("Importing other stuff")
21+
22+
23+
end = time.time()
24+
print(end - start)
25+
26+
# 0.75s initial
27+
# 0.73s final
28+
# 3.5 x faster
29+
30+
31+
# 640, 480
32+
WIDTH, HEIGHT = 1000, 1000
33+
34+
# COLOURS
35+
RED = (255, 0, 0)
36+
VIOLET = (148, 0, 211)
37+
INDIGO = (75, 0, 130)
38+
BLUE = (0, 0, 255)
39+
GREEN = (0, 255, 0)
40+
YELLOW = (255, 255, 0)
41+
ORANGE = (255, 127, 0)
42+
WHITE = (255, 255, 255)
43+
44+
color = RED
45+
rainbow = [VIOLET, INDIGO, BLUE, GREEN, YELLOW, ORANGE, RED]
46+
47+
desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
48+
ss_count = 1
49+
50+
run = True
51+
52+
pygame.init()
53+
54+
window = pygame.display.set_mode((WIDTH, HEIGHT))
55+
pygame.display.set_caption("Drawing Board")
56+
57+
hands = mp_hands.Hands(max_num_hands=1, min_tracking_confidence=0.9)
58+
camera = VideoCapture(0)
59+
60+
camera.set(CAP_PROP_FRAME_WIDTH, WIDTH)
61+
camera.set(CAP_PROP_FRAME_HEIGHT, HEIGHT)
62+
63+
64+
65+
66+
def generate_rainbow(rainbow):
67+
it = iter(rainbow)
68+
while True:
69+
yield next(it)
70+
try:
71+
yield next(it)
72+
except StopIteration:
73+
it = iter(rainbow)
74+
75+
76+
def convert_to_pixel_coordinates():
77+
normalized_landmark = handlms.landmark[id]
78+
pixel_coordinate = mp_drawing._normalized_to_pixel_coordinates(normalized_landmark.x,
79+
normalized_landmark.y, width, height)
80+
return pixel_coordinate
81+
82+
83+
gen_rainbow = generate_rainbow(rainbow)
84+
window.fill(WHITE)
85+
86+
while run:
87+
ret, frame = camera.read()
88+
frame = flip(frame, 1)
89+
imgRGB = cvtColor(frame, COLOR_BGR2RGB)
90+
results = hands.process(imgRGB)
91+
hand = results.multi_hand_landmarks
92+
93+
for event in pygame.event.get():
94+
if event.type == pygame.QUIT:
95+
run = False
96+
keys = pygame.key.get_pressed()
97+
if keys[pygame.K_q]:
98+
run = False
99+
if keys[pygame.K_c]:
100+
window.fill(WHITE)
101+
if keys[pygame.K_r]:
102+
color = RED
103+
if keys[pygame.K_b]:
104+
color = BLUE
105+
if keys[pygame.K_y]:
106+
color = YELLOW
107+
if keys[pygame.K_g]:
108+
color = GREEN
109+
if keys[pygame.K_o]:
110+
color = ORANGE
111+
if keys[pygame.K_l]:
112+
color = next(gen_rainbow)
113+
114+
if hand:
115+
for handlms in hand:
116+
for id, lm in enumerate(handlms.landmark):
117+
height, width, c = frame.shape
118+
cx, cy = int(lm.x * width), int(lm.y * height)
119+
120+
if id == 4:
121+
circle(frame, (cx, cy), 15, (255, 0, 0), FILLED)
122+
thumb_coordinates = convert_to_pixel_coordinates()
123+
124+
if id == 8:
125+
circle(frame, (cx, cy), 15, (255, 0, 255), FILLED)
126+
index_coordinates = convert_to_pixel_coordinates()
127+
128+
try:
129+
x_distance = index_coordinates[0] - thumb_coordinates[0]
130+
y_distance = index_coordinates[1] - thumb_coordinates[1]
131+
distance = sqrt((x_distance ** 2) + (y_distance ** 2))
132+
133+
# try:
134+
if 0 <= distance <= 20:
135+
pygame.draw.circle(window, color,
136+
(index_coordinates[0], index_coordinates[1]), 5)
137+
except TypeError:
138+
print("ERROR")
139+
140+
if id == 12:
141+
circle(frame, (cx, cy), 15, (255, 255, 0), FILLED)
142+
middle_tip_coordinates = convert_to_pixel_coordinates()
143+
144+
try:
145+
146+
x_middle_distance = index_coordinates[0] - middle_tip_coordinates[0]
147+
y_middle_distance = index_coordinates[1] - middle_tip_coordinates[1]
148+
distance_middle_to_index = distance = sqrt(
149+
(x_middle_distance ** 2) + (y_middle_distance ** 2))
150+
151+
if 0 <= distance_middle_to_index <= 20:
152+
print(desktop)
153+
image = pyautogui.screenshot()
154+
image.save(desktop + f"/screenshot{ss_count}.png")
155+
ss_count += 1
156+
157+
except TypeError:
158+
print("error")
159+
160+
mp_drawing.draw_landmarks(frame, handlms, mp_hands.HAND_CONNECTIONS)
161+
162+
pygame.display.update()
163+
imshow("Window", frame)
164+
165+
camera.release()
166+
destroyAllWindows()
167+
pygame.quit()

PYTHON APPS/FinanceTracker/Finance.db

40 KB
Binary file not shown.

PYTHON APPS/FinanceTracker/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# FinanceApp
2+
![Finance_Tracker](https://user-images.githubusercontent.com/59937191/170799233-576fdaf2-6603-4fd1-8966-4b18cb556368.png)
3+
4+
5+
## Installations
6+
````
7+
pip install PyQt5
8+
pip install matplotlib
9+
pip install db-sqlite3
10+
````
11+
12+
## Imports for main.py
13+
````
14+
import sys
15+
from PyQt5 import QtWidgets
16+
from PyQt5.QtWidgets import QDialog, QApplication
17+
from PyQt5.uic import loadUi
18+
import financeDataBase
19+
````
20+
21+
## Imports for financeDataBase.py
22+
````
23+
import sqlite3
24+
from matplotlib import pyplot as plt
25+
````
26+
27+
### Note
28+
financeDataBase is the other python file containing all necessary methods to perform SQL actions
29+
30+
## What is this?
31+
This is a simple finance tracker that allows users to track and mange their expenses on various categories. This app allows users to monitor their finances, add expenses, delete expenses, view their total expesnes, view various graphs on how their money is being spent and more! Some intersting features that were recently added are, users can change the background of their app based on their liking, or they can chose from 3 default gradients.
32+
33+
![main](https://user-images.githubusercontent.com/59937191/170799097-222e8b83-f73c-4e41-b2bd-a520af125cb4.png)
34+
![main2](https://user-images.githubusercontent.com/59937191/170799105-27d18519-69a4-4abb-ac4c-18d4446b27ce.png)
35+
![settings](https://user-images.githubusercontent.com/59937191/170799166-4a884a29-2587-4d24-a704-1e04c4f9cbb9.png)
36+
![other](https://user-images.githubusercontent.com/59937191/170799111-04ff05df-2af9-4df1-aec7-67b675b66bbe.png)
37+
![piechart](https://user-images.githubusercontent.com/59937191/170799112-7f760048-b9a3-417e-8268-8b46f3cd6f91.png)
38+
39+
## Inspiration
40+
After taking part in my first hackathon when I was 15, and creatign a pet expense tracker, I decided to take my SQL knowedge and GUI capabilities to the next level. I wanted to create an app that would help my family and other peopel monitor their finances. This is app focuses on the simplicity on just keeping track of how you spend your money.
41+
42+
## What I learned
43+
- Pyqt5
44+
- Matplotlib
45+
- More from SQL
46+
This project allowed me to become more confident in my Object Oriented programming skills, and allowed me to work with new technologies I have previous not worked with before such as a powerful GUI builder "Pyqt5". I was able to learn how to efficiently use Matplot lib to implement graphs and a pie chart. Lastly, I became more familar with SQL commands in python and using better practices to retrieve data.
47+
48+
49+
## Latest Updates:
50+
### July 9th 2022
51+
- Added some doccumention for code to make it easier to read
52+
- Added ability to tell users when they hit goal or over budget once expense entered
53+

PYTHON APPS/FinanceTracker/confirm.ui

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Dialog</class>
4+
<widget class="QDialog" name="Dialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>1190</width>
10+
<height>766</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Dialog</string>
15+
</property>
16+
<property name="styleSheet">
17+
<string notr="true">QDialog#Dialog{
18+
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(67, 206, 162, 1), stop:1 rgba(24, 90, 157, 1));
19+
}</string>
20+
</property>
21+
<widget class="QPushButton" name="proceedButton">
22+
<property name="geometry">
23+
<rect>
24+
<x>350</x>
25+
<y>250</y>
26+
<width>140</width>
27+
<height>50</height>
28+
</rect>
29+
</property>
30+
<property name="font">
31+
<font>
32+
<pointsize>14</pointsize>
33+
<weight>75</weight>
34+
<bold>true</bold>
35+
</font>
36+
</property>
37+
<property name="styleSheet">
38+
<string notr="true">QPushButton{
39+
background-color: rgb(222, 255, 201); font-size: 14pt;
40+
border-radius: 10px;
41+
}
42+
43+
QPushButton:hover{
44+
background-color: rgb(85, 255, 255);
45+
}</string>
46+
</property>
47+
<property name="text">
48+
<string>Yes Proceed</string>
49+
</property>
50+
</widget>
51+
<widget class="QPushButton" name="cancelButton">
52+
<property name="geometry">
53+
<rect>
54+
<x>580</x>
55+
<y>250</y>
56+
<width>170</width>
57+
<height>50</height>
58+
</rect>
59+
</property>
60+
<property name="font">
61+
<font>
62+
<pointsize>14</pointsize>
63+
<weight>75</weight>
64+
<bold>true</bold>
65+
</font>
66+
</property>
67+
<property name="styleSheet">
68+
<string notr="true">QPushButton{
69+
background-color: rgb(222, 255, 201); font-size: 14pt;
70+
border-radius: 10px;
71+
}
72+
73+
QPushButton:hover{
74+
background-color: rgb(255, 83, 83);
75+
}</string>
76+
</property>
77+
<property name="text">
78+
<string>Cancel/Go back</string>
79+
</property>
80+
</widget>
81+
<widget class="QLabel" name="warning">
82+
<property name="geometry">
83+
<rect>
84+
<x>270</x>
85+
<y>170</y>
86+
<width>801</width>
87+
<height>61</height>
88+
</rect>
89+
</property>
90+
<property name="font">
91+
<font>
92+
<pointsize>13</pointsize>
93+
<weight>75</weight>
94+
<bold>true</bold>
95+
</font>
96+
</property>
97+
<property name="text">
98+
<string>Are you sure you want to delete eveyrthing? This action CANNOT be undone!</string>
99+
</property>
100+
</widget>
101+
</widget>
102+
<resources/>
103+
<connections/>
104+
</ui>

0 commit comments

Comments
 (0)