Fix structure box errors (#82)

Closes: #80

Closes: #81

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>

Reviewed-on: Georgi_Lab/ALVINN_f7#82
This commit is contained in:
2024-01-27 17:12:58 -07:00
parent 39975ec35b
commit 09cb078f63

View File

@@ -357,23 +357,13 @@
} }
xhr.send() xhr.send()
} }
window.onresize = (e) => { this.selectChip('redraw') }
}, },
computed: { computed: {
showResults () { showResults () {
var filteredResults = this.resultData.detections var filteredResults = this.resultData.detections
if (!filteredResults) return [] if (!filteredResults) return []
const imCanvas = this.$refs.image_cvs
var imgWidth
var imgHeight
const imgAspect = this.imageView.width / this.imageView.height
const rendAspect = imCanvas.width / imCanvas.height
if (imgAspect >= rendAspect) {
imgWidth = imCanvas.width
imgHeight = imCanvas.width / imgAspect
} else {
imgWidth = imCanvas.height * imgAspect
imgHeight = imCanvas.height
}
var allSelect = this.detectorLabels.every( s => { return s.detect } ) var allSelect = this.detectorLabels.every( s => { return s.detect } )
var selectedLabels = this.detectorLabels var selectedLabels = this.detectorLabels
.filter( l => { return l.detect }) .filter( l => { return l.detect })
@@ -382,10 +372,6 @@
filteredResults[i].resultIndex = i filteredResults[i].resultIndex = i
filteredResults[i].aboveThreshold = d.confidence >= this.detectorLevel filteredResults[i].aboveThreshold = d.confidence >= this.detectorLevel
filteredResults[i].isSearched = allSelect || selectedLabels.includes(d.label) filteredResults[i].isSearched = allSelect || selectedLabels.includes(d.label)
filteredResults[i].cvsLeft = (imCanvas.width - imgWidth) / 2 + filteredResults[i].left * imgWidth
filteredResults[i].cvsRight = (imCanvas.width - imgWidth) / 2 + filteredResults[i].right * imgWidth
filteredResults[i].cvsTop = (imCanvas.height - imgHeight) / 2 + filteredResults[i].top * imgHeight
filteredResults[i].cvsBottom = (imCanvas.height - imgHeight) / 2 + filteredResults[i].bottom * imgHeight
}) })
return filteredResults return filteredResults
}, },
@@ -470,10 +456,17 @@
return return
} }
var boxLeft = this.resultData.detections[iChip].cvsLeft if (iChip == 'redraw') {
var boxTop = this.resultData.detections[iChip].cvsTop if (this.selectedChip == -1) return
var boxWidth = this.resultData.detections[iChip].cvsRight - this.resultData.detections[iChip].cvsLeft iChip = this.selectedChip
var boxHeight = this.resultData.detections[iChip].cvsBottom - this.resultData.detections[iChip].cvsTop }
const boxCoords = this.box2cvs(this.resultData.detections[iChip])[0]
var boxLeft = boxCoords.cvsLeft
var boxTop = boxCoords.cvsTop
var boxWidth = boxCoords.cvsRight - boxCoords.cvsLeft
var boxHeight = boxCoords.cvsBottom - boxCoords.cvsTop
imageCtx.strokeRect(boxLeft,boxTop,boxWidth,boxHeight) imageCtx.strokeRect(boxLeft,boxTop,boxWidth,boxHeight)
this.selectedChip = iChip this.selectedChip = iChip
this.resultData.detections[iChip].beenViewed = true this.resultData.detections[iChip].beenViewed = true
@@ -540,13 +533,42 @@
this.detectorLevel = value this.detectorLevel = value
}, },
structureClick(e) { structureClick(e) {
var findBox = this.showResults.find( r => { return r.cvsLeft <= e.offsetX && const boxCoords = this.box2cvs(this.showResults)
var findBox = boxCoords.findIndex( (r, i) => { return r.cvsLeft <= e.offsetX &&
r.cvsRight >= e.offsetX && r.cvsRight >= e.offsetX &&
r.cvsTop <= e.offsetY && r.cvsTop <= e.offsetY &&
r.cvsBottom >= e.offsetY && r.cvsBottom >= e.offsetY &&
r.resultIndex > this.selectedChip this.resultData.detections[i].resultIndex > this.selectedChip &&
this.resultData.detections[i].aboveThreshold &&
this.resultData.detections[i].isSearched &&
!this.resultData.detections[i].isDeleted
}) })
this.selectChip(findBox ? findBox.resultIndex : this.selectedChip) this.selectChip(findBox >= 0 ? this.resultData.detections[findBox].resultIndex : this.selectedChip)
},
box2cvs(boxInput) {
if (!boxInput) return []
const boxList = boxInput.length ? boxInput : [boxInput]
const [imCanvas, imageCtx] = this.resetView()
var imgWidth
var imgHeight
const imgAspect = this.imageView.width / this.imageView.height
const rendAspect = imCanvas.width / imCanvas.height
if (imgAspect >= rendAspect) {
imgWidth = imCanvas.width
imgHeight = imCanvas.width / imgAspect
} else {
imgWidth = imCanvas.height * imgAspect
imgHeight = imCanvas.height
}
const cvsCoords = boxList.map( (d, i) => {
return {
"cvsLeft": (imCanvas.width - imgWidth) / 2 + d.left * imgWidth,
"cvsRight": (imCanvas.width - imgWidth) / 2 + d.right * imgWidth,
"cvsTop": (imCanvas.height - imgHeight) / 2 + d.top * imgHeight,
"cvsBottom": (imCanvas.height - imgHeight) / 2 + d.bottom * imgHeight
}
})
return cvsCoords
} }
} }
} }