Skip to content

Commit 6cf647a

Browse files
Changed algorithm to used to detect houses. Removed redundant code in recolour.py
1 parent 604deb4 commit 6cf647a

14 files changed

+60
-33
lines changed

.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ __pycache__/
88
*.py[cod]
99
*$py.class
1010

11+
tapplacement/*
12+
venv/*
13+
14+
credentials.py
15+
16+
*.pyc
17+
1118
# C extensions
1219
*.so
1320

@@ -126,4 +133,5 @@ dmypy.json
126133
# End of https://www.gitignore.io/api/python
127134

128135
# Visual Studio Code
129-
.vscode/
136+
.vscode/
137+
.pylintrc

TapWork.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import math
22
from PIL import Image, ImageChops
33
import networkx as nx
4+
import matplotlib
5+
# matplotlib.use('TkAgg')
6+
matplotlib.use('agg')
47
import matplotlib.pyplot as plt
58
import itertools
69
import cv2
@@ -124,4 +127,4 @@ def greedy_brute(houses,amount_of_taps,grid_size):
124127

125128
min_total_differnces = total_differnce
126129
stored_taps.append(happy_taps[-1])
127-
return stored_taps
130+
return stored_taps

api.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import cv2
55
import base64
66
import numpy
7-
import TapWork, recolour, resize, contours, map_downloader
8-
9-
API_KEY = 'AgqByPum4K6T5wlV3oIAhSDvFHVRuoPs6cwipRdvprWtmvqld0poyLI54AP0e6HI'
7+
import TapWork, recolour, resize, contours, map_downloader, credentials
108

119
app = Flask(__name__)
1210
cors = CORS(app)
@@ -38,7 +36,7 @@ def giveLocation():
3836
response = Response()
3937
response.status_code = 400
4038
return response
41-
response = map_downloader.download_patch((lat,lon),API_KEY)
39+
response = map_downloader.download_patch((lat,lon), credentials.API_KEY)
4240
image_array = numpy.asarray(bytearray(response.content), dtype=numpy.uint8)
4341
map_image = cv2.imdecode(image_array, -1)
4442
if max_size is not None and taps is not None:

contours.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
# construct the argument parse and parse the arguments
66
def get_contour_nodes(image):
7-
height, width, channels = image.shape
8-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
9-
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
10-
thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY)[1]
7+
height, width = image.shape
8+
# gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
9+
# blurred = cv2.GaussianBlur(gray, (5, 5), 0)
10+
# thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY)[1]
1111

1212
# find contours in the thresholded image
13-
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
13+
cnts = cv2.findContours(image.copy(), cv2.RETR_EXTERNAL,
1414
cv2.CHAIN_APPROX_SIMPLE)
1515
cnts = imutils.grab_contours(cnts)
1616

@@ -20,7 +20,7 @@ def get_contour_nodes(image):
2020
for c in cnts:
2121
# compute the center of the contour
2222
try:
23-
if cv2.contourArea(c) > 40:
23+
if cv2.contourArea(c) > 5:
2424
M = cv2.moments(c)
2525
cX = int(M["m10"] / M["m00"])
2626
cY = int(M["m01"] / M["m00"])

figureTaps(hsv).png

157 KB
Loading

figureTaps(hsv2).png

157 KB
Loading

figureTaps.png

19.1 KB
Loading

figureTaps1.png

154 KB
Loading

figureTaps2.png

151 KB
Loading

figureTaps3(rgb).png

156 KB
Loading

main.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1+
import cv2
2+
import numpy as np
13
import resize
24
import recolour
35
import contours
46
import TapWork
57
import map_downloader
6-
import cv2
7-
import numpy as np
8+
import credentials
89

9-
API_KEY = 'PLACEHOLDER'
10-
11-
response = map_downloader.download_patch((13.623299, -15.192386),API_KEY)
10+
# 13.624999, -15.191250
11+
# 13.623299, -15.192386
12+
response = map_downloader.download_patch((13.624999, -15.191250), credentials.API_KEY)
13+
print("Got map")
1214
image_array = np.asarray(bytearray(response.content), dtype=np.uint8)
1315
map_image = cv2.imdecode(image_array, -1)
1416
max_size = 200
15-
resized_image = resize.resize(map_image,max_size)
17+
resized_image = resize.resize(map_image, max_size)
1618
height, width, _ = resized_image.shape
19+
cv2.imwrite("test.png", resized_image)
20+
cv2.imshow("Window", resized_image)
21+
cv2.waitKey(0)
22+
1723
recoloured_image = recolour.find_silver(resized_image)
24+
cv2.imshow("Window", recoloured_image)
25+
cv2.waitKey(0)
26+
1827
houses = contours.get_contour_nodes(recoloured_image)
19-
tap_locations = TapWork.greedy_brute(houses,5,(height,width))
20-
TapWork.draw_network(houses,tap_locations,resized_image)
28+
print(houses)
29+
tap_locations = TapWork.greedy_brute(houses, 5, (height, width))
30+
print(tap_locations)
31+
TapWork.draw_network(houses, tap_locations, resized_image)

mapppp.png

100 KB
Loading

recolour.py

+20-13
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22
import numpy
33

44
def find_silver(image):
5+
image = cv2.GaussianBlur(image,(5,5),0)
56
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
6-
h,s,v = cv2.split(hsv)
7-
87
rgb = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
98

10-
mask = cv2.inRange(rgb, (150,160,160), (255, 255, 255))
11-
image = cv2.bitwise_and(image, image, mask=mask)
12-
13-
for w in range(image.shape[0]):
14-
for h in range(image.shape[1]):
15-
# checks if not pure black
16-
if(all(rgb != 0 for rgb in image[w][h])):
17-
# makes pixel completely white
18-
for colour in range(image.shape[2]):
19-
image[w][h][colour] = 255
20-
return image
9+
cv2.imshow("HSV", hsv)
10+
cv2.waitKey();
11+
12+
mask2 = cv2.inRange(hsv, (10,0,120), (85, 70, 255))
13+
# mask2 = cv2.inRange(hsv, (0,0,180), (255, 255, 255))
14+
15+
16+
cv2.imshow("mask2", mask2)
17+
18+
newimage = cv2.bitwise_and(rgb, rgb, mask=mask2)
19+
mask = cv2.inRange(rgb, (150,150,140), (255, 255, 255))
20+
21+
22+
23+
cv2.imshow("mask", mask)
24+
cv2.waitKey();
25+
26+
27+
return mask

test.png

99.7 KB
Loading

0 commit comments

Comments
 (0)