From f837bbd22f13db7cc1099e7341b5d425ba77ea68 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 10 Nov 2023 10:53:06 -0500 Subject: [PATCH] some fixes --- .../Cameras/GetMask/GetCameraMaskHandler.cs | 5 +++ .../UpsertMask/UpsertCameraMaskHandler.cs | 14 +++++-- OpenAlprWebhookProcessor/Startup.cs | 2 + .../camera-mask/camera-mask.component.ts | 42 +++++++++++-------- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/OpenAlprWebhookProcessor/Cameras/GetMask/GetCameraMaskHandler.cs b/OpenAlprWebhookProcessor/Cameras/GetMask/GetCameraMaskHandler.cs index 29ed091e..d6af07cb 100644 --- a/OpenAlprWebhookProcessor/Cameras/GetMask/GetCameraMaskHandler.cs +++ b/OpenAlprWebhookProcessor/Cameras/GetMask/GetCameraMaskHandler.cs @@ -29,6 +29,11 @@ public async Task> GetCameraMaskAsync( .Select(x => x.Coordinates) .FirstOrDefaultAsync(cancellationToken); + if (maskCoordinates == null) + { + maskCoordinates = string.Empty; + } + return JsonSerializer.Deserialize>(maskCoordinates); } } diff --git a/OpenAlprWebhookProcessor/Cameras/UpsertMask/UpsertCameraMaskHandler.cs b/OpenAlprWebhookProcessor/Cameras/UpsertMask/UpsertCameraMaskHandler.cs index 1dde01ef..5a1b02e2 100644 --- a/OpenAlprWebhookProcessor/Cameras/UpsertMask/UpsertCameraMaskHandler.cs +++ b/OpenAlprWebhookProcessor/Cameras/UpsertMask/UpsertCameraMaskHandler.cs @@ -36,10 +36,18 @@ public async Task UpsertCameraMaskAsync( .Include(x => x.Mask) .FirstOrDefaultAsync(x => x.Id == cameraMask.CameraId, cancellationToken); - camera.Mask = new Data.CameraMask() + if (cameraMask.Coordinates.Any()) { - Coordinates = JsonSerializer.Serialize(cameraMask.Coordinates), - }; + camera.Mask = new CameraMask() + { + Coordinates = JsonSerializer.Serialize(cameraMask.Coordinates), + }; + } + else + { + camera.Mask = null; + } + var result = await _websocketClientOrganizer.UpsertCameraMaskAsync( agentUid, diff --git a/OpenAlprWebhookProcessor/Startup.cs b/OpenAlprWebhookProcessor/Startup.cs index 89a03a9a..01b4825b 100644 --- a/OpenAlprWebhookProcessor/Startup.cs +++ b/OpenAlprWebhookProcessor/Startup.cs @@ -181,6 +181,8 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/OpenAlprWebhookProcessor/angularapp/src/app/settings/cameras/edit-camera/camera-mask/camera-mask.component.ts b/OpenAlprWebhookProcessor/angularapp/src/app/settings/cameras/edit-camera/camera-mask/camera-mask.component.ts index db9b4fd9..47ea8a14 100644 --- a/OpenAlprWebhookProcessor/angularapp/src/app/settings/cameras/edit-camera/camera-mask/camera-mask.component.ts +++ b/OpenAlprWebhookProcessor/angularapp/src/app/settings/cameras/edit-camera/camera-mask/camera-mask.component.ts @@ -196,31 +196,37 @@ export class CameraMaskComponent implements OnInit { } public saveMask() { - this.savingCtx.drawImage(this.image, 0, 0, this.image.width, this.image.height); - this.savingCtx.fillStyle = 'white'; - this.savingCtx.fillRect(0, 0, this.image.width, this.image.height); + let cameraMask = new CameraMask(); + cameraMask.coordinates = []; + cameraMask.cameraId = this.camera.id; - this.savingCtx.beginPath(); - this.savingCtx.moveTo(this.coordinates[0].x * this.scaleFactor, this.coordinates[0].y * this.scaleFactor); + if (this.coordinates.length > 0) { + this.savingCtx.drawImage(this.image, 0, 0, this.image.width, this.image.height); + this.savingCtx.fillStyle = 'white'; + this.savingCtx.fillRect(0, 0, this.image.width, this.image.height); - for (let i = 1; i < this.coordinates.length; i++) { - this.savingCtx.lineTo(this.coordinates[i].x * this.scaleFactor, this.coordinates[i].y * this.scaleFactor); - } + this.savingCtx.beginPath(); + this.savingCtx.moveTo(this.coordinates[0].x * this.scaleFactor, this.coordinates[0].y * this.scaleFactor); - this.savingCtx.closePath(); - this.savingCtx.globalCompositeOperation = 'destination-out'; - this.savingCtx.fill(); - this.savingCtx.globalCompositeOperation = 'source-over'; + for (let i = 1; i < this.coordinates.length; i++) { + this.savingCtx.lineTo(this.coordinates[i].x * this.scaleFactor, this.coordinates[i].y * this.scaleFactor); + } - let cameraMask = new CameraMask(); - cameraMask.imageMask = this.savingCanvas.nativeElement.toDataURL('image/jpeg', 1.0); - cameraMask.cameraId = this.camera.id; - cameraMask.coordinates = []; + this.savingCtx.closePath(); + this.savingCtx.globalCompositeOperation = 'destination-out'; + this.savingCtx.fill(); + this.savingCtx.globalCompositeOperation = 'source-over'; + + for (let i = 0; i < this.coordinates.length; i++) { + cameraMask.coordinates.push({ x: this.coordinates[i].x * this.scaleFactor, y: this.coordinates[i].y * this.scaleFactor }); + } - for (let i = 0; i < this.coordinates.length; i++) { - cameraMask.coordinates.push({ x: this.coordinates[i].x * this.scaleFactor, y: this.coordinates[i].y * this.scaleFactor }); + cameraMask.imageMask = this.savingCanvas.nativeElement.toDataURL('image/jpeg', 1.0); } + cameraMask.imageMask = this.savingCanvas.nativeElement.toDataURL('image/jpeg', 1.0); + + this.cameraMaskService.upsertImageMask(cameraMask).subscribe(() => { this.snackbarService.create("Camera mask saved.", SnackBarType.Saved); },