Advertisement
TerryTZ

Untitled

May 27th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var angle = 0;
  2.  
  3. function setup() {
  4.   createCanvas(400, 400);
  5. }
  6.  
  7. function draw() {
  8.   background(255);
  9.   noFill();
  10.  
  11.   rect(200, 200, 55, 100);
  12.   ellipse(255, 200, 80);
  13.  
  14.   // Calculate target box coordinate
  15.   x = 180;
  16.   w = 255 - 40 * sin(angle) - 180;
  17.   y = 200 + 40 * cos(angle);
  18.   h = 310 - y;
  19.   rect(x, y, w, h);
  20.  
  21.   // Calculate IoU
  22.   xmin_max = max(200, x);
  23.   xmin_min = min(200, x);
  24.   xmax_min = min(255, x+w);
  25.   xmax_max = max(255, x+w);
  26.   ymin_max = max(200, y);
  27.   ymin_min = min(200, y);
  28.   ymax_min = min(300, y+h);
  29.   ymax_max = max(300, y+h);
  30.   iou = ((xmax_min - xmin_max) * (ymax_min - ymin_max)) / (w * h + 55 * 100 - (xmax_min - xmin_max) * (ymax_min - ymin_max))
  31.   iou = iou.toFixed(2)
  32.   textSize(32);
  33.   fill(0, 102, 153);
  34.   text('iou = ' + str(iou), 50, 150);
  35.  
  36.   // Update angle
  37.   if (angle >= (2 * PI)) {
  38.     angle = 0;
  39.   } else {
  40.     angle += (PI / 200);
  41.   }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement