-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
353 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
export default { | ||
zhCN: { | ||
_tabbar: { | ||
image: '图像', | ||
image: '图片', | ||
video: '视频', | ||
webcam: '摄像' | ||
}, | ||
image: '图像', | ||
image: '图片', | ||
video: '视频', | ||
webcam: '摄像' | ||
webcam: '摄像', | ||
'Open Image': '打开图片' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
[ | ||
"person", | ||
"bicycle", | ||
"car", | ||
"motorcycle", | ||
"airplane", | ||
"bus", | ||
"train", | ||
"truck", | ||
"boat", | ||
"traffic light", | ||
"fire hydrant", | ||
"stop sign", | ||
"parking meter", | ||
"bench", | ||
"bird", | ||
"cat", | ||
"dog", | ||
"horse", | ||
"sheep", | ||
"cow", | ||
"elephant", | ||
"bear", | ||
"zebra", | ||
"giraffe", | ||
"backpack", | ||
"umbrella", | ||
"handbag", | ||
"tie", | ||
"suitcase", | ||
"frisbee", | ||
"skis", | ||
"snowboard", | ||
"sports ball", | ||
"kite", | ||
"baseball bat", | ||
"baseball glove", | ||
"skateboard", | ||
"surfboard", | ||
"tennis racket", | ||
"bottle", | ||
"wine glass", | ||
"cup", | ||
"fork", | ||
"knife", | ||
"spoon", | ||
"bowl", | ||
"banana", | ||
"apple", | ||
"sandwich", | ||
"orange", | ||
"broccoli", | ||
"carrot", | ||
"hot dog", | ||
"pizza", | ||
"donut", | ||
"cake", | ||
"chair", | ||
"couch", | ||
"potted plant", | ||
"bed", | ||
"dining table", | ||
"toilet", | ||
"tv", | ||
"laptop", | ||
"mouse", | ||
"remote", | ||
"keyboard", | ||
"cell phone", | ||
"microwave", | ||
"oven", | ||
"toaster", | ||
"sink", | ||
"refrigerator", | ||
"book", | ||
"clock", | ||
"vase", | ||
"scissors", | ||
"teddy bear", | ||
"hair drier", | ||
"toothbrush" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import labels from './labels.json' | ||
|
||
/** | ||
* Render prediction boxes | ||
* @param {HTMLCanvasElement} canvasRef canvas tag reference | ||
* @param {Array} boxes_data boxes array | ||
* @param {Array} scores_data scores array | ||
* @param {Array} classes_data class array | ||
* @param {Array[Number]} ratios boxes ratio [xRatio, yRatio] | ||
*/ | ||
export function renderBoxes( | ||
canvasRef: HTMLCanvasElement, | ||
boxes_data: Float32Array | Int32Array | Uint8Array, | ||
scores_data: Float32Array | Int32Array | Uint8Array, | ||
classes_data: Float32Array | Int32Array | Uint8Array, | ||
ratios: any[] | ||
) { | ||
const ctx = canvasRef.getContext('2d') | ||
if (ctx) { | ||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height) // clean canvas | ||
|
||
const colors = new Colors() | ||
|
||
// font configs | ||
const font = `${Math.max(Math.round(Math.max(ctx.canvas.width, ctx.canvas.height) / 40), 14)}px Arial` | ||
ctx.font = font | ||
ctx.textBaseline = 'top' | ||
|
||
for (let i = 0; i < scores_data.length; ++i) { | ||
// filter based on class threshold | ||
const klass = labels[classes_data[i]] | ||
const color = colors.get(classes_data[i]) | ||
const score = (scores_data[i] * 100).toFixed(1) | ||
|
||
let [y1, x1, y2, x2] = boxes_data.slice(i * 4, (i + 1) * 4) | ||
x1 *= ratios[0] | ||
x2 *= ratios[0] | ||
y1 *= ratios[1] | ||
y2 *= ratios[1] | ||
const width = x2 - x1 | ||
const height = y2 - y1 | ||
|
||
// draw box. | ||
ctx.fillStyle = Colors.hexToRgba(color, 0.2)! | ||
ctx.fillRect(x1, y1, width, height) | ||
|
||
// draw border box. | ||
ctx.strokeStyle = color | ||
ctx.lineWidth = Math.max(Math.min(ctx.canvas.width, ctx.canvas.height) / 200, 2.5) | ||
ctx.strokeRect(x1, y1, width, height) | ||
|
||
// Draw the label background. | ||
ctx.fillStyle = color | ||
const textWidth = ctx.measureText(`${klass} - ${score}%`).width | ||
const textHeight = parseInt(font, 10) // base 10 | ||
const yText = y1 - (textHeight + ctx.lineWidth) | ||
ctx.fillRect( | ||
x1 - 1, | ||
yText < 0 ? 0 : yText, // handle overflow label box | ||
textWidth + ctx.lineWidth, | ||
textHeight + ctx.lineWidth | ||
) | ||
|
||
// Draw labels | ||
ctx.fillStyle = '#ffffff' | ||
ctx.fillText(`${klass} - ${score}%`, x1 - 1, yText < 0 ? 0 : yText) | ||
} | ||
} | ||
} | ||
|
||
class Colors { | ||
palette: string[] | ||
n: number | ||
// ultralytics color palette https://ultralytics.com/ | ||
constructor() { | ||
this.palette = [ | ||
'#FF3838', | ||
'#FF9D97', | ||
'#FF701F', | ||
'#FFB21D', | ||
'#CFD231', | ||
'#48F90A', | ||
'#92CC17', | ||
'#3DDB86', | ||
'#1A9334', | ||
'#00D4BB', | ||
'#2C99A8', | ||
'#00C2FF', | ||
'#344593', | ||
'#6473FF', | ||
'#0018EC', | ||
'#8438FF', | ||
'#520085', | ||
'#CB38FF', | ||
'#FF95C8', | ||
'#FF37C7' | ||
] | ||
this.n = this.palette.length | ||
} | ||
|
||
get = (i: number) => this.palette[Math.floor(i) % this.n] | ||
|
||
static hexToRgba = (hex: string, alpha: number) => { | ||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) | ||
return result ? `rgba(${[parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)].join(', ')}, ${alpha})` : null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.