Skip to content
This repository was archived by the owner on Jun 22, 2020. It is now read-only.
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# IDEs and editors
.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
.vscode/
77 changes: 32 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,46 @@
# HackIIITV 19 Submission
<p align="center"><img src="logo.jpg" align="center" width="175"></p>
<h1 align="center">Actum</h1>
<p align="center">
<img width="155" height="55" src="https://forthebadge.com/images/badges/built-with-love.svg">
</p>
<hr>
<p align="center"><b>Because Action speaks louder than Words</b>
</p>

This repository is archive of hacks created during HackIIITV 2019.
### Motive

## Requirements
For actions to speak louder than words Actum has been designed to enhance the communication between normal and specially abled (deaf and dumb).

- GitHub account
- Install [git](https://git-scm.com/) for your repsective OS.
- Make sure you are part of IIITV organisation on GitHub, else join [here](http://getmein.glitch.me/)
### Why Actum?

## Few pointers
Actum is the complete solution to ease communication between normal and especially abled person viz. deaf and dumb. Using it anyone can easily recognize gestures produced by the deaf and dumb. Now speech will no more be a restriction to interact with someone. Using it the deaf and dumb can also easily interact with someone who don’t recognize their action, so that speech is no longer a restriction for them to express their feelings. Actum also has a chat app which the deaf and dumb can use to interact with others just by their gestures.

- You can make at max one commit per hour.
- Don't close your PR.
- No commits after Hackathon ends will be entertained.
- It is recommended to make one commit/hour to keep your hack backed up.
- Make sure your whole project is inside the folder of your team.
- If you have time left, make sure you make a README.md 😉(it will help others to understand your code)
### Technologies

## How to submit?
- Django
- Image Processing
- Image classfication using classifier

One member from each team have to follow this instructions:
Follow the instructions in order:
## Modus Operandi

1. Fork this repository.
Actum has a ML script running in the Django backend which will detect the gestures performed by any deaf or dumb which can be then mapped to a particular action which will be unique to that gesture.Then this gesture is passed by the backend to frontend where the text is displayed.

2. Clone your fork, using
`git clone https://github.com/<your-username>/hackiiitv19-submissions.git`

3. Change Directory to `hackiiitv19-submissions`, using
`cd hackiiitv19-submissions`
<p align="center"><img src="fact.jpg" align="center" width="375"></p>

4. Set remote to original repository using
`git remote add ups https://github.com/iiitv/hackiiitv19-submissions.git`
### Contributors

5. Create a branch named `team#x`, where x is your team number, using
`git checkout -b team#x`
<details>
<summary>Team Vision</summary>
<ul>
<li><a href="https://github.com/amanraj1608">Aman Raj</a></li>
<li><a href="https://github.com/dixitaniket">Aniket Dixit</a></li>
<li><a href="https://github.com/fuzious">Arpit Srivastava</a></li>
<li><a href="https://github.com/">Jatin Singh Chauhan</a></li>
<li><a href="https://github.com/">Souhard Swami</a></li>
</ul>
</details>

6. Add a folder with name `team#x - {Chosen_Theme}` in root directory. Make sure your whole hack is in folder `team#x - {Chosen_Theme}`.
### References

7. Now add this folder to your staging area, using
`git add "team#x - {Chosen_Theme}"`

8. Now commit the changes using,
`git commit -m "Add team#x"`

9. Push the changes using,
`git push`

10. Open a pull request: As soon as the changes will be pushed, GUI of repository's main page will show a yellow banner saying you too open a Pull request, just click on it and you are done.

For making changes to PR, just keep on repeating Step 6-9.

## Rules

- Keep your content as original as possible.
- It is allowed to use available softwares/packages as a module, but they can't be your project.

Happy Hacking! 🖖
- [Model Retraining and Transfer Learning](https://www.tensorflow.org/tutorials/image_retraining)
Binary file added fact.jpg
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 logo.jpg
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 team#29 - Smart_Communication/bhai_yeh_model.h5
Binary file not shown.
Binary file added team#29 - Smart_Communication/db.sqlite3
Binary file not shown.
69 changes: 69 additions & 0 deletions team#29 - Smart_Communication/display_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import cv2
import tensorflow as tf
from tensorflow.keras.preprocessing.image import img_to_array
import pandas as pd
import numpy as np
#
agest_cascade=cv2.CascadeClassifier("aGest.xml")
fist_cascade=cv2.CascadeClassifier("palm_v4.xml")
# v_cascade=cv2.CascadeClassifier("cascade.xml")
# model=tf.keras.models.load_model("final_model.h5")
# fist=cv2.CascadeClassifier("fist.xml")
# palm=cv2.CascadeClassifier("palm.xml")
# lpalm=cv2.CascadeClassifier("right.xml")
plam_cascade=cv2.CascadeClassifier("right.xml")
# model=tf.keras.models.load"_model("sign_lang_")
cap=cv2.VideoCapture(0)
while(True):
ret,frame=cap.read()
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

agest=agest_cascade.detectMultiScale(gray,scaleFactor=1.5,minNeighbors=5)
for (x,y,w,h) in agest:

# print(x,y,w,h)
roi_gray=gray[y:y+h,x:x+w]
f=frame[y:y+h,x:x+w]
# print(np.argmax(model.predict(cv2.resize(f,(64,64),interpolation=cv2.INTER_AREA).reshape(1,64,64,3))))

# img_item="image.png"
# cv2.imwrite(img_item,roi_gray)
color=(255,0,0)
stroke=2
en_x=x+w
en_y=y+h
cv2.rectangle(frame,(x,y),(en_x,en_y),color,stroke)

fist = fist_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)
for (x, y, w, h) in fist:
# print(x,y,w,h)
roi_gray = gray[y:y + h, x:x + w]
f = frame[y:y + h, x:x + w]
# print(np.argmax(model.predict(cv2.resize(f,(64,64),interpolation=cv2.INTER_AREA).reshape(1,64,64,3))))

# img_item="image.png"
# cv2.imwrite(img_item,roi_gray)
color = (255, 0, 0)
stroke = 2
en_x = x + w
en_y = y + h
cv2.rectangle(frame, (x, y), (en_x, en_y), color, stroke)
r=plam_cascade.detectMultiScale(gray,scaleFactor=1.5,minNeighbors=5)
for (x,y,w,h) in r:
roi_gray = gray[y:y + h, x:x + w]
f = frame[y:y + h, x:x + w]
# print(np.argmax(model.predict(cv2.resize(f,(64,64),interpolation=cv2.INTER_AREA).reshape(1,64,64,3))))

# img_item="image.png"
# cv2.imwrite(img_item,roi_gray)
color = (255, 0, 0)
stroke = 2
en_x = x + w
en_y = y + h
cv2.rectangle(frame, (x, y), (en_x, en_y), color, stroke)

cv2.imshow('frame',frame)
if(cv2.waitKey(20)&0xFF==ord("q")):
break
cap.release()
cap.destroyAllWindows()
72 changes: 72 additions & 0 deletions team#29 - Smart_Communication/experimental/Hand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import cv2
import math


class Hand:

def __init__(self, binary, masked, raw, frame):
self.masked = masked
self.binary = binary
self._raw = raw
self.frame = frame
self.contours = []
self.outline = self.draw_outline()
self.fingertips = self.extract_fingertips()

def draw_outline(self, min_area=10000, color=(0, 255, 0), thickness=2):
contours, _ = cv2.findContours(
self.binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
palm_area = 0
flag = None
cnt = None
for (i, c) in enumerate(contours):
area = cv2.contourArea(c)
if area > palm_area:
palm_area = area
flag = i
if flag is not None and palm_area > min_area:
cnt = contours[flag]
self.contours = cnt
cpy = self.frame.copy()
cv2.drawContours(cpy, [cnt], 0, color, thickness)
return cpy
else:
return self.frame

def extract_fingertips(self, filter_value=50):
cnt = self.contours
if len(cnt) == 0:
return cnt
points = []
hull = cv2.convexHull(cnt, returnPoints=False)
defects = cv2.convexityDefects(cnt, hull)
for i in range(defects.shape[0]):
s, e, f, d = defects[i, 0]
end = tuple(cnt[e][0])
points.append(end)
filtered = self.filter_points(points, filter_value)

filtered.sort(key=lambda point: point[1])
return [pt for idx, pt in zip(range(5), filtered)]

def filter_points(self, points, filter_value):
for i in range(len(points)):
for j in range(i + 1, len(points)):
if points[i] and points[j] and self.dist(points[i], points[j]) < filter_value:
points[j] = None
filtered = []
for point in points:
if point is not None:
filtered.append(point)
return filtered

def get_center_of_mass(self):
if len(self.contours) == 0:
return None
M = cv2.moments(self.contours)
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
return (cX, cY)

def dist(self, a, b):
return math.sqrt((a[0] - b[0])**2 + (b[1] - a[1])**2)
48 changes: 48 additions & 0 deletions team#29 - Smart_Communication/experimental/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# handy
An easy to use wrapper for hand recognition, made using OpenCV 4.

![Alt Text](sample.gif)

```sh
import handy
import cv2

cap = cv2.VideoCapture(0)
hist = handy.capture_histogram(source=0)

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

# detect the hand
hand = handy.detect_hand(frame, hist)

# plot the fingertips
for fingertip in hand.fingertips:
cv2.circle(hand.outline, fingertip, 5, (0, 0, 255), -1)

cv2.imshow("Handy", hand.outline)

k = cv2.waitKey(5)
if k == ord('q'):
break
```

## Get started
1. Clone or download the repo, and then,
```sh
$ cd handy-master
$ pip install -r requirements.txt
$ python test.py
```
2. When the program starts, it'll pop open a web cam feed and you have to place a part of your hand in the rectangle shown and press the key 'a' to calibrate the system with your skin color and the detection process will start.

## Note
Please use OpenCV version 4 to use Handy.

## Documentation
I didn't want to make a full, proper documentation. 😅
However, `test.py` contains all the functions and their usage.

## Purpose
The purpose of this project was to detect hands in images/videos without using Machine/Deep Learning. So, this has been done using only Image Processing, and it is much faster than ML/DL solutions on a normal system. However, it is not as as accurate (backgrounds with similar color as that of skin can fool the detector).
Also note that, this isn't really a "Hand detector". It is just an Object Detector, using color. You can play around and modify the code to detect other objects as well, pretty easily.
84 changes: 84 additions & 0 deletions team#29 - Smart_Communication/experimental/handy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import cv2
import math
from Hand import Hand


def detect_face(frame, block=False, colour=(0, 0, 0)):
fill = [1, -1][block]
face_cascade = cv2.CascadeClassifier(
cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.1, 5)
area = 0
X = Y = W = H = 0
for (x, y, w, h) in faces:
if w * h > area:
area = w * h
X, Y, W, H = x, y, w, h
cv2.rectangle(frame, (X, Y), (X + W, Y + H), colour, fill)


def capture_histogram(source=0):
cap = cv2.VideoCapture(source)
while True:
_, frame = cap.read()
frame = cv2.flip(frame, 1)
frame = cv2.resize(frame, (1000, 600))

font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(frame, "Place region of the hand inside box and press `A`",
(5, 50), font, 0.7, (255, 255, 255), 2, cv2.LINE_AA)
cv2.rectangle(frame, (500, 100), (580, 180), (105, 105, 105), 2)
box = frame[105:175, 505:575]

cv2.imshow("Capture Histogram", frame)

key = cv2.waitKey(10)
if key == 97:
object_color = box
cv2.destroyAllWindows()
break
if key == 27:
cv2.destroyAllWindows()
cap.release()
break

object_color_hsv = cv2.cvtColor(object_color, cv2.COLOR_BGR2HSV)
object_hist = cv2.calcHist([object_color_hsv], [0, 1], None,
[12, 15], [0, 180, 0, 256])

cv2.normalize(object_hist, object_hist, 0, 255, cv2.NORM_MINMAX)
cap.release()
return object_hist


def locate_object(frame, object_hist):
hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

# apply back projection to image using object_hist as
# the model histogram
object_segment = cv2.calcBackProject(
[hsv_frame], [0, 1], object_hist, [0, 180, 0, 256], 1)

disc = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (9, 9))
cv2.filter2D(object_segment, -1, disc, object_segment)

_, segment_thresh = cv2.threshold(
object_segment, 70, 255, cv2.THRESH_BINARY)

# apply some image operations to enhance image
kernel = None
eroded = cv2.erode(segment_thresh, kernel, iterations=2)
dilated = cv2.dilate(eroded, kernel, iterations=2)
closing = cv2.morphologyEx(dilated, cv2.MORPH_CLOSE, kernel)

# masking
masked = cv2.bitwise_and(frame, frame, mask=closing)

return closing, masked, segment_thresh


def detect_hand(frame, hist):
detected_hand, masked, raw = locate_object(frame, hist)
return Hand(detected_hand, masked, raw, frame)
2 changes: 2 additions & 0 deletions team#29 - Smart_Communication/experimental/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy
opencv-python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading