
As shown in the image, I wrote the code to display the image and the bounding boxes by reading the annotations file.
enter image description here
this is the format for the annotation file
‘671 57 663 53 672 37 679 42 small-vehicle 0’
462 394 459 384 486 375 489 385 large-vehicle 0
696 483 713 519 610 546 595 510 tennis-court 0
677 440 692 476 591 504 575 469 tennis-court 0
498 502 528 493 536 515 507 525 swimming-pool 0
and then I store all the classes of the image (for eg: small-vehicle,swimming pool etc) in a set and display it on the top right of the webpage as shown in image.
Now I am interested only in vehicles so I want to display the bounding boxes of small-vehicles and large-vehicle with one color (lets say blue ) and all the other classes with another color (lets say yellow) and if I click on small-vehicles/large vehicles only the bounding boxes of those should be displayed and bounding boxes of other classes should be hidden and vice versa.
Someone suggested I use legend, but I don’t know how to start this with bounding boxes as I have seen only tutorials with line charts or is there any other better way?. If an example with a code for bounding boxes is shown.is shown that would be great
This is my first experience with javascript at all and I have to finish this task soon no matter what at work. Please help me. Thank you
…
async function fetchData(annotationpath, imagesource, template, width, height) {
await fetch(annotationpath)
.then(response => response.text())
.then(text => {
filecontent= text; //s contains the content of the file
console.log(filecontent);
var lines = this.filecontent.split(/rn|n/);
for (var line = 2; line < lines.length; line++) { //array to loop through each lines an
console.log(line + " --> " + lines[line]);
var annotationline = lines[line].split(' '),
x1 = annotationline[0],
y1 = annotationline[1],
x2 = annotationline[2],
y2 = annotationline[3],
x3 = annotationline[4],
y3 = annotationline[5],
x4 = annotationline[6],
y4 = annotationline[7],
classes = annotationline[8],
detected = annotationline[9];
classarray.push(classes);
//bounding boxes(bb)
var bb= d3.select(template).append("svg")
.attr("width", width)
.attr("height", height),
poly = [{
"x": x1,
"y": y1
},
{
"x": x2,
"y": y2
},
{
"x": x3,
"y": y3
},
{
"x": x4,
"y": y4
}
];
bb.selectAll("polygon")
.data([poly])
.enter().append("polygon")
.attr("points", function(d) {
return d.map(function(d) {
return [d.x, d.y].join(",");
}).join(" ");
})
.attr("stroke","red")
.attr("fill", "none");
}
console.log(classarray);
classarray.sort();
classset=new Set(classarray);
console.log(classset);
text = "";
classset.forEach (function(value) {
text += value + "<br>";
})
document.getElementById("classname").innerHTML = text;
classarray.length = 0;
})
}
}
…