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 Project Overview.pdf
Binary file not shown.
16 changes: 16 additions & 0 deletions ProjectProposal
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Our main idea is to create a two-player pong game with hand gestures as the main way of playing.
We will explore OpenCV and try to implement gesture recognition so it can serve as the main controller
for the game. Our minimum viable will be designing the game interface and getting the gesture recognition
to successfully detect gestures so the components of the game will all work individually. Our stretch goal would be 3D pong.

Anna's Learning Goal: I want to become more familiar with pygame and explore OpenCV's capabilities in depth.
Shyheim's Learning Goal: I want to design something that is nastolgic through pygame and learn to peer program more.

We plan on using Pygame library for one and the OpenCV library, we do not know how to use them yet but
we plan on exploring their differnt abilities. We want to use OpenCV in order to use the camera to recognize
hand gestures while using pygame to actually design the game.


We want to get the layout of the game working and have it working with the mouse and/or keyboard commands.
The biggest risk we may face is taking on too much in the amount of time we have or trying to figure out
OpenCV since neither of us have any experience with it
46 changes: 46 additions & 0 deletions ProjectProposal.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Our main idea is to create a two-player pong game with hand gestures as the main way of playing. We will explore OpenCV and try to implement gesture recognition so it can serve as the main controller for the game. Our minimum viable will be designing the game interface and getting the gesture recognition to successfully detect gestures so the components of the game will all work individually. Our stretch goal would be 3D pong. \n",
" Anna's Learning Goal: I want to become more familiar with pygame and explore OpenCV's capabilities in depth.\n",
" Shyheim's Learning Goal: I want to design something that is nastolgic through pygame and learn to peer program more.\n",
" We plan on using Pygame library for one and the OpenCV library, we do not know how to use them yet but we plan on exploring their differnt abilities. We want to use OpenCV in order to use the camera to recognize hand gestures while using pygame to actually design the game.\n",
" We want to get the layout of the game working and have it working with the mouse and/or keyboard commands.\n",
" The biggest risk we may face is taking on too much in the amount of time we have or trying to figure out OpenCV since neither of us have any experience with it."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# InteractiveProgramming
This is the base repo for the interactive programming project for Software Design, Spring 2018 at Olin College.

Install PyGame:
$ apt-get build-dep python-pygame
$ apt-get install mercurial python-dev python-numpy ffmpeg libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev
$ pip install pygame

Install OpenCV:
$ pip install opencv-python
25 changes: 25 additions & 0 deletions contours.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
# Capture frame-by-frame
ret, frame = cap.read()

imgray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 127, 255, 0)
im2, contours, hierachy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(imgray, contours, -1, (0,255,0), 3)


cv2.imshow('frame', imgray)


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


# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
79 changes: 79 additions & 0 deletions handgesture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import numpy as np
from collections import deque
import cv2


cap = cv2.VideoCapture(0)

while True:
# Capture frame-by-frame
ret, frame = cap.read()

# Convert to HSV
hsv_scale = cv2.cvtColor(frame.copy(), cv2.COLOR_BGR2HSV)


# defining range of blue
lower_threshold_blue = np.array([110,50,50])
upper_threshold_blue = np.array([130,255,255])

# creating the threshold
# binary
mask = cv2.inRange(hsv_scale, lower_threshold_blue, upper_threshold_blue)
mask = cv2.erode(mask, None, iterations=2)
mask = cv2.dilate(mask, None, iterations=2)


# blue moment tracking
contours = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2]
center = None
blue_coordinates = []

if len(contours) > 0:

c = max(contours, key=cv2.contourArea)
((x,y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
cv2.circle(frame, (int(x), int(y)), int(radius), (0,255,255), 2)
cv2.circle(frame, center, 5, (0, 0, 255), -1)


# definng range of red
lower_threshold_red = np.array([0,100,100])
upper_threshold_red = np.array([179,255,255])

mask2 = cv2.inRange(hsv_scale, lower_threshold_red, upper_threshold_red)
mask2 = cv2.erode(mask2, None, iterations=2)
mask2 = cv2.dilate(mask2, None, iterations=2)

# blue moment tracking
contours2 = cv2.findContours(mask2.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2]
center2 = None

if len(contours2) > 0:

c = max(contours2, key=cv2.contourArea)
((x,y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
center2 = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))

cv2.circle(frame, (int(x), int(y)), int(radius), (0,255,255), 2)
cv2.circle(frame, center2, 5, (0, 0, 255), -1)


# blue
res = cv2.bitwise_and(frame,frame,mask=mask)


# Display the resulting frame
cv2.imshow('frame', frame)
cv2.imshow('mask', mask)
cv2.imshow('mask2', mask2)
cv2.imshow('res', res)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Loading