12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- /*
- Aroz Photo
- Image Classification Script
- Generate classification for the given image path
- Require Data:
- imagepath (string)
- */
- requirelib("filelib");
- requirelib("imagelib");
- includes("imagedb.js");
- function returnError(msg){
- sendJSONResp(JSON.stringify({"error": msg}));
- }
- function main(){
- //Check if the imagepath exists
- if (!filelib.fileExists(imagepath)){
- returnError("file not exists");
- return
- }
- //Check if it is a supported image format
- var fileExt = imagepath.split(".").pop();
- if (fileExt == "jpg" || fileExt == "png" || fileExt == "jpeg"){
- //Get image classification, will take a bit time
- var results = imagelib.classify(imagepath, "darknet19");
- var responses = [];
- for (var i = 0; i < results.length; i++){
- responses.push({
- "object": results[i].Name,
- "confidence": results[i].Percentage,
- "position_x": results[i].Positions[0],
- "position_y": results[i].Positions[1],
- "width": results[i].Positions[2],
- "height": results[i].Positions[3]
- });
- }
- sendJSONResp(JSON.stringify(responses));
- }else{
- //Not supported format
- returnError("format not supported");
- return
- }
-
- }
- main();
|