Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mlapaglia committed Nov 10, 2023
1 parent 73ca31a commit f837bbd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public async Task<List<MaskCoordinate>> GetCameraMaskAsync(
.Select(x => x.Coordinates)
.FirstOrDefaultAsync(cancellationToken);

if (maskCoordinates == null)
{
maskCoordinates = string.Empty;
}

return JsonSerializer.Deserialize<List<MaskCoordinate>>(maskCoordinates);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ public async Task<bool> 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,
Expand Down
2 changes: 2 additions & 0 deletions OpenAlprWebhookProcessor/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ public void ConfigureServices(IServiceCollection services)
services.AddScoped<TriggerAutofocusHandler>();
services.AddScoped<UpsertCameraMaskHandler>();
services.AddScoped<GetCameraMaskHandler>();
services.AddScoped<DisableAgentRequestHandler>();
services.AddScoped<EnableAgentRequestHandler>();

services.AddScoped<UpsertWebPushClientRequestHandler>();
services.AddScoped<GetWebPushClientRequestHandler>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down

0 comments on commit f837bbd

Please sign in to comment.