Comparing version 1.0.7 to 1.0.8
@@ -32,2 +32,29 @@ 'use strict'; | ||
function polygonToSvgPath(polygon, left, top) { | ||
// M 10,10 L 100,10 100,100 z M 30,20 L 70,20 70,60 z | ||
var path_strings = []; | ||
for (var part of polygon) { | ||
if (part.length < 2) { | ||
continue; | ||
} | ||
path_strings.push('M'); | ||
var first = true; | ||
for (var point of part) { | ||
path_strings.push((point[0]-left) + "," + (point[1]-top)); | ||
if (isNaN(point[0]) || isNaN(point[1])) { | ||
console.log('not showing invalid polygon, found NaN'); | ||
return ""; | ||
} | ||
if (first) { | ||
path_strings.push('L'); | ||
first = false; | ||
} | ||
} | ||
path_strings.push('z'); | ||
} | ||
return path_strings.join(" "); | ||
} | ||
/* | ||
@@ -214,8 +241,78 @@ | ||
bbox.style.position = 'absolute'; | ||
bbox.style.left = annotation.bounding_box[0] + 'px'; | ||
bbox.style.top = annotation.bounding_box[1] + 'px'; | ||
bbox.style.width = annotation.bounding_box[2] + 'px'; | ||
bbox.style.height = annotation.bounding_box[3] + 'px'; | ||
var left; | ||
var top; | ||
var width; | ||
var height; | ||
var color = WAD_COLORS[i++ % WAD_COLORS.length]; | ||
bbox.style.border = '2px solid ' + color; | ||
if(annotation.mask_vertices){ | ||
var minx = null; | ||
var miny = null; | ||
var maxx = null; | ||
var maxy = null; | ||
for(var part of annotation.mask_vertices){ | ||
for(var point of part){ | ||
var x = point[0]; | ||
var y = point[1]; | ||
if(minx === null || x < minx){ | ||
minx = x; | ||
} | ||
if(miny === null || y < miny){ | ||
miny = y; | ||
} | ||
if(maxx === null || x > maxx){ | ||
maxx = x; | ||
} | ||
if(maxy === null || y > maxy){ | ||
maxy = y; | ||
} | ||
} | ||
} | ||
width = maxx - minx; | ||
height = maxy - miny; | ||
left = minx; | ||
top = miny; | ||
var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); | ||
svg.style.position = 'absolute'; | ||
svg.style.overflow = 'visible'; | ||
svg.style.width = width + 'px'; | ||
svg.style.height = height + 'px'; | ||
var path = document.createElementNS('http://www.w3.org/2000/svg',"path"); | ||
path.setAttributeNS(null, "d", polygonToSvgPath(annotation.mask_vertices, left, top)); | ||
path.style.fill = 'none'; | ||
path.style.stroke = color; | ||
path.style.strokeWidth = 'calc(var(--fontscale) / 75)'; | ||
svg.appendChild(path); | ||
bbox.appendChild(svg); | ||
bbox.style.border = 'none'; | ||
}else if(annotation.bounding_box){ | ||
left = annotation.bounding_box[0]; | ||
top = annotation.bounding_box[1]; | ||
width = annotation.bounding_box[2]; | ||
height = annotation.bounding_box[3]; | ||
bbox.style.border = '2px solid ' + color; | ||
}else { | ||
throw new Exception('Neither mask_vertices or bounding_box is passed, unknown annotation format'); | ||
} | ||
bbox.style.left = left + 'px'; | ||
bbox.style.top = top + 'px'; | ||
bbox.style.width = width + 'px'; | ||
bbox.style.height = height + 'px'; | ||
bbox_container.appendChild(bbox); | ||
@@ -228,2 +325,3 @@ var bbox_label = document.createElement('boundingboxlabel'); | ||
bbox_label.style.fontSize = 'var(--fontscale)'; | ||
bbox_label.style.position = 'absolute'; | ||
bbox.appendChild(bbox_label); | ||
@@ -341,9 +439,35 @@ } | ||
caption = detection[visualizer_data.label_key]; // non demographic mode | ||
if(caption && caption.constructor === String) | ||
{ | ||
//It's a string | ||
}else{ | ||
// some other type of object | ||
var keys = Object.keys(caption); | ||
if(keys.length == 1){ | ||
caption = caption[keys[0]]; // get the only property | ||
}else{ | ||
caption = JSON.stringify(caption); | ||
} | ||
} | ||
} | ||
detection.bounding_box[0] *= scale_applied; | ||
detection.bounding_box[1] *= scale_applied; | ||
detection.bounding_box[2] *= scale_applied; | ||
detection.bounding_box[3] *= scale_applied; | ||
if (detection.bounding_box){ | ||
detection.bounding_box[0] *= scale_applied; | ||
detection.bounding_box[1] *= scale_applied; | ||
detection.bounding_box[2] *= scale_applied; | ||
detection.bounding_box[3] *= scale_applied; | ||
} | ||
if (detection.mask_vertices){ | ||
for(var part of detection.mask_vertices){ | ||
for(var point of part){ | ||
point[0] *= scale_applied; | ||
point[1] *= scale_applied; | ||
} | ||
} | ||
} | ||
processed_annotations.push({ | ||
bounding_box: detection.bounding_box, | ||
mask_vertices: detection.mask_vertices, | ||
caption: caption | ||
@@ -350,0 +474,0 @@ }); |
{ | ||
"name": "deepai", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"license": "BSD-2-Clause", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1936662
13032