diff --git a/src/app/navi/services/scanner.service.ts b/src/app/navi/services/scanner.service.ts index 62d24de..51a1717 100644 --- a/src/app/navi/services/scanner.service.ts +++ b/src/app/navi/services/scanner.service.ts @@ -11,35 +11,34 @@ import { TileDatabaseService } from './tile-database.service'; providedIn: 'root', }) export class ScannerService { - private classifier?: DonjaraTileScanner; + private classifier: DonjaraTileScanner = new DonjaraTileScanner(); constructor(private tileDatabaseService: TileDatabaseService) {} async initialize() { - this.classifier = new DonjaraTileScanner({ + await this.classifier.initialize({ modelBaseUrl: environment.modelBaseUrl, }); - await this.classifier.initialize(); } public getCameraPreviewStream() { - return this.classifier!.getPreviewMediaStream(); + return this.classifier.getPreviewMediaStream(); } public get onScanned$() { - return this.classifier!.onScanned$; + return this.classifier.onScanned$; } public get onDetectionStatusChanged$() { - return this.classifier!.onDetectionStatusChanged$; + return this.classifier.onDetectionStatusChanged$; } async onVideoFrame(videoElement: HTMLVideoElement) { - await this.classifier!.onVideoFrame(videoElement); + await this.classifier.onVideoFrame(videoElement); } async detect() { - return this.classifier!.detect(); + return this.classifier.detect(); } async getCgTilesByScannerResult( diff --git a/src/app/shared/classes/donjara-tile-scanner/donjara-tile-scanner.ts b/src/app/shared/classes/donjara-tile-scanner/donjara-tile-scanner.ts index 79b3eb5..fd91853 100644 --- a/src/app/shared/classes/donjara-tile-scanner/donjara-tile-scanner.ts +++ b/src/app/shared/classes/donjara-tile-scanner/donjara-tile-scanner.ts @@ -50,7 +50,13 @@ export class DonjaraTileScanner { // パイの表面領域の分類器 private tileClassifier!: TileClassifier; - constructor(params: { modelBaseUrl: string }) { + constructor() {} + + async initialize(params: { modelBaseUrl: string }) { + if (this.previewCanvas) { + return; + } + this.tileDetector = new TileDetector({ modelBaseUrl: params.modelBaseUrl, }); @@ -58,12 +64,6 @@ export class DonjaraTileScanner { this.tileClassifier = new TileClassifier({ modelBaseUrl: params.modelBaseUrl, }); - } - - async initialize() { - if (this.previewCanvas) { - return; - } // プレビュー映像生成用キャンバスを初期化 this.previewCanvas = document.createElement('canvas');