Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. let imageFile = 'images/beer.jpg'; //画像ファイル名
  2. let classifier; //画像分類器
  3. let img; //画像
  4. let status = ''; //表示テキスト
  5.  
  6. function preload() {
  7. //モデルを読み込み
  8. classifier = ml5.imageClassifier('MobileNet');
  9. //画像を読み込み
  10. img = loadImage(imageFile);
  11. }
  12.  
  13. function setup() {
  14. //p5jsキャンバス生成
  15. createCanvas(windowWidth, windowHeight);
  16. //画像の分類開始
  17. classifier.classify(img, gotResult);
  18. status = '画像分類中...';
  19. }
  20.  
  21. function draw() {
  22. //画像を表示
  23. image(img, 0, 0, width, height);
  24. //分析結果をテキストで表示
  25. fill(255, 255, 127);
  26. textSize(18);
  27. text(status, 20, 30);
  28. }
  29.  
  30. // 解析結果の出力
  31. function gotResult(err, results) {
  32. // エラー処理
  33. if (err) {
  34. console.error(err);
  35. status = err;
  36. }
  37. // 結果を出力
  38. status =
  39. 'ラベル: ' + results[0].label
  40. + ', 確度: ' + results[0].confidence + '\n';
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement