├── Run.exe
├── Vicinity.zip
├── CONTRIBUTING.md
├── README.md
├── help.html
├── SendGes.py
└── ReceiveGes.py
/Run.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/siwalikm/Vicinity/HEAD/Run.exe
--------------------------------------------------------------------------------
/Vicinity.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/siwalikm/Vicinity/HEAD/Vicinity.zip
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | You are free to improve/clean the code, add functionalities to the application.
2 |
3 | You can also contact me at contact@siwalik.in to discuss or report an issue.
4 |
5 | Happy Hacking!
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Vicinity
4 |
5 |
6 |
7 | A python based app which lets you transfer files within computers in the same network, using Simple Hand Gestures.
8 |
9 | This is a hobby project created along with my friends YashParikh and AnubhavArukia.
10 | USAGE POLICY >> You're free to use the app and free to contribute to it but any commercial usage of this application is strictly prohibited without prior permission from the authors.
11 |
12 | HOW TO USE >> To use the application, first create a directory in C drive called "VICINITY".
13 | Copy contents of zip package to c:/VICINITY and you're ready to run the app.
14 |
15 | Run the run.exe file in both the sender and receiver computer, make sure that both computers are connected to the same wifi or hotspot.
16 | Click "Receive" on the receiving computer.. on the sending computer, copy files to send folder and then click on send.
17 |
18 | The app will dynamically connect the two computers and then open the camera terminal in both the computers. Do a "Grab" gesture on
19 | the sender computer and with a "Release" gesture, drop the files into the receiver pc.
20 |
--------------------------------------------------------------------------------
/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
VICINITY - DOCUMENTATION
13 |
14 |
15 |
16 |
SENDING A FILE
17 |
18 | 1. To Initiate data transfer, first copy the files you want to transfer to the "SEND" folder in your application root.
19 |
20 | 2. Ensure all the devices participating in the data transfer are part of the same network i.e., make sure they are connected to the same WIFI or the same Wired LAN.
21 |
22 | 3. Wait for the receiver to run the Run.exe application on their computer first and select the "Receive" option present in the menu. It is very important to make sure that the receiver runs the application before you.
23 |
24 | 4. Once the Receiver has performed step 3, run the Run.exe application and select "Send".
25 |
26 | 5. A camera interface will open shortly. Place only your hand inside the given box and make a grab gesture there to initiate the transfer. Note. We perform a grab gesture by showing your full palm showing all the 5 fingers stretched broad wide and then quickly making a fist, as if you're grabbing something.
27 |
28 | 6. Congratulations! Your work is done.
29 |
30 |
31 |
32 |
RECEIVING A FILE
33 |
34 | 1. To receive a file, run the Run.exe application on their computer first and select the "Receive" option present in the menu. It is very important to make sure that you runs the application before the sender tries to send any data.
35 |
36 | 2. Wait for the sender to perform send gesture on his computer. Once this is done, a camera interface will pop up on your screen. Place your hand inside the given box and perform a release gesture there to receive the files. Note. We perform a release gesture by showing your fist and then quickly show your palm showing all the 5 fingers stretched broad wide, as if you're releasing something.
37 |
38 | 3. Congratulations! Your work is done. Check the received files in the "RECEIVE" folder in your application root.
39 |
40 |
41 |
42 |
43 |
About VICINITY
44 |
45 | VICINITY is available for download, completely free of cost.
46 |
47 | This project has been developed completely from scratch in Python and the source code is freely available in GitHub for further development and modification according to the user's needs.
48 |
49 | This project has been developed by Siwalik Mukherjee, Anubhav Arukia and Yash Parikh of final semester CSE department of MVJ College of Engineering, Bangalore.
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/SendGes.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import math
4 | import os
5 |
6 |
7 | p = 0
8 | q = 0
9 |
10 | # Test_Server_py_START
11 |
12 | import socket
13 |
14 | s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
15 | s.connect(("8.8.8.8", 80))
16 | ip = s.getsockname()[0]
17 |
18 | BC_PORT = 9012
19 | # port for ip broadcast
20 | import sys
21 | import time
22 | from socket import *
23 |
24 | s = socket(AF_INET, SOCK_DGRAM)
25 | s.bind(('', 0))
26 | s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
27 | # Include IP headers: setsockopt
28 | s.sendto(ip, ('', BC_PORT))
29 | # Send data to the socket
30 |
31 |
32 | # Test_Server_py_END
33 |
34 |
35 | cap = cv2.VideoCapture(0)
36 | cam = 1
37 | while True:
38 |
39 | while(cam):
40 | ret, img = cap.read()
41 | # Deleting this is causing an error,dont know why!
42 | cv2.rectangle(img, (250, 250), (50, 50), (0, 255, 0), 1)
43 | crop_img = img[50:250, 50:250]
44 | grey = cv2.cvtColor(crop_img, cv2.COLOR_BGR2GRAY)
45 | value = (35, 35)
46 | blurred = cv2.GaussianBlur(grey, value, 0)
47 | _, thresh1 = cv2.threshold(blurred, 127, 255,
48 | cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
49 | cv2.imshow('Thresholded', thresh1)
50 | _, contours, hierarchy = cv2.findContours(
51 | thresh1.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
52 |
53 | max_area = -1
54 | for i in range(len(contours)):
55 | cnt = contours[i]
56 | area = cv2.contourArea(cnt)
57 | if(area > max_area):
58 | max_area = area
59 | ci = i
60 | cnt = contours[ci]
61 | x, y, w, h = cv2.boundingRect(cnt)
62 | # Red box in the img window from the countours
63 | cv2.rectangle(crop_img, (x, y), (x + w, y + h), (0, 0, 255), 0)
64 | hull = cv2.convexHull(cnt)
65 | drawing = np.zeros(crop_img.shape, np.uint8)
66 | # contour window green
67 | cv2.drawContours(drawing, [cnt], 0, (0, 255, 0), 0)
68 | # contour window red line
69 | cv2.drawContours(drawing, [hull], 0, (0, 0, 255), 0)
70 | hull = cv2.convexHull(cnt, returnPoints=False)
71 | defects = cv2.convexityDefects(cnt, hull)
72 | count_defects = 0
73 |
74 | cv2.drawContours(thresh1, contours, -1, (0, 255, 0), 3)
75 | for i in range(defects.shape[0]):
76 | s, e, f, d = defects[i, 0]
77 | start = tuple(cnt[s][0])
78 | end = tuple(cnt[e][0])
79 | far = tuple(cnt[f][0])
80 | a = math.sqrt((end[0] - start[0])**2 + (end[1] - start[1])**2)
81 | b = math.sqrt((far[0] - start[0])**2 + (far[1] - start[1])**2)
82 | c = math.sqrt((end[0] - far[0])**2 + (end[1] - far[1])**2)
83 | angle = math.acos((b**2 + c**2 - a**2) / (2 * b * c)) * 57
84 | if angle <= 90:
85 | count_defects += 1
86 | cv2.circle(crop_img, far, 1, [0, 0, 255], -1)
87 | #dist = cv2.pointPolygonTest(cnt,far,True)
88 | cv2.line(crop_img, start, end, [0, 255, 0], 2)
89 | # cv2.circle(crop_img,far,5,[0,0,255],-1)
90 |
91 | if count_defects == 1:
92 | cv2.putText(img, "defect 1", (50, 50),
93 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
94 | if p == 1:
95 | q = 1
96 | cam = 0
97 | elif count_defects == 2:
98 | cv2.putText(img, "defect 2", (50, 50),
99 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
100 |
101 | elif count_defects == 3:
102 | cv2.putText(img, "defect 3", (50, 50),
103 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
104 | elif count_defects == 4:
105 | cv2.putText(img, "defect 4", (50, 50),
106 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
107 | elif count_defects == 5:
108 | cv2.putText(img, "defect 5", (50, 50),
109 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
110 | p = 1
111 |
112 | else:
113 | cv2.putText(img, "Default defect", (50, 50),
114 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
115 | #cv2.imshow('drawing', drawing)
116 | # cv2.imshow('end', crop_img) #Crop_img part of screen(The green box)
117 | cv2.imshow('Gesture', img)
118 | all_img = np.hstack((drawing, crop_img))
119 | cv2.imshow('Contours', all_img)
120 | if cv2.waitKey(10) & 0xFF == ord('q'):
121 | exit()
122 |
123 | if p == 1 and q == 1:
124 |
125 | import SimpleHTTPServer
126 | import SocketServer
127 | import sys
128 | import time
129 | import socket
130 |
131 | cap.release()
132 | cv2.destroyAllWindows()
133 | p = 0
134 | q = 0
135 | # START HTTP server
136 | PORT = 8000
137 | Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
138 | Handler.extensions_map.update({
139 | '.webapp': 'application/x-web-app-manifest+json',
140 | })
141 |
142 | httpd = SocketServer.TCPServer(("", PORT), Handler)
143 |
144 | httpd.serve_forever()
145 |
146 | # END ~ Server Created
147 |
148 | #cam = 1
149 | #cap = cv2.VideoCapture(0)
150 |
151 | if cv2.waitKey(10) & 0xFF == ord('q'):
152 | exit()
153 |
154 | cap.release()
155 | cv2.destroyAllWindows()
156 |
--------------------------------------------------------------------------------
/ReceiveGes.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import math
4 | import urllib
5 | import select
6 | import socket
7 | import os
8 |
9 | k = 0
10 | m = 0
11 | cam = 1
12 |
13 | # Code for receiving sender's IP
14 |
15 | import select
16 | import socket
17 |
18 | port = 9012 # where do you expect to get a msg?
19 | bufferSize = 1024 # whatever you need
20 |
21 | # address family and connection type
22 | s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
23 | s.bind(("", port))
24 | s.setblocking(0)
25 |
26 | ip_count = 0
27 | # takes ip
28 | while True:
29 | result = select.select([s], [], [])
30 | ip = result[0][0].recv(bufferSize)
31 | # print ip
32 | break
33 |
34 |
35 | print("ip successfully received")
36 | print("The ip address of sender is:" + ip)
37 | print("Ready to receive the data.")
38 | print("-------------------------------------------")
39 |
40 |
41 | # IP is received!
42 |
43 | cap = cv2.VideoCapture(0)
44 |
45 | while True:
46 |
47 | while(cam):
48 | ret, img = cap.read()
49 | cv2.rectangle(img, (250, 250), (50, 50),
50 | (0, 255, 0), 0) # green rectangle
51 | crop_img = img[50:250, 50:250]
52 | grey = cv2.cvtColor(crop_img, cv2.COLOR_BGR2GRAY)
53 | value = (35, 35)
54 | blurred = cv2.GaussianBlur(grey, value, 0)
55 | _, thresh1 = cv2.threshold(blurred, 127, 255,
56 | cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU) # optimal threahold value
57 | cv2.imshow('Thresholded', thresh1)
58 | _, contours, hierarchy = cv2.findContours(thresh1.copy(
59 | ), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) # retrieves all of the contours
60 |
61 | max_area = -1
62 | for i in range(len(contours)): # finds outer boundary contour
63 | cnt = contours[i]
64 | area = cv2.contourArea(cnt)
65 | if(area > max_area):
66 | max_area = area
67 | ci = i
68 | cnt = contours[ci]
69 | x, y, w, h = cv2.boundingRect(cnt)
70 | cv2.rectangle(crop_img, (x, y), (x + w, y + h),
71 | (0, 0, 255), 0) # red box from the countours
72 | hull = cv2.convexHull(cnt)
73 | drawing = np.zeros(crop_img.shape, np.uint8) # uint8 data type
74 | # contour window green
75 | cv2.drawContours(drawing, [cnt], 0, (0, 255, 0), 0)
76 | # contour window red line
77 | cv2.drawContours(drawing, [hull], 0, (0, 0, 255), 0)
78 | # returns indices of contour point corresponding to the hull point
79 | hull = cv2.convexHull(cnt, returnPoints=False)
80 | defects = cv2.convexityDefects(cnt, hull)
81 | count_defects = 0
82 |
83 | cv2.drawContours(thresh1, contours, -1, (0, 255, 0), 3)
84 | for i in range(defects.shape[0]):
85 | s, e, f, d = defects[i, 0]
86 | start = tuple(cnt[s][0])
87 | end = tuple(cnt[e][0])
88 | far = tuple(cnt[f][0])
89 | a = math.sqrt((end[0] - start[0])**2 + (end[1] - start[1])**2)
90 | b = math.sqrt((far[0] - start[0])**2 + (far[1] - start[1])**2)
91 | c = math.sqrt((end[0] - far[0])**2 + (end[1] - far[1])**2)
92 | angle = math.acos((b**2 + c**2 - a**2) / (2 * b * c)) * 57
93 | if angle <= 90:
94 | count_defects += 1
95 | cv2.circle(crop_img, far, 1, [0, 0, 255], -1)
96 | #dist = cv2.pointPolygonTest(cnt,far,True)
97 | cv2.line(crop_img, start, end, [0, 255, 0], 2)
98 | # cv2.circle(crop_img,far,5,[0,0,255],-1)
99 |
100 | if count_defects == 1:
101 | cv2.putText(img, "defect 1", (50, 50),
102 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
103 | k = 1
104 | elif count_defects == 2:
105 | cv2.putText(img, "defect 2", (50, 50),
106 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
107 | elif count_defects == 3:
108 | cv2.putText(img, "defect 3", (50, 50),
109 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
110 | elif count_defects == 4:
111 | cv2.putText(img, "defect 4", (50, 50),
112 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
113 | elif count_defects == 5:
114 | cv2.putText(img, "defect 5", (50, 50),
115 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
116 | if k == 1:
117 | m = 1
118 | cam = 0
119 |
120 | else:
121 | cv2.putText(img, "Default defect", (50, 50),
122 | cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
123 | #cv2.imshow('drawing', drawing)
124 | # cv2.imshow('end', crop_img) #Crop_img part of screen(The green box)
125 | cv2.imshow('Gesture', img)
126 | all_img = np.hstack((drawing, crop_img)) # horizontal stack
127 | cv2.imshow('Contours', all_img)
128 | if cv2.waitKey(10) & 0xFF == ord('q'):
129 | exit()
130 |
131 | if k == 1 and m == 1: # k and m are set to 1 which shows fingers went 1 to 5
132 |
133 | k = 0
134 | cam = 0
135 | cap.release()
136 | cv2.destroyAllWindows()
137 | testfile = urllib.URLopener()
138 |
139 | from urllib2 import urlopen
140 | import re
141 |
142 | urlpath = urlopen("http://" + ip + ":8000/SEND/")
143 | string = urlpath.read().decode('utf-8')
144 |
145 | # the pattern actually creates duplicates in the list
146 | pattern = re.compile('[\w\s,!@#$%^&*()=-]*[.][\w]{1,4}"')
147 | filelist = pattern.findall(string)
148 |
149 | print("Received files are:\n")
150 |
151 | for filenames in filelist:
152 | print(filenames[:-1])
153 | fullfilename = os.path.join("C:\VICINITY\RECEIVE", filenames[:-1])
154 | testfile.retrieve("http://" + ip + ":8000/SEND/" +
155 | filenames[:-1], fullfilename)
156 |
157 | print("Goto Received folder to see the files.")
158 | #cam = 1
159 | #cap = cv2.VideoCapture(0)
160 |
161 | if cv2.waitKey(10) & 0xFF == ord('q'):
162 | break
163 |
164 | cap.release()
165 | cv2.destroyAllWindows()
166 |
--------------------------------------------------------------------------------