Skip to content

Commit

Permalink
Updated Version to 4.0. Using Sqlite instead of SQL Server. Added go …
Browse files Browse the repository at this point in the history
…to Date/Time. Fix Date/Time between cameras. Added multiple log levels, and changed code to respect these levels. Test Pictures can now be sent to specific cameras. Menus have been reorganized. Application Settings removed SQL connection string since no longer using SQL Server. Bug Fixes
  • Loading branch information
Ken98045 committed Jul 4, 2022
1 parent 7131920 commit 74fe7f0
Show file tree
Hide file tree
Showing 60 changed files with 2,224 additions and 1,849 deletions.
Binary file modified DBNewMotionFrames.mdf
Binary file not shown.
Binary file modified DBNewMotionFrames_log.ldf
Binary file not shown.
12 changes: 7 additions & 5 deletions OnGuardCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<DisableWinExeOutputInference>true</DisableWinExeOutputInference>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<Version>3.1.0</Version>
<Version>4.0.0</Version>
<AssemblyName>OnGuard</AssemblyName>
<Platforms>AnyCPU;x64</Platforms>
<Configurations>Debug;Release;xsx</Configurations>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<AssemblyVersion>3.1.0</AssemblyVersion>
<FileVersion>3.1.0</FileVersion>
<AssemblyVersion>4.0.0</AssemblyVersion>
<FileVersion>4.0.0</FileVersion>
<Copyright>Ken Koch</Copyright>
</PropertyGroup>

Expand Down Expand Up @@ -41,7 +41,6 @@
<None Remove="Resources\HelpFiles\PTZMovementHelp.rtf" />
<None Remove="Resources\HelpFiles\SnapshotMethodHelp.rtf" />
<None Remove="Resources\HelpFiles\SnapshotResolutionHelp.rtf" />
<None Remove="Resources\HelpFiles\SQLConnectionHelp.rtf" />
<None Remove="Resources\OnGuard.jpg" />
<None Remove="Src\Resources\Samples\Street1.jpg" />
</ItemGroup>
Expand All @@ -62,16 +61,19 @@
<EmbeddedResource Include="Resources\HelpFiles\PTZMovementHelp.rtf" />
<EmbeddedResource Include="Resources\HelpFiles\SnapshotMethodHelp.rtf" />
<EmbeddedResource Include="Resources\HelpFiles\SnapshotResolutionHelp.rtf" />
<EmbeddedResource Include="Resources\HelpFiles\SQLConnectionHelp.rtf" />
<EmbeddedResource Include="Resources\OnGuard.jpg" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.6" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="17.0.63" />
<PackageReference Include="Mictlanix.DotNet.OnvifClient" Version="0.0.3" />
<PackageReference Include="MQTTnet" Version="3.0.16" />
<PackageReference Include="SolarCalculator" Version="3.0.6" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
<PackageReference Include="System.Management" Version="7.0.0-preview.4.22229.4" />
</ItemGroup>

<ItemGroup>
Expand Down
907 changes: 0 additions & 907 deletions Resources/HelpFiles/SQLConnectionHelp.rtf

This file was deleted.

60 changes: 4 additions & 56 deletions Setup/Setup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
"SccProvider" = "8:"
"Hierarchy"
{
"Entry"
{
"MsmKey" = "8:_253015C3B4DC4DB69638C7537BD046A6"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_44719A92832243089A2B13176AF820AB"
Expand All @@ -31,12 +25,6 @@
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_9102E02584F847C88F6272AFE30F2AA3"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
}
"Configurations"
{
Expand Down Expand Up @@ -149,26 +137,6 @@
}
"File"
{
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_253015C3B4DC4DB69638C7537BD046A6"
{
"SourcePath" = "8:..\\DBNewMotionFrames.mdf"
"TargetName" = "8:DBNewMotionFrames.mdf"
"Tag" = "8:"
"Folder" = "8:_C4C594B07A7C4E75B1FB8A3678AA3A34"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_44719A92832243089A2B13176AF820AB"
{
"SourcePath" = "8:..\\docs\\OnGuard-ReadMe.docx"
Expand All @@ -189,26 +157,6 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_9102E02584F847C88F6272AFE30F2AA3"
{
"SourcePath" = "8:..\\DBNewMotionFrames_log.ldf"
"TargetName" = "8:DBNewMotionFrames_log.ldf"
"Tag" = "8:"
"Folder" = "8:_C4C594B07A7C4E75B1FB8A3678AA3A34"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
}
"FileType"
{
Expand Down Expand Up @@ -297,16 +245,16 @@
"Product"
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:OnGuard"
"ProductCode" = "8:{2E0D2EEB-B4DC-4369-8186-D9AC9E40216A}"
"PackageCode" = "8:{AAC8BE25-23EC-45FC-A315-A3AFEE774AAE}"
"ProductName" = "8:On Guard"
"ProductCode" = "8:{2921D75A-A444-4711-86EA-B181ADF64D94}"
"PackageCode" = "8:{0BD79C1E-783A-4478-AA02-1F36807D597F}"
"UpgradeCode" = "8:{D3BCA8E0-0468-46F2-B474-C2AF858BCFFC}"
"AspNetVersion" = "8:4.0.30319.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:3.1.1"
"ProductVersion" = "8:4.0.0"
"Manufacturer" = "8:OnGuard"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down
Binary file modified docs/OnGuard-ReadMe.docx
Binary file not shown.
16 changes: 8 additions & 8 deletions src/AI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static bool RestartAI(bool ignoreRestartTime, bool forceStart)
lock (s_lock)
{

Dbg.Write("AILocation - Atttempting to restart the AI");
Dbg.Write(LogLevel.Warning, "AILocation - Atttempting to restart the AI");

TimeSpan timeSinceRestart = DateTime.Now - s_timeOfLastRestart;
if (ignoreRestartTime || timeSinceRestart.TotalMinutes > 1)
Expand All @@ -135,7 +135,7 @@ public static bool RestartAI(bool ignoreRestartTime, bool forceStart)
// Note that with the current (9/1/21) DeepStack there can be only one
foreach (var process in Process.GetProcessesByName("deepstack"))
{
Dbg.Write("AILocation - Restart AI - Killing off the existing AI");
Dbg.Write(LogLevel.Warning, "AILocation - Restart AI - Killing off the existing AI");
process.Kill(true);
Thread.Sleep(1000);
break;
Expand Down Expand Up @@ -169,7 +169,7 @@ public static bool RestartAI(bool ignoreRestartTime, bool forceStart)
// At this point we will assume that we have a fresh copy of the AI that is good to go!
s_AIDead = false;
AIStateChange(true);
Dbg.Write("AILocation - RestartAI - The restart was successful!");
Dbg.Write(LogLevel.Info, "AILocation - RestartAI - The restart was successful!");
s_timeLastSuccess = DateTime.Now;

if ((s_maxInstances - s_semaphore.CurrentCount) > 0)
Expand All @@ -187,19 +187,19 @@ public static bool RestartAI(bool ignoreRestartTime, bool forceStart)
}
else
{
Dbg.Write("AILocation - RestartAI - The DeepStack process started and then stopped!");
Dbg.Write(LogLevel.Error, "AILocation - RestartAI - The DeepStack process started and then stopped!");
}
}
}
else
{
Dbg.Write("AILocation - Restart AI - The current settings do not allow for an AI restart");
Dbg.Write(LogLevel.Warning, "AILocation - Restart AI - The current settings do not allow for an AI restart");
s_timeOfLastRestart = DateTime.Now;
}
}
else
{
Dbg.Trace("AILocation - RestartAI - We are attempting to restart the AI too frequently");
Dbg.Write(LogLevel.Warning, "AILocation - RestartAI - We are attempting to restart the AI too frequently");
}
}

Expand Down Expand Up @@ -253,7 +253,7 @@ public static void StopAI()
{
foreach (var process in Process.GetProcessesByName("deepstack"))
{
Dbg.Write("AILocation - StopAI - Killing off the existing AI");
Dbg.Write(LogLevel.Warning, "AILocation - StopAI - Killing off the existing AI");
process.Kill(true);
Thread.Sleep(1000);
break;
Expand All @@ -265,7 +265,7 @@ public static async Task<HttpResponseMessage> PostAIRequestAsync(HttpClient clie

HttpResponseMessage output = null;
bool waitResult;
url = string.Format("http://{0}:{1}/{2}", IPAddress, Port, url);
url = $"http://{IPAddress}:{Port}/{url}";

if (IsAIDead())
{
Expand Down
36 changes: 18 additions & 18 deletions src/AIAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public AIAnalyzer()
lock (_fileLock)
{
SortedDictionary<string, PictureInfo> dateSortedList = new ();
string fileSearch = string.Format("{0}*.jpg", cameraNamePrefix);
string fileSearch = $"{cameraNamePrefix}*.jpg";

string[] files;
if (subDirectories)
Expand Down Expand Up @@ -140,7 +140,7 @@ public static void RemoveItemsOfNoInterest(CameraData camera, List<InterestingOb

if (!addedOne)
{
Dbg.Trace("AIAnalyzer - RemoveItemsOfNoInterest - Camera: " + camera.CameraPrefix + " - Weeded out: " + io.Label);
Dbg.Write(LogLevel.DetailedInfo, "AIAnalyzer - RemoveItemsOfNoInterest - Camera: " + camera.CameraPrefix + " - Weeded out: " + io.Label);
}
}

Expand Down Expand Up @@ -220,10 +220,10 @@ public static void RemoveDuplicateVehiclesInImage(List<InterestingObject> object
vehicles[i].Confidence = 0.9999; // this number is below 1 and is magic in the sense that it can be recognized by the user
}

Dbg.Trace("Boosting vehicle confidence from: " + beforeConfidence.ToString() + " After: " + vehicles[i].Confidence.ToString());
Dbg.Write(LogLevel.DetailedInfo, "Boosting vehicle confidence from: " + beforeConfidence.ToString() + " After: " + vehicles[i].Confidence.ToString());
}

Dbg.Trace("Removing duplicate vehicle (1) " + vehicles[j].Label);
Dbg.Write(LogLevel.DetailedInfo, "Removing duplicate vehicle (1) " + vehicles[j].Label);
// Since there was an overlap, remove the lower confidence vehicle
objectList.RemoveAll(obj => obj.ID == vehicles[j].ID); // and remove it from the passed list
vehicles.RemoveAt(j);
Expand All @@ -240,9 +240,9 @@ public static void RemoveDuplicateVehiclesInImage(List<InterestingObject> object
vehicles[j].Confidence = 0.9999; // this number is below 1 and is magic in the sense that it can be recognized by the user
}

Dbg.Trace("Boosting vehicle confidence from: " + beforeConfidence.ToString() + " After: " + vehicles[j].Confidence.ToString());
Dbg.Write(LogLevel.DetailedInfo, "Boosting vehicle confidence from: " + beforeConfidence.ToString() + " After: " + vehicles[j].Confidence.ToString());

Dbg.Trace("Removing duplicate vehicle (2): " + vehicles[i].Label);
Dbg.Write(LogLevel.DetailedInfo, "Removing duplicate vehicle (2): " + vehicles[i].Label);
objectList.RemoveAll(obj => obj.ID == vehicles[i].ID); // and remove it from the passed list
vehicles.RemoveAt(i); // We only do the vehicle once.
removedOne = true;
Expand All @@ -264,7 +264,7 @@ public static void RemoveDuplicateVehiclesInImage(List<InterestingObject> object
}
}

Dbg.Trace("Objects after duplicate vehicle check: " + objectList.Count.ToString());
Dbg.Write(LogLevel.DetailedInfo, "Objects after duplicate vehicle check: " + objectList.Count.ToString());
}

// I am assuming that if there are people then there is motion.
Expand All @@ -291,7 +291,7 @@ static List<InterestingObject> GetPeople(List<InterestingObject> InterestingObje

void RemoveUnmovedVehicles(CameraData camera, List<InterestingObject> objectList)
{
Dbg.Trace("Object count before removing parked: " + objectList.Count.ToString());
Dbg.Write(LogLevel.DetailedInfo, "Object count before removing parked: " + objectList.Count.ToString());

List<InterestingObject> vehicles = new ();
int nonVehicleObjects = 0;
Expand Down Expand Up @@ -347,7 +347,7 @@ void RemoveUnmovedVehicles(CameraData camera, List<InterestingObject> objectList
double previousScreenWidthPercent = Math.Round((100.0 * _previousVehicles[j].ObjectRectangle.Width) / BitmapResolution.XResolution, 1, MidpointRounding.AwayFromZero);
double previousScreenHeightPercent = Math.Round((100.0 * _previousVehicles[j].ObjectRectangle.Height) / BitmapResolution.YResolution, 1, MidpointRounding.AwayFromZero);

Dbg.Trace("Vehicle found parked using area overlap - Previous: " +
Dbg.Write(LogLevel.DetailedInfo, "Vehicle found parked using area overlap - Previous: " +
"X: " + _previousVehicles[j].ObjectRectangle.X.ToString() +
" Y: " + _previousVehicles[j].ObjectRectangle.Y.ToString() +
" Width: " + previousScreenWidthPercent.ToString() +
Expand All @@ -358,7 +358,7 @@ void RemoveUnmovedVehicles(CameraData camera, List<InterestingObject> objectList
double currentScreenWidthPercent = Math.Round((100.0 * vehicles[i].ObjectRectangle.Width) / BitmapResolution.XResolution, 1, MidpointRounding.AwayFromZero);
double currentScreenHeightPercent = Math.Round((100.0 * vehicles[i].ObjectRectangle.Height) / BitmapResolution.YResolution, 1, MidpointRounding.AwayFromZero);

Dbg.Trace("Vehicle found parked using area overlap - Current: " +
Dbg.Write(LogLevel.DetailedInfo, "Vehicle found parked using area overlap - Current: " +
"X: " + vehicles[i].ObjectRectangle.X.ToString() +
" Y: " + vehicles[i].ObjectRectangle.Y.ToString() +
" Width: " + currentScreenWidthPercent.ToString() +
Expand Down Expand Up @@ -397,14 +397,14 @@ void RemoveUnmovedVehicles(CameraData camera, List<InterestingObject> objectList
{
if (ulDistance < targetSize || lrDistance < targetSize)
{
Dbg.Trace("Parked Target Size: " + targetSize.ToString());
Dbg.Trace("Parked ULDistance: " + ulDistance.ToString());
Dbg.Trace("Parked LRDistance: " + lrDistance.ToString());
Dbg.Write(LogLevel.Verbose, "Parked Target Size: " + targetSize.ToString());
Dbg.Write(LogLevel.Verbose, "Parked ULDistance: " + ulDistance.ToString());
Dbg.Write(LogLevel.Verbose, "Parked LRDistance: " + lrDistance.ToString());

double previousScreenWidthPercent = Math.Round((100.0 * _previousVehicles[j].ObjectRectangle.Width) / BitmapResolution.XResolution, 1, MidpointRounding.AwayFromZero);
double previousScreenHeightPercent = Math.Round((100.0 * _previousVehicles[j].ObjectRectangle.Height) / BitmapResolution.YResolution, 1, MidpointRounding.AwayFromZero);

Dbg.Trace("Vehicle found parked using Corners - Previous: " +
Dbg.Write(LogLevel.Verbose, "Vehicle found parked using Corners - Previous: " +
"X: " + _previousVehicles[j].ObjectRectangle.X.ToString() +
" Y: " + _previousVehicles[j].ObjectRectangle.Y.ToString() +
" Width: " + previousScreenWidthPercent.ToString() +
Expand All @@ -414,7 +414,7 @@ void RemoveUnmovedVehicles(CameraData camera, List<InterestingObject> objectList
double currentScreenWidthPercent = Math.Round((100.0 * vehicles[i].ObjectRectangle.Width) / BitmapResolution.XResolution, 1, MidpointRounding.AwayFromZero);
double currentScreenHeightPercent = Math.Round((100.0 * vehicles[i].ObjectRectangle.Height) / BitmapResolution.YResolution, 1, MidpointRounding.AwayFromZero);

Dbg.Trace("Vehicle found parked using Corners - Current: " +
Dbg.Write(LogLevel.DetailedInfo, "Vehicle found parked using Corners - Current: " +
"X: " + vehicles[i].ObjectRectangle.X.ToString() +
" Y: " + vehicles[i].ObjectRectangle.Y.ToString() +
" Width: " + currentScreenWidthPercent.ToString() +
Expand All @@ -432,7 +432,7 @@ void RemoveUnmovedVehicles(CameraData camera, List<InterestingObject> objectList
// We add which ever has the highest confidence level to the result;

objectList.RemoveAll(obj => obj.ID == vehicles[i].ID); // and remove it from the passed list
Dbg.Trace("Removing parked vehicle: " + vehicles[i].Label);
Dbg.Write(LogLevel.DetailedInfo, "Removing parked vehicle: " + vehicles[i].Label);
vehicles.RemoveAt(i); // we are done with this vehicle
removedOne = true;
break;
Expand All @@ -458,11 +458,11 @@ void RemoveUnmovedVehicles(CameraData camera, List<InterestingObject> objectList
}
catch (Exception ex)
{
Dbg.Write("AIAnalyzer - RemoveUnmovedVehicles - Exception caught: " + ex.Message);
Dbg.Write(LogLevel.Error, "AIAnalyzer - RemoveUnmovedVehicles - Exception caught: " + ex.Message);
}
}

Dbg.Trace("Total objects after parked vehicle check: " + objectList.Count.ToString() + " Vehicles remaining: " + vehicles.Count.ToString());
Dbg.Write(LogLevel.DetailedInfo, "Total objects after parked vehicle check: " + objectList.Count.ToString() + " Vehicles remaining: " + vehicles.Count.ToString());
}

public static double GetPointDistance(Point p1, Point p2)
Expand Down

0 comments on commit 74fe7f0

Please sign in to comment.