Skip to content

Commit 123e75b

Browse files
authored
Merge pull request #139 from ulvestad/comments
Improved comments
2 parents fdc6ecf + c0c1095 commit 123e75b

28 files changed

+1542
-447
lines changed
Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1+
"""
2+
3+
Filename: dist/pythonScript/label_image.py
4+
@Author: Group 13
5+
6+
Description: Uses the TensorFlow library for python to parse the trained graph and predict
7+
if an input image is either quarry or not and update database accordingly.
8+
9+
Globals:
10+
image_dir - Where to look for images to scan
11+
scanned_img_dir - Where to place images after they have been scanned
12+
conn - Database connection
13+
label_lines - Labels for output from graph. (e.g. quarry or nonquarry)
14+
15+
Output:
16+
Updated database
17+
18+
"""
19+
120
import tensorflow as tf, sys, os
221
import sqlite3
322
import sys
423
import shutil
524

625
image_dir = "maps/"
726
scanned_img_dir = "scannedMaps/"
8-
#image_dir = sys.argv[1]
9-
#log_filename = "log.txt"
10-
#log = open(log_filename, 'w')
1127
conn = sqlite3.connect('db/QuarryLocations.db')
12-
#counter = 0
13-
#threshold = 0.65
1428

1529
# Loads label file, strips off carriage return
16-
label_lines = [line.rstrip() for line
30+
label_lines = [line.rstrip() for line
1731
in tf.gfile.GFile("graphs/retrained_labels.txt")]
1832

1933
# Unpersists graph from file
@@ -23,86 +37,49 @@
2337
del(graph_def.node[1].attr["dct_method"]) #needed for newGraphs
2438
_ = tf.import_graph_def(graph_def, name='')
2539

40+
#Starts session (comparable to main function for TensorFlow)
2641
with tf.Session() as sess:
2742
# Feed the image_data as input to the graph and get first prediction
2843
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
2944
try:
3045
for filename in os.listdir(image_dir):
31-
#counter += 1
3246
if filename.endswith(".jpg"):
3347
img_name = filename
3448
filename = os.path.join(image_dir, filename)
49+
50+
# Read image file
3551
image_data = tf.gfile.FastGFile(filename, 'rb').read()
3652
predictions = sess.run(softmax_tensor, \
3753
{'DecodeJpeg/contents:0': image_data})
54+
3855
# Sort to show labels of first prediction in order of confidence
3956
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
40-
print ("\n")
41-
print (filename)
42-
#log.write(filename +'\t')
57+
58+
# Loop trough nodes to check results
4359
for node_id in top_k:
4460
human_string = label_lines[node_id]
4561
score = predictions[0][node_id]
46-
#print('%s (score = %.5f)' % (human_string, score))
47-
#log.write('%s (score = %.5f)\t' % (human_string, score))
62+
63+
# Only look for the quarry prediction
4864
if human_string == 'quarry':
49-
#line = open("coordinates.txt", "r").readlines()[counter-1]
50-
#cordinates = line.replace('\n','').split(',')
51-
#print('*************** Found something *****************')
52-
#print (cordinates)
53-
#lat_data = cordinates[0]
54-
#long_data = cordinates[1]
5565
scr = float(score)
5666
scr = format(scr, ".5g")
67+
68+
# Format filename
5769
fileName = filename.split("/")
58-
fileName = fileName[1] #remove /maps
59-
#fileName = fileName.replace("-","_") #Escaping special characters for FTS query search on DB
60-
#fileName = fileName.split(".")[0]
61-
print(fileName, scr)
70+
fileName = fileName[1]
71+
72+
# Update database based on results from parsing the neural net
6273
conn.execute("UPDATE PossibleLocations SET Score = ? WHERE FileName = ?",(scr,fileName))
6374
conn.commit()
64-
#log.write('\n')
75+
# Move from maps folder to scannedMaps folder
6576
shutil.move(filename, os.path.join(scanned_img_dir, img_name))
6677
continue
6778
else:
6879
continue
80+
# Close database connection
6981
conn.close()
70-
#log.close()
82+
# Print exception
7183
except Exception as e:
7284
print(str(e))
7385
pass
74-
75-
76-
"""
77-
import tensorflow as tf, sys, os
78-
79-
image_path = sys.argv[1]
80-
81-
# Read in the image_data
82-
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
83-
84-
# Loads label file, strips off carriage return
85-
label_lines = [line.rstrip() for line
86-
in tf.gfile.GFile("/tf_files/retrained_labels.txt")]
87-
88-
# Unpersists graph from file
89-
with tf.gfile.FastGFile("/tf_files/retrained_graph.pb", 'rb') as f:
90-
graph_def = tf.GraphDef()
91-
graph_def.ParseFromString(f.read())
92-
_ = tf.import_graph_def(graph_def, name='')
93-
94-
with tf.Session() as sess:
95-
# Feed the image_data as input to the graph and get first prediction
96-
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
97-
98-
predictions = sess.run(softmax_tensor, \
99-
{'DecodeJpeg/contents:0': image_data})
100-
101-
# Sort to show labels of first prediction in order of confidence
102-
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
103-
104-
for node_id in top_k:
105-
human_string = label_lines[node_id]
106-
score = predictions[0][node_id]
107-
print('%s (score = %.5f)' % (human_string, score))
108-
"""

application/userInterface/index.html

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1+
<!--
2+
Filename: userInterface/index.html
3+
@Author Group 13
4+
5+
Contains all HTML code for displaying the "Main Page" in the application
6+
7+
-->
8+
19
<!DOCTYPE html>
210
<html>
311
<head>
412
<meta charset="utf-8">
513
<meta name="viewport" content="width=device-width, initial-scale=1">
614

715
<title>Analysis of Map and Satellite Images</title>
16+
17+
<!-- Custom Stylesheets-->
818
<link rel="stylesheet" href="css/styles.css">
919
<link rel="stylesheet" href="css/navbar.css">
1020

21+
<!--Bootstrap stylesheet used to style navbar -->
1122
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
1223

13-
<!-- Needed to select folders n' shit -->
24+
<!-- jQuery script needed to select folders-->
1425
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
1526
</head>
1627

1728
<body>
18-
<!-- NAVBAR - NO TOUCHING!! -->
29+
<!-- ______________________________________START "MAIN PAGE" ______________________________________ -->
30+
<!-- ____START "Navbar"____ -->
1931
<!-- The top-navbar for the application, this is the same for all .html pages -->
2032
<nav class="navbar navbar-inverse" id="navbar">
2133
<div class="container-fluid">
@@ -35,80 +47,98 @@
3547
</div>
3648
</div>
3749
</nav>
38-
<!-- NAVBAR - NO TOUCHING!! -->
50+
<!-- ____END "Navbar"____ -->
3951

4052
<div id="hideLoader"></div>
4153
<div id="hideTransparentLayer"> </div>
4254

43-
44-
<!-- The content of the index.html page -->
55+
<!-- "Div Show description" Div that allows the user to show/hide the description of the "Main Page" -->
4556
<div onclick="toggleDescriptionField()" class="togglePageDescription">
4657
<span><b>Show/Hide Main Page Description</b></span>
4758
</div>
4859

60+
<!-- ____START "Div Main page Description"____ -->
61+
<!-- "Div Main Page Description" Contains the description of the "Main Page" -->
4962
<div class="flex-item" id="hideDescription">
5063
<div class="descriptionPlaceholder">
5164
<h2 class="centerHeader"> Main Page</h2>
52-
<p>The main page is where the process of preparing and scanning images is done. Before the scanning of data can be done, it must be preprocessed with the "<b>Pre-process folders</b>"-button after one or more folders containing .jpg-images and associated .xml-files has been selected. When this process is done, all pre-processed data can be scanned using the "<b>Scan pre-processed data</b>"-button, and the results can be seen in the Result Page. The scanning will take some time, depending on the amount of images scanned at once. </p>
53-
54-
<p>The "<b>Update known locations</b>"-button is used to update the Known Locations in the database. This is done by selecting a .CSV file with coordinates to already known locations. After a scan is done and the result has been processed by a user, the "<b>Export new results</b>"-button can be used to get the New Locations as a .CSV-file. The "<b>Reset data</b>"-button resets the pre-processed and scanned data in the system, and should be used when the results from the scan has been exported and processed by a user, or simply just to reset the system. </p>
55-
</div>
56-
</div>
57-
<div class="flex-container mainPageContent">
65+
<p>The main page is where the process of preparing and scanning images is done. Before the scanning of data can be done, it must be preprocessed with the "<b>Pre-process folders</b>"-button after one or more folders containing .jpg-images and associated .xml-files has been selected. When this process is done, all pre-processed data can be scanned using the "<b>Scan pre-processed data</b>"-button, and the results can be seen in the Result Page. The scanning will take some time, depending on the amount of images scanned at once. </p>
5866

59-
<div class="flex-item columnx"> <!-- Container 1 -->
67+
<p>The "<b>Update known locations</b>"-button is used to update the Known Locations in the database. This is done by selecting a .CSV file with coordinates to already known locations. After a scan is done and the result has been processed by a user, the "<b>Export new results</b>"-button can be used to get the New Locations as a .CSV-file. The "<b>Reset data</b>"-button resets the pre-processed and scanned data in the system, and should be used when the results from the scan has been exported and processed by a user, or simply just to reset the system. </p>
68+
</div>
69+
</div>
70+
<!-- ____END "Div Main Page Description"____ -->
71+
72+
<!-- Div container for the "Main Page" content "-->
73+
<div class="flex-container mainPageContent">
74+
75+
<!-- ____START "Div container Process data"____ -->
76+
<!-- "Div container Process data" Contains buttons for processing data, selecting folders, and scanning selected folders -->
77+
<div class="flex-item columnx">
6078
<h3>Process Data</h3>
6179
<div class="flex-item scanButtons" id="scanButtons"> <!-- BUTTONS for the page -->
6280
<p>Selected folders: </p>
6381
<textarea rows="10" cols="50" readonly id="folderPathSelected" style = "height:100px; overflow:hidden; font-size: 11px; overflow:hidden; overflow-y:scroll;">
6482
</textarea><br>
6583
<button onclick="openFolder()" id="btnOpenFolder" style="font-family:Open Sans Condensed;">Select a folder</button>
66-
<button onclick="clearFolderList()" id="btnClearFolderList" style="font-family:Open Sans Condensed;"></button>
84+
<button onclick="clearFolderList()" id="btnClearFolderList" style="font-family:Open Sans Condensed;"></button>
6785
<button onclick="preProcessing()" id="btnPreProcessing" style="font-family:Open Sans Condensed;">Pre-process folders</button>
6886
<br>
6987
<span id="pFolderProgress"></span>
7088
<br><br>
7189
<button onclick="launchProgram()" id="btnLaunchProgram" style="font-family:Open Sans Condensed;">Scan pre-processed data</button>
7290
<br> <span>Scans all pre-processed images for potential quarries. This may take some time.</span> <br><br><br>
73-
91+
7492
</div>
7593
</div>
94+
<!-- ____END "Div container Process data"____ -->
7695

77-
<div class="flex-item columnx"><!-- Container 2 -->
96+
<!-- ____START "Div container data management"____ -->
97+
<!-- "Div container data management" Contains buttons for reseting, updating, and exporting data -->
98+
<div class="flex-item columnx">
7899
<h3>Manage Database</h3>
79100
<br>
80-
<button onclick="wipeDbAndMaps()" id="btnWipeDBAndMaps" style="font-family:Open Sans Condensed;">Reset data</button>
101+
<button onclick="wipeDbAndMaps()" id="btnWipeDBAndMaps" style="font-family:Open Sans Condensed;">Reset data</button>
81102
<br><span>Removes all pre-processed and scanned data.</span> <br><br>
82103
<button onclick="openCSVFile()" id="btnOpenCSVFile" style="font-family:Open Sans Condensed;">Update known locations</button>
83104
<br><span>Select a .CSV file with coordinates to all known locations. </span> <br><br>
84105
<button onclick="openFolderCSV()" id="btnOpenFolderCSV" style="font-family:Open Sans Condensed;">Export new results</button>
85106
<br><span>Export all new confirmed locations as a .CSV file</span> <br><br>
86-
107+
87108
</div>
88-
<div class="flex-item columnx"> <!-- Container 3 -->
109+
<!-- ____END "Div container data management"____ -->
110+
111+
<!-- ____START "Div container Textarea"____ -->
112+
<!-- "Div container Textarea" Contains the textarea for giving feedback to the user -->
113+
<div class="flex-item columnx">
89114
<br>
90115
<textarea rows="21" cols="50" readonly id="textOutput"></textarea>
91116
</div>
117+
<!-- ____END "Div container Textarea"____ -->
92118
</div>
93-
<!-- ______________________________________END OF MAIN________________________________________ -->
119+
<!-- ______________________________________END "MAIN PAGE"________________________________________ -->
94120

95121

96122

97-
<!-- EVERYTHING SCRIPT-RELATED -->
98-
<!-- Needed to select folders or some shit -->
123+
<!-- ______________________________________START "SCRIPT SECTION"________________________________________ -->
124+
<!-- ____START "Input File Dialog"____ -->
125+
<!-- "Input File Dialog and CSV" Needed for selection of files -->
99126
<input style="display:none;" id="fileDialog" type="file" webkitdirectory />
100127
<input style="display:none;" id="csvFile" type="file" />
128+
<!-- ____END "Input File Dialog"____ -->
101129

102-
<!-- Needed to solve jquery issue -->
130+
<!-- Needed because Electron does not recognize jQuery libraries -->
103131
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
104132

133+
<!-- jQuery import used in navbar -->
105134
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
135+
<!-- Bootstrap import used in navbar -->
106136
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
107137

108-
<!-- Needed to solve jquery issue -->
138+
<!-- Needed because Electron does not recognize jQuery libraries -->
109139
<script>if (window.module) module = window.module;</script>
110140

111-
<!-- All javascript file inclusions -->
141+
<!-- All custom javascript file imports -->
112142
<script src="js/launchEXE.js"></script>
113143
<script src="js/navbar.js"></script>
114144
<script src="js/updateDBSelectFile.js"></script>
@@ -117,5 +147,6 @@ <h3>Manage Database</h3>
117147
<script src="js/moveFiles.js"></script>
118148
<script src="js/xmlReader.js"></script>
119149
<script src="js/resetDB.js"></script>
150+
<!-- ______________________________________END "SCRIPT SECTION"________________________________________ -->
120151
</body>
121-
</html>
152+
</html>
Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
1-
//DISPLAYS IMAGE OF SELECTED POTENTIAL QUARRY
2-
//Static imagePath to the ScannedMaps folder
3-
var imagePath = "../scannedMaps/";
1+
/*
2+
Filename: userInterface/js/displayImage.js
3+
@Author Group 13
4+
5+
Displays the image-file that is specified in the "imageName" parameter on ther result page
6+
7+
Globals:
8+
imagePath - the path to the folder where the image-files are located
9+
emptyImagePath - the path to the empty white image used when no image is available
10+
*/
11+
var imagePath = "../scannedMaps/"; // This file has to be located in the /scannedmaps folder, as specified in the "ImagePath" variable.
412
var emptyImagePath = "../userInterface/icons/white.jpg"
5-
//Run this function when clicking on a marker/list item for a quarry. Insert correct imageName
13+
14+
15+
16+
/*
17+
getCurrentImage
18+
19+
Displays the image in /scannedmaps that has the provided filename.
20+
21+
Inputs:
22+
- Image filename
23+
24+
Outputs:
25+
- Displays the specified image on the result page
26+
27+
Returns: None
28+
29+
*/
630
function getCurrentImage(imageName){
731
fullImagePath = imagePath + imageName;
832
if (imageName != ""){
9-
document.getElementById('quarryImage').src=fullImagePath;
33+
document.getElementById('quarryImage').src=fullImagePath; //Displays the image
1034
}else{
11-
document.getElementById('quarryImage').src = emptyImagePath;
35+
document.getElementById('quarryImage').src = emptyImagePath; //Displays an empty white image, used when no image should be displayed
1236
}
13-
1437
}

0 commit comments

Comments
 (0)