|
@@ -53,6 +53,13 @@ function isSupportedImage(filename){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function inCacheFolder(filename){
|
|
|
+ if (filename.indexOf(".cache") >= 0){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
//Get all the image files exists in *:/Photo/*
|
|
|
function getAllImageFiles(){
|
|
|
var results = [];
|
|
@@ -62,7 +69,7 @@ function getAllImageFiles(){
|
|
|
var allFilesInThisPhotoRoot = filelib.walk(thisRootInfo[2]);
|
|
|
for ( var j = 0; j < allFilesInThisPhotoRoot.length; j++){
|
|
|
var thisFile = allFilesInThisPhotoRoot[j];
|
|
|
- if (!filelib.isDir(thisFile) && isSupportedImage(thisFile)){
|
|
|
+ if (!filelib.isDir(thisFile) && isSupportedImage(thisFile) && !inCacheFolder(thisFile)){
|
|
|
results.push(thisFile);
|
|
|
}
|
|
|
}
|
|
@@ -73,10 +80,11 @@ function getAllImageFiles(){
|
|
|
|
|
|
//Get the tag of a certain image file given its filepath
|
|
|
function getImageTags(imagefile){
|
|
|
- var results = imagelib.classify(imagefile, "darknet19");
|
|
|
+ var results = imagelib.classify(imagefile, "yolo3");
|
|
|
var tags = [];
|
|
|
for (var i = 0; i < results.length; i++){
|
|
|
- if (results[i].Percentage > 50){
|
|
|
+ console.log(results[i].Name, results[i].Percentage);
|
|
|
+ if (results[i].Percentage > 10){
|
|
|
//Confidence larger than 50
|
|
|
tags.push({
|
|
|
"object": results[i].Name,
|
|
@@ -97,7 +105,7 @@ function getImageTagsRecord(imagefile){
|
|
|
}
|
|
|
|
|
|
function loadAllTagsRecord(rootID){
|
|
|
- var tagFile = rootID + ":/Photo/tags.json"
|
|
|
+ var tagFile = rootID + "Photo/tags.json"
|
|
|
if (filelib.fileExists(tagFile)){
|
|
|
var tagsData = filelib.readFile(tagFile)
|
|
|
return JSON.parse(tagsData);
|
|
@@ -106,7 +114,7 @@ function loadAllTagsRecord(rootID){
|
|
|
}
|
|
|
|
|
|
function saveAllTagsRecords(rootID, tagRecords){
|
|
|
- var tagFile = rootID + ":/Photo/tags.json"
|
|
|
+ var tagFile = rootID + "Photo/tags.json"
|
|
|
return filelib.writeFile(tagFile, JSON.stringify(tagRecords))
|
|
|
}
|
|
|
|
|
@@ -126,3 +134,43 @@ function matchAndClearNonExistsRecords(tagRecords){
|
|
|
return cleanedTagRecords;
|
|
|
}
|
|
|
|
|
|
+//Translate the record array into keyvalue paris of [filepath](record object)
|
|
|
+function summarizeAndRestructureFilepaths(tagRecords){
|
|
|
+ var filepathMap = {};
|
|
|
+ for ( var i = 0; i < tagRecords.length; i++){
|
|
|
+ var thisRecord = tagRecords[i];
|
|
|
+ filepathMap[thisRecord.filepath] = JSON.parse(JSON.stringify(thisRecord));
|
|
|
+ }
|
|
|
+ return filepathMap;
|
|
|
+}
|
|
|
+
|
|
|
+//Translate the tag array into key-value pairs of [tag](filepath)
|
|
|
+function summarizeAndrestructureTags(tagRecords){
|
|
|
+ var tags = {};
|
|
|
+ for ( var i = 0; i < tagRecords.length; i++){
|
|
|
+ var thisRecord = tagRecords[i];
|
|
|
+ for ( var j = 0; j < thisRecord.tags.length; j++){
|
|
|
+ var thisTag = thisRecord.tags[j];
|
|
|
+ if (typeof(tags[thisTag.object]) == "undefined"){
|
|
|
+ //Not exists. Create it
|
|
|
+ tags[thisTag.object] = [thisRecord.filepath];
|
|
|
+ }else{
|
|
|
+ //Already exists. Remove duplicate
|
|
|
+ var alreadyExists = false;
|
|
|
+ for ( var k = 0; k < tags[thisTag.object].length; k++){
|
|
|
+ if (tags[thisTag.object][k] == thisRecord.filepath){
|
|
|
+ alreadyExists = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!alreadyExists){
|
|
|
+ tags[thisTag.object].push(thisRecord.filepath);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return tags;
|
|
|
+}
|