Skip to content

Commit

Permalink
Merge pull request #139 from ulvestad/comments
Browse files Browse the repository at this point in the history
Improved comments
  • Loading branch information
cbroko authored May 31, 2017
2 parents fdc6ecf + c0c1095 commit 123e75b
Show file tree
Hide file tree
Showing 28 changed files with 1,542 additions and 447 deletions.
95 changes: 36 additions & 59 deletions application/dist/pythonScript/label_image.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
"""
Filename: dist/pythonScript/label_image.py
@Author: Group 13
Description: Uses the TensorFlow library for python to parse the trained graph and predict
if an input image is either quarry or not and update database accordingly.
Globals:
image_dir - Where to look for images to scan
scanned_img_dir - Where to place images after they have been scanned
conn - Database connection
label_lines - Labels for output from graph. (e.g. quarry or nonquarry)
Output:
Updated database
"""

import tensorflow as tf, sys, os
import sqlite3
import sys
import shutil

image_dir = "maps/"
scanned_img_dir = "scannedMaps/"
#image_dir = sys.argv[1]
#log_filename = "log.txt"
#log = open(log_filename, 'w')
conn = sqlite3.connect('db/QuarryLocations.db')
#counter = 0
#threshold = 0.65

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

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

#Starts session (comparable to main function for TensorFlow)
with tf.Session() as sess:
# Feed the image_data as input to the graph and get first prediction
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
try:
for filename in os.listdir(image_dir):
#counter += 1
if filename.endswith(".jpg"):
img_name = filename
filename = os.path.join(image_dir, filename)

# Read image file
image_data = tf.gfile.FastGFile(filename, 'rb').read()
predictions = sess.run(softmax_tensor, \
{'DecodeJpeg/contents:0': image_data})

# Sort to show labels of first prediction in order of confidence
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
print ("\n")
print (filename)
#log.write(filename +'\t')

# Loop trough nodes to check results
for node_id in top_k:
human_string = label_lines[node_id]
score = predictions[0][node_id]
#print('%s (score = %.5f)' % (human_string, score))
#log.write('%s (score = %.5f)\t' % (human_string, score))

# Only look for the quarry prediction
if human_string == 'quarry':
#line = open("coordinates.txt", "r").readlines()[counter-1]
#cordinates = line.replace('\n','').split(',')
#print('*************** Found something *****************')
#print (cordinates)
#lat_data = cordinates[0]
#long_data = cordinates[1]
scr = float(score)
scr = format(scr, ".5g")

# Format filename
fileName = filename.split("/")
fileName = fileName[1] #remove /maps
#fileName = fileName.replace("-","_") #Escaping special characters for FTS query search on DB
#fileName = fileName.split(".")[0]
print(fileName, scr)
fileName = fileName[1]

# Update database based on results from parsing the neural net
conn.execute("UPDATE PossibleLocations SET Score = ? WHERE FileName = ?",(scr,fileName))
conn.commit()
#log.write('\n')
# Move from maps folder to scannedMaps folder
shutil.move(filename, os.path.join(scanned_img_dir, img_name))
continue
else:
continue
# Close database connection
conn.close()
#log.close()
# Print exception
except Exception as e:
print(str(e))
pass


"""
import tensorflow as tf, sys, os
image_path = sys.argv[1]
# Read in the image_data
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
# Loads label file, strips off carriage return
label_lines = [line.rstrip() for line
in tf.gfile.GFile("/tf_files/retrained_labels.txt")]
# Unpersists graph from file
with tf.gfile.FastGFile("/tf_files/retrained_graph.pb", 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')
with tf.Session() as sess:
# Feed the image_data as input to the graph and get first prediction
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
predictions = sess.run(softmax_tensor, \
{'DecodeJpeg/contents:0': image_data})
# Sort to show labels of first prediction in order of confidence
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
for node_id in top_k:
human_string = label_lines[node_id]
score = predictions[0][node_id]
print('%s (score = %.5f)' % (human_string, score))
"""
81 changes: 56 additions & 25 deletions application/userInterface/index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
<!--
Filename: userInterface/index.html
@Author Group 13
Contains all HTML code for displaying the "Main Page" in the application
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Analysis of Map and Satellite Images</title>

<!-- Custom Stylesheets-->
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/navbar.css">

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

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

<body>
<!-- NAVBAR - NO TOUCHING!! -->
<!-- ______________________________________START "MAIN PAGE" ______________________________________ -->
<!-- ____START "Navbar"____ -->
<!-- The top-navbar for the application, this is the same for all .html pages -->
<nav class="navbar navbar-inverse" id="navbar">
<div class="container-fluid">
Expand All @@ -35,80 +47,98 @@
</div>
</div>
</nav>
<!-- NAVBAR - NO TOUCHING!! -->
<!-- ____END "Navbar"____ -->

<div id="hideLoader"></div>
<div id="hideTransparentLayer"> </div>


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

<!-- ____START "Div Main page Description"____ -->
<!-- "Div Main Page Description" Contains the description of the "Main Page" -->
<div class="flex-item" id="hideDescription">
<div class="descriptionPlaceholder">
<h2 class="centerHeader"> Main Page</h2>
<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>

<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>
</div>
</div>
<div class="flex-container mainPageContent">
<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>

<div class="flex-item columnx"> <!-- Container 1 -->
<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>
</div>
</div>
<!-- ____END "Div Main Page Description"____ -->

<!-- Div container for the "Main Page" content "-->
<div class="flex-container mainPageContent">

<!-- ____START "Div container Process data"____ -->
<!-- "Div container Process data" Contains buttons for processing data, selecting folders, and scanning selected folders -->
<div class="flex-item columnx">
<h3>Process Data</h3>
<div class="flex-item scanButtons" id="scanButtons"> <!-- BUTTONS for the page -->
<p>Selected folders: </p>
<textarea rows="10" cols="50" readonly id="folderPathSelected" style = "height:100px; overflow:hidden; font-size: 11px; overflow:hidden; overflow-y:scroll;">
</textarea><br>
<button onclick="openFolder()" id="btnOpenFolder" style="font-family:Open Sans Condensed;">Select a folder</button>
<button onclick="clearFolderList()" id="btnClearFolderList" style="font-family:Open Sans Condensed;"></button>
<button onclick="clearFolderList()" id="btnClearFolderList" style="font-family:Open Sans Condensed;"></button>
<button onclick="preProcessing()" id="btnPreProcessing" style="font-family:Open Sans Condensed;">Pre-process folders</button>
<br>
<span id="pFolderProgress"></span>
<br><br>
<button onclick="launchProgram()" id="btnLaunchProgram" style="font-family:Open Sans Condensed;">Scan pre-processed data</button>
<br> <span>Scans all pre-processed images for potential quarries. This may take some time.</span> <br><br><br>

</div>
</div>
<!-- ____END "Div container Process data"____ -->

<div class="flex-item columnx"><!-- Container 2 -->
<!-- ____START "Div container data management"____ -->
<!-- "Div container data management" Contains buttons for reseting, updating, and exporting data -->
<div class="flex-item columnx">
<h3>Manage Database</h3>
<br>
<button onclick="wipeDbAndMaps()" id="btnWipeDBAndMaps" style="font-family:Open Sans Condensed;">Reset data</button>
<button onclick="wipeDbAndMaps()" id="btnWipeDBAndMaps" style="font-family:Open Sans Condensed;">Reset data</button>
<br><span>Removes all pre-processed and scanned data.</span> <br><br>
<button onclick="openCSVFile()" id="btnOpenCSVFile" style="font-family:Open Sans Condensed;">Update known locations</button>
<br><span>Select a .CSV file with coordinates to all known locations. </span> <br><br>
<button onclick="openFolderCSV()" id="btnOpenFolderCSV" style="font-family:Open Sans Condensed;">Export new results</button>
<br><span>Export all new confirmed locations as a .CSV file</span> <br><br>

</div>
<div class="flex-item columnx"> <!-- Container 3 -->
<!-- ____END "Div container data management"____ -->

<!-- ____START "Div container Textarea"____ -->
<!-- "Div container Textarea" Contains the textarea for giving feedback to the user -->
<div class="flex-item columnx">
<br>
<textarea rows="21" cols="50" readonly id="textOutput"></textarea>
</div>
<!-- ____END "Div container Textarea"____ -->
</div>
<!-- ______________________________________END OF MAIN________________________________________ -->
<!-- ______________________________________END "MAIN PAGE"________________________________________ -->



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

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

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

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

<!-- All javascript file inclusions -->
<!-- All custom javascript file imports -->
<script src="js/launchEXE.js"></script>
<script src="js/navbar.js"></script>
<script src="js/updateDBSelectFile.js"></script>
Expand All @@ -117,5 +147,6 @@ <h3>Manage Database</h3>
<script src="js/moveFiles.js"></script>
<script src="js/xmlReader.js"></script>
<script src="js/resetDB.js"></script>
<!-- ______________________________________END "SCRIPT SECTION"________________________________________ -->
</body>
</html>
</html>
37 changes: 30 additions & 7 deletions application/userInterface/js/displayImage.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
//DISPLAYS IMAGE OF SELECTED POTENTIAL QUARRY
//Static imagePath to the ScannedMaps folder
var imagePath = "../scannedMaps/";
/*
Filename: userInterface/js/displayImage.js
@Author Group 13
Displays the image-file that is specified in the "imageName" parameter on ther result page
Globals:
imagePath - the path to the folder where the image-files are located
emptyImagePath - the path to the empty white image used when no image is available
*/
var imagePath = "../scannedMaps/"; // This file has to be located in the /scannedmaps folder, as specified in the "ImagePath" variable.
var emptyImagePath = "../userInterface/icons/white.jpg"
//Run this function when clicking on a marker/list item for a quarry. Insert correct imageName



/*
getCurrentImage
Displays the image in /scannedmaps that has the provided filename.
Inputs:
- Image filename
Outputs:
- Displays the specified image on the result page
Returns: None
*/
function getCurrentImage(imageName){
fullImagePath = imagePath + imageName;
if (imageName != ""){
document.getElementById('quarryImage').src=fullImagePath;
document.getElementById('quarryImage').src=fullImagePath; //Displays the image
}else{
document.getElementById('quarryImage').src = emptyImagePath;
document.getElementById('quarryImage').src = emptyImagePath; //Displays an empty white image, used when no image should be displayed
}

}
Loading

0 comments on commit 123e75b

Please sign in to comment.