Skip to content

Commit

Permalink
Merge pull request #41 from euquiq/main
Browse files Browse the repository at this point in the history
Added LabelBelowBox and AlternativeLabelling settings
  • Loading branch information
djdd87 authored Jul 25, 2021
2 parents fce3866 + 5b4658c commit 7f561ed
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 143 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

SynoAI.sln

# User-specific files
*.rsuser
*.suo
Expand Down
4 changes: 2 additions & 2 deletions SynoAI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SynoAI", "SynoAI\SynoAI.csproj", "{D55517BF-4185-4B3D-956F-9CCE6425D88B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SynoAI.Tests", "SynoAI.Tests\SynoAI.Tests.csproj", "{C3A70D73-D1DD-46E4-882E-34CA833BE3EF}"
EndProject
#Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SynoAI.Tests", "SynoAI.Tests\SynoAI.Tests.csproj", "{C3A70D73-D1DD-46E4-882E-34CA833BE3EF}"
#EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
8 changes: 3 additions & 5 deletions SynoAI/AIs/DeepStack/DeepStackAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;

namespace SynoAI.AIs.DeepStack
{
public class DeepStackAI : AI
{
private const string URL_VISION_DETECTION = "v1/vision/detection";

public async override Task<IEnumerable<AIPrediction>> Process(ILogger logger, Camera camera, byte[] image)
{
using (HttpClient client = new HttpClient())
Expand All @@ -36,13 +33,14 @@ public async override Task<IEnumerable<AIPrediction>> Process(ILogger logger, Ca

logger.LogDebug($"{camera.Name}: DeepStackAI: Sending image.");

HttpResponseMessage response = await client.PostAsync(URL_VISION_DETECTION, multipartContent);
HttpResponseMessage response = await client.PostAsync(Config.AIPath, multipartContent);
if (response.IsSuccessStatusCode)
{
DeepStackResponse deepStackResponse = await GetResponse(response);
if (deepStackResponse.Success)
{
IEnumerable<AIPrediction> predictions = deepStackResponse.Predictions.Where(x=> x.Confidence >= minConfidence).Select(x => new AIPrediction()

IEnumerable<AIPrediction> predictions = deepStackResponse.Predictions.Where(x=> x.Confidence >= minConfidence).Select(x => new AIPrediction()
{
Confidence = x.Confidence * 100,
Label = x.Label,
Expand Down
36 changes: 24 additions & 12 deletions SynoAI/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
using SynoAI.AIs;
using SynoAI.Models;
using SynoAI.Notifiers;
using SynoAI.Notifiers.Pushbullet;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Threading.Tasks;

namespace SynoAI
{
Expand Down Expand Up @@ -51,12 +47,6 @@ public static class Config
/// 2 = Low bandwidth
/// </summary>
public static CameraQuality Quality { get; private set; }

/// <summary>
/// The amount of time that needs to have passed between the last call to check the camera and the current call.
/// </summary>
public static int Delay { get; private set; }

/// <summary>
/// The hex code of the colour to use for the boxing around image matches.
/// </summary>
Expand All @@ -83,6 +73,19 @@ public static class Config
/// </summary>
public static int TextOffsetY { get; private set; }
/// <summary>
/// True will only place a reference number on each label image, later detailing object type and confidence percentage on the notification text
/// </summary>
public static bool AlternativeLabelling { get; private set; }
/// <summary>
/// True will place each image label below the boundary box.
/// </summary>
public static bool LabelBelowBox { get; private set; }
/// <summary>
/// <summary>
/// Upon movement, the maximum number of snapshots sequentially retrieved from SSS until finding an object of interest (i.e. 4 snapshots)
/// </summary>
public static int MaxSnapshots { get; private set; }
/// <summary>
/// Whether this original snapshot generated from the API should be saved to the file system.
/// </summary>
public static bool SaveOriginalSnapshot { get; private set; }
Expand All @@ -92,6 +95,7 @@ public static class Config
/// </summary>
public static AIType AI { get; private set; }
public static string AIUrl { get; private set; }
public static string AIPath { get; private set; }
public static int MinSizeX { get; private set; }
public static int MinSizeY { get; private set; }

Expand Down Expand Up @@ -131,8 +135,7 @@ public static void Generate(ILogger logger, IConfiguration configuration)
ApiVersionCamera = configuration.GetValue<int>("ApiVersionCamera", 9); // Surveillance Station 8.0

Quality = configuration.GetValue<CameraQuality>("Quality", CameraQuality.Balanced);

Delay = configuration.GetValue<int>("Delay", 5000);

DrawMode = configuration.GetValue<DrawMode>("DrawMode", DrawMode.Matches);

BoxColor = configuration.GetValue<string>("BoxColor", SKColors.Red.ToString());
Expand All @@ -147,11 +150,20 @@ public static void Generate(ILogger logger, IConfiguration configuration)
MinSizeX = configuration.GetValue<int>("MinSizeX", 50);
MinSizeY = configuration.GetValue<int>("MinSizeY", 50);

LabelBelowBox = configuration.GetValue<bool>("LabelBelowBox", false);
AlternativeLabelling = configuration.GetValue<bool>("AlternativeLabelling", false);
MaxSnapshots = configuration.GetValue<int>("MaxSnapshots", 1);
if (MaxSnapshots > 254) {
MaxSnapshots = 254;
logger.LogWarning("ATTENTION: Config parameter MaxSnapshots is too big: Maximum accepted value is 254 ");
}

SaveOriginalSnapshot = configuration.GetValue<bool>("SaveOriginalSnapshot", false);

IConfigurationSection aiSection = configuration.GetSection("AI");
AI = aiSection.GetValue<AIType>("Type", AIType.DeepStack);
AIUrl = aiSection.GetValue<string>("Url");
AIPath = aiSection.GetValue<string>("Path","v1/vision/detection");

Cameras = GenerateCameras(logger, configuration);
Notifiers = GenerateNotifiers(logger, configuration);
Expand Down
Loading

0 comments on commit 7f561ed

Please sign in to comment.