(canvas, trueBoundingBox, predictBoundingBox)
| 40 | const PREDICT_BOUNDING_BOX_STYLE = 'rgb(0,0,255)'; |
| 41 | |
| 42 | function drawBoundingBoxes(canvas, trueBoundingBox, predictBoundingBox) { |
| 43 | tf.util.assert( |
| 44 | trueBoundingBox != null && trueBoundingBox.length === 4, |
| 45 | `Expected boundingBoxArray to have length 4, ` + |
| 46 | `but got ${trueBoundingBox} instead`); |
| 47 | tf.util.assert( |
| 48 | predictBoundingBox != null && predictBoundingBox.length === 4, |
| 49 | `Expected boundingBoxArray to have length 4, ` + |
| 50 | `but got ${trueBoundingBox} instead`); |
| 51 | |
| 52 | let left = trueBoundingBox[0]; |
| 53 | let right = trueBoundingBox[1]; |
| 54 | let top = trueBoundingBox[2]; |
| 55 | let bottom = trueBoundingBox[3]; |
| 56 | |
| 57 | const ctx = canvas.getContext('2d'); |
| 58 | ctx.beginPath(); |
| 59 | ctx.strokeStyle = TRUE_BOUNDING_BOX_STYLE; |
| 60 | ctx.lineWidth = TRUE_BOUNDING_BOX_LINE_WIDTH; |
| 61 | ctx.moveTo(left, top); |
| 62 | ctx.lineTo(right, top); |
| 63 | ctx.lineTo(right, bottom); |
| 64 | ctx.lineTo(left, bottom); |
| 65 | ctx.lineTo(left, top); |
| 66 | ctx.stroke(); |
| 67 | |
| 68 | ctx.font = '15px Arial'; |
| 69 | ctx.fillStyle = TRUE_BOUNDING_BOX_STYLE; |
| 70 | ctx.fillText('true', left, top); |
| 71 | |
| 72 | left = predictBoundingBox[0]; |
| 73 | right = predictBoundingBox[1]; |
| 74 | top = predictBoundingBox[2]; |
| 75 | bottom = predictBoundingBox[3]; |
| 76 | |
| 77 | ctx.beginPath(); |
| 78 | ctx.strokeStyle = PREDICT_BOUNDING_BOX_STYLE; |
| 79 | ctx.lineWidth = PREDICT_BOUNDING_BOX_LINE_WIDTH; |
| 80 | ctx.moveTo(left, top); |
| 81 | ctx.lineTo(right, top); |
| 82 | ctx.lineTo(right, bottom); |
| 83 | ctx.lineTo(left, bottom); |
| 84 | ctx.lineTo(left, top); |
| 85 | ctx.stroke(); |
| 86 | |
| 87 | ctx.font = '15px Arial'; |
| 88 | ctx.fillStyle = PREDICT_BOUNDING_BOX_STYLE; |
| 89 | ctx.fillText('predicted', left, bottom); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Synthesize an input image, run inference on it and visualize the results. |
no outgoing calls
no test coverage detected