Skip to content

Instantly share code, notes, and snippets.

@hawkeye64
Created August 27, 2018 18:57
Show Gist options
  • Save hawkeye64/dd34783430c7cefa1906e58949cf2275 to your computer and use it in GitHub Desktop.
Save hawkeye64/dd34783430c7cefa1906e58949cf2275 to your computer and use it in GitHub Desktop.
opencv4nodejs Example
// OpenCV
const cv = require('opencv4nodejs')
// initialize model from prototxt and modelFile
let net
if (dataFile === 'coco300' || dataFile === 'coco512') {
net = cv.readNetFromCaffe(prototxt, modelFile)
}
// read the image
const img = cv.imread(imagePath)
// starting time of classification
let start = new Date()
// get predictions
const predictions = predict(img).filter((item) => {
// filter out what we don't want
if (item.confidence < confidence) {
return false
}
// user wants to filter items
if (filterItems.length > 0) {
if (filterItems.indexOf(classes[item.classIndex]) < 0) {
return false
}
}
return true
})
// end of classification
let end = new Date()
finalize(start, end)
// write updated image with new name
updateImage(imagePath, img, predictions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment