-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin Van den Abeele
committed
Mar 3, 2021
1 parent
93d5387
commit a7b1cd7
Showing
6 changed files
with
75 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import {Detection, Detector, Loader} from "../motion/coco/loader"; | ||
import {Canvas, Image} from "canvas"; | ||
import {ImageUtils} from "../utils/image-utils"; | ||
|
||
const assert = require("assert"); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
export class DetectionIntegrationTest { | ||
|
||
constructor() { | ||
} | ||
|
||
public async run(): Promise<void> { | ||
console.log('Loader-detect-image-full-model-IT'); | ||
let modelLoader: Loader = new Loader(this.mockLogging()); | ||
let detector: Detector = await modelLoader.loadCoco(true); | ||
await this.verifyDetections(detector); | ||
|
||
console.log('Loader-detect-image-lite-model-IT'); | ||
modelLoader = new Loader(this.mockLogging()); | ||
detector = await modelLoader.loadCoco(); | ||
await this.verifyDetections(detector); | ||
} | ||
|
||
private async verifyDetections(detector: Detector): Promise<void> { | ||
assert(detector !== null); | ||
|
||
//This is needed to run on a machine which does not have a .homebridge folder! | ||
const homebridgeDir = require('os').homedir() + '/.homebridge'; | ||
ImageUtils.userStoragePath = homebridgeDir; | ||
if (!fs.existsSync(homebridgeDir)) { | ||
fs.mkdirSync(homebridgeDir); | ||
} | ||
|
||
let image: Image = await ImageUtils.createImage(path.resolve('../../resources/images/test.jpg')); | ||
assert(image !== null); | ||
|
||
let detections: Detection[] = await detector.detect(image, true); | ||
assert(detections !== null); | ||
assert(detections.length > 0); | ||
|
||
const annotatedImage: Canvas = await ImageUtils.generateAnnotatedImage(image, detections); | ||
const fileName: string = await ImageUtils.saveCanvasToFile(annotatedImage); | ||
let stats = fs.statSync(fileName); | ||
assert(stats.isFile() == true); | ||
|
||
fs.unlinkSync(fileName); | ||
}; | ||
|
||
private mockLogging(): any { | ||
return { | ||
info: ((message: string) => { | ||
console.log(message); | ||
}), | ||
debug: ((message: string) => { | ||
console.log(message); | ||
}) | ||
} | ||
} | ||
} | ||
|
||
(async () => { | ||
const test = new DetectionIntegrationTest(); | ||
await test.run(); | ||
})(); |
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.