Created
August 27, 2018 18:57
-
-
Save hawkeye64/dd34783430c7cefa1906e58949cf2275 to your computer and use it in GitHub Desktop.
opencv4nodejs Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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