Skip to content

Instantly share code, notes, and snippets.

@hawkeye64
Created August 27, 2018 19:10
Show Gist options
  • Save hawkeye64/0d50330deb2a6fedb46968fbe871fe81 to your computer and use it in GitHub Desktop.
Save hawkeye64/0d50330deb2a6fedb46968fbe871fe81 to your computer and use it in GitHub Desktop.
Extract Results Example
/**
* Extracts results from a network OutputBob
* @param {Object} outputBlob The outputBlob returned from net.forward()
* @param {Object} img The image used for classification
*/
const extractResultsCoco = (outputBlob, img) => {
return Array(outputBlob.rows).fill(0)
.map((res, i) => {
// get class index
const classIndex = outputBlob.at(i, 1);
const confidence = outputBlob.at(i, 2);
// output blobs are in a percentage
const bottomLeft = new cv.Point(
outputBlob.at(i, 3) * img.cols,
outputBlob.at(i, 6) * img.rows
);
const topRight = new cv.Point(
outputBlob.at(i, 5) * img.cols,
outputBlob.at(i, 4) * img.rows
);
// create a rect
const rect = new cv.Rect(
bottomLeft.x,
topRight.y,
topRight.x - bottomLeft.x,
bottomLeft.y - topRight.y
);
return ({
classIndex,
confidence,
rect
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment