image.classify.js 882 B

1234567891011121314151617181920212223242526
  1. requirelib("http");
  2. requirelib("imagelib");
  3. function main(){
  4. //Download stock image for testing from
  5. //https://cdn.pixabay.com/photo/2017/03/28/12/10/chairs-2181947_960_720.jpg
  6. http.download("https://cdn.pixabay.com/photo/2017/03/28/12/10/chairs-2181947_960_720.jpg", "tmp:/", "classify.jpg");
  7. //Get image classification, will take a bit time
  8. var results = imagelib.classify("tmp:/classify.jpg", "yolo3");
  9. var responses = [];
  10. for (var i = 0; i < results.length; i++){
  11. responses.push({
  12. "object": results[i].Name,
  13. "confidence": results[i].Percentage,
  14. "position_x": results[i].Positions[0],
  15. "position_y": results[i].Positions[1],
  16. "width": results[i].Positions[2],
  17. "height": results[i].Positions[3]
  18. });
  19. }
  20. sendJSONResp(JSON.stringify(responses));
  21. }
  22. main();