/* Aroz Photo Image Classification Script Generate classification for the given image path Paramters: ws (Optional), upgrade this connection to websocket for realtime progress viewing */ requirelib("filelib"); requirelib("imagelib"); requirelib("websocket"); includes("imagedb.js"); function returnError(msg){ sendJSONResp(JSON.stringify({"error": msg})); } function init(){ newDBTableIfNotExists("photo"); } function main(){ var roots = getAllPossibleRoots(); for (var i = 0; i < roots.length; i++){ var thisVroot = roots[i][1]; //Load all tags record for this vroot var tagsRecords = loadAllTagsRecord(thisVroot); //Clear up all images tags that no longer exists tagsRecords = matchAndClearNonExistsRecords(tagsRecords); //Convert it to a path:value keypair var filepathMap = summarizeAndRestructureFilepaths(tagsRecords); //sendResp(JSON.stringify(filepathMap)); //Scan for new images that is not classified and add them to the root tag file var allValidImagesInThisDir = getAllImageFiles(); var websocketMode = false; if (typeof(ws) != "undefined"){ websocketMode = true; websocket.upgrade(10); delay(100); } var counter = 1; for ( var i = 0; i < allValidImagesInThisDir.length; i++){ var thisImageFile = allValidImagesInThisDir[i]; //Check if this filepath is already been classified. if (typeof(filepathMap[thisImageFile]) == "undefined"){ //Not found in cache. New photo! console.log("[Photo] Analysising photo with neuralnet: " + thisImageFile); var thisImageTagRecord = getImageTagsRecord(thisImageFile); if (websocketMode){ websocket.send(JSON.stringify(thisImageFile)); } //Push it into the record tagsRecords.push(thisImageTagRecord); counter++; } if (counter%5 == 0){ //Auto save every 5 photos console.log("[Photo] Auto saved") saveAllTagsRecords(thisVroot, tagsRecords); } } //Final save saveAllTagsRecords(thisVroot, tagsRecords); } console.log("[Photo] Automatic tag generation - Done") websocket.close(); sendResp("OK"); } init(); main();