Update msg pack

This commit is contained in:
drastiq 2020-06-20 14:00:42 +02:00
parent 06d459d2db
commit 2ba1f47010
11 changed files with 90 additions and 76 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR.Client; using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.DependencyInjection;
namespace squirrowse.client namespace squirrowse.client
{ {
@ -16,6 +17,7 @@ namespace squirrowse.client
_connection = new HubConnectionBuilder() _connection = new HubConnectionBuilder()
.WithUrl($"{url}:{port}/hub") .WithUrl($"{url}:{port}/hub")
.WithAutomaticReconnect() .WithAutomaticReconnect()
.AddMessagePackProtocol()
.Build(); .Build();
} }

View File

@ -6,8 +6,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.2" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="3.1.2" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.2" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.2" />
<PackageReference Include="OpenCvSharp4" Version="4.2.0.20200208" /> <PackageReference Include="OpenCvSharp4" Version="4.2.0.20200208" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.2.0.20200208" /> <PackageReference Include="OpenCvSharp4.runtime.win" Version="4.2.0.20200208" />

View File

@ -6,6 +6,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="LiteDB" Version="5.0.3" /> <PackageReference Include="LiteDB" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.5" />
<PackageReference Include="Microsoft.Azure.CognitiveServices.Vision.ComputerVision" Version="6.0.0-dev.20190919.3" /> <PackageReference Include="Microsoft.Azure.CognitiveServices.Vision.ComputerVision" Version="6.0.0-dev.20190919.3" />
<PackageReference Include="OpenCvSharp4" Version="4.2.0.20200208" /> <PackageReference Include="OpenCvSharp4" Version="4.2.0.20200208" />
<PackageReference Include="OpenCvSharp4.runtime.ubuntu.18.04-x64" Version="4.2.0.20200208" /> <PackageReference Include="OpenCvSharp4.runtime.ubuntu.18.04-x64" Version="4.2.0.20200208" />

View File

@ -7,6 +7,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.3.0" /> <PackageReference Include="Azure.Storage.Blobs" Version="12.3.0" />
<PackageReference Include="LiteDB" Version="5.0.3" /> <PackageReference Include="LiteDB" Version="5.0.3" />
<PackageReference Include="OpenCvSharp4.runtime.ubuntu.18.04-x64" Version="4.2.0.20200208" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -21,13 +21,13 @@ namespace squirrowse.web.Data
public class Detection : IDetection public class Detection : IDetection
{ {
private readonly CascadeClassifier CascadeFace = new CascadeClassifier( private readonly CascadeClassifier CascadeFace = new CascadeClassifier(
@".\StaticFiles\haarcascade_frontalface_alt.xml"); @"./StaticFiles/haarcascade_frontalface_alt.xml");
private readonly CascadeClassifier CascadeLowerBody = new CascadeClassifier( private readonly CascadeClassifier CascadeLowerBody = new CascadeClassifier(
@".\StaticFiles\haarcascade_lowerbody.xml"); @"./StaticFiles/haarcascade_lowerbody.xml");
private readonly CascadeClassifier CascadeUpperBody = new CascadeClassifier( private readonly CascadeClassifier CascadeUpperBody = new CascadeClassifier(
@".\StaticFiles\haarcascade_upperbody.xml"); @"./StaticFiles/haarcascade_upperbody.xml");
public Mat DetectTypes(Mat frame, Filters filter) public Mat DetectTypes(Mat frame, Filters filter)
{ {

View File

@ -9,7 +9,7 @@ namespace squirrowse.web.Data
{ {
public class VideoQ public class VideoQ
{ {
public ConcurrentFixedSizeQueue<byte[]> _framebuffer = new ConcurrentFixedSizeQueue<byte[]>(255); public ConcurrentFixedSizeQueue<byte[]> _framebuffer = new ConcurrentFixedSizeQueue<byte[]>(33);
public Mat getFrame() public Mat getFrame()
{ {

View File

@ -8,9 +8,9 @@
<h1>live</h1> <h1>live</h1>
<img src="@_imgSrc"/> <img src="@_imgSrc" />
<img src="@_tempcogni"/> <img src="@_tempcogni" />
<div style="padding-top: 10px"> <div style="padding-top: 10px">
<button id="Save" class="btn btn-success btn-sm" @onclick="() => GetDataFromAzure()"> <button id="Save" class="btn btn-success btn-sm" @onclick="() => GetDataFromAzure()">
@ -24,7 +24,7 @@
<li class="list-group-item d-flex justify-content-between" style="background-color: transparent; color: inherit;"> <li class="list-group-item d-flex justify-content-between" style="background-color: transparent; color: inherit;">
<DxCheckBox CheckType="CheckType.Switch" LabelPosition="@LabelPosition.Left" style="width: 100%" Checked="@fetchDataFromAzure" CheckedChanged="@Update(v => fetchDataFromAzure = v)">Fetch Data from azure</DxCheckBox> <DxCheckBox CheckType="CheckType.Switch" LabelPosition="@LabelPosition.Left" style="width: 100%" Checked="@fetchDataFromAzure" CheckedChanged="@Update(v => fetchDataFromAzure = v)">Fetch Data from azure</DxCheckBox>
</li> </li>
@*<li class="list-group-item d-flex justify-content-between" style="background-color: transparent; color: inherit;"> <li class="list-group-item d-flex justify-content-between" style="background-color: transparent; color: inherit;">
<DxCheckBox CheckType="CheckType.Switch" LabelPosition="@LabelPosition.Left" style="width: 100%" Checked="@filter.Face" CheckedChanged="@Update(v => filter.Face = v)">Face</DxCheckBox> <DxCheckBox CheckType="CheckType.Switch" LabelPosition="@LabelPosition.Left" style="width: 100%" Checked="@filter.Face" CheckedChanged="@Update(v => filter.Face = v)">Face</DxCheckBox>
</li> </li>
<li class="list-group-item d-flex justify-content-between" style="background-color: transparent; color: inherit;"> <li class="list-group-item d-flex justify-content-between" style="background-color: transparent; color: inherit;">
@ -32,81 +32,79 @@
</li> </li>
<li class="list-group-item d-flex justify-content-between" style="background-color: transparent; color: inherit;"> <li class="list-group-item d-flex justify-content-between" style="background-color: transparent; color: inherit;">
<DxCheckBox CheckType="CheckType.Switch" LabelPosition="@LabelPosition.Left" style="width: 100%" Checked="@filter.LowerBody" CheckedChanged="@Update(v => filter.LowerBody = v)">Lower Body</DxCheckBox> <DxCheckBox CheckType="CheckType.Switch" LabelPosition="@LabelPosition.Left" style="width: 100%" Checked="@filter.LowerBody" CheckedChanged="@Update(v => filter.LowerBody = v)">Lower Body</DxCheckBox>
</li>*@ </li>
</ul> </ul>
</div> </div>
@inject SaveVideo save @inject SaveVideo save
@inject IAzureCV azureCv @inject IAzureCV azureCv
@inject VideoQ Video @inject VideoQ Video
@inject Detection detect
@code { @code { private readonly Filters filter = new Filters(false, false, false);
// private readonly Filters filter = new Filters(false, false, false); private string _imgSrc;
private string _imgSrc; private string _tempcogni;
private string _tempcogni; private byte[] buffer;
private byte[] buffer; private bool fetchDataFromAzure = true;
private bool fetchDataFromAzure = true;
private readonly Frame Frametest = new Frame(); private readonly Frame Frametest = new Frame();
private Mat tempory = new Mat(); private Mat tempory = new Mat();
public Action<bool> Update(Action<bool> set) public Action<bool> Update(Action<bool> set)
{
return v =>
{
set(v);
InvokeAsync(StateHasChanged);
};
}
protected override async Task OnInitializedAsync()
{
using var temp = new Mat(480, 640, MatType.CV_8UC3, new Scalar(0, 0, 100));
Cv2.PutText(temp, "No clients".ToUpper(),
new Point(240, 320),
HersheyFonts.HersheyComplex, 0.9f, Scalar.Yellow);
var base64T = Convert.ToBase64String(temp.ToBytes());
while (true)
{
try
{ {
using var frame = Video.getFrame(); return v =>
tempory = Frametest.CopyMat(frame); {
// var face = detect.DetectTypes(frame, filter); set(v);
buffer = frame.ToBytes(); InvokeAsync(StateHasChanged);
var base64 = Convert.ToBase64String(buffer); };
_imgSrc = $"data:image/gif;base64,{base64}";
Cv2.WaitKey(1);
await Task.Delay(1000 / 33);
StateHasChanged();
} }
catch (Exception e)
protected override async Task OnInitializedAsync()
{ {
_imgSrc = $"data:image/gif;base64,{base64T}"; using var temp = new Mat(480, 640, MatType.CV_8UC3, new Scalar(0, 0, 100));
await Task.Delay(1000 / 33);
Cv2.PutText(temp, "No clients".ToUpper(),
new Point(240, 320),
HersheyFonts.HersheyComplex, 0.9f, Scalar.Yellow);
var base64T = Convert.ToBase64String(temp.ToBytes());
while (true)
{
try
{
using var frame = Video.getFrame();
tempory = Frametest.CopyMat(frame);
var face = detect.DetectTypes(frame, filter);
buffer = face.ToBytes();
var base64 = Convert.ToBase64String(buffer);
_imgSrc = $"data:image/gif;base64,{base64}";
Cv2.WaitKey(1);
await Task.Delay(1000 / 33);
StateHasChanged();
}
catch (Exception e)
{
_imgSrc = $"data:image/gif;base64,{base64T}";
await Task.Delay(1000 / 33);
StateHasChanged();
}
}
StateHasChanged();
} }
}
}
private async Task GetDataFromAzure() private async Task GetDataFromAzure()
{ {
while (fetchDataFromAzure) while (fetchDataFromAzure)
{ {
var azrespons = await azureCv.GetObjects(tempory); var azrespons = await azureCv.GetObjects(tempory);
var azureFrame = azureCv.DrawResults(tempory, azrespons); var azureFrame = azureCv.DrawResults(tempory, azrespons);
var b_tempcogni = Convert.ToBase64String(azureFrame.Result.ToBytes()); var b_tempcogni = Convert.ToBase64String(azureFrame.Result.ToBytes());
_tempcogni = $"data:image/gif;base64,{b_tempcogni}"; _tempcogni = $"data:image/gif;base64,{b_tempcogni}";
await Task.Delay(TimeSpan.FromSeconds(5)); await Task.Delay(TimeSpan.FromSeconds(5));
StateHasChanged(); StateHasChanged();
} }
} } }
}

View File

@ -3,7 +3,7 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://10.230.115.112:80", "applicationUrl": "http://192.168.0.13:8000",
"sslPort": 443 "sslPort": 443
} }
}, },
@ -22,7 +22,7 @@
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
}, },
"applicationUrl": "http://10.230.115.112:80" "applicationUrl": "http://192.168.0.13:8000"
}, },
"Docker": { "Docker": {
"commandName": "Docker", "commandName": "Docker",

View File

@ -32,13 +32,13 @@ namespace squirrowse.web
}); });
services.AddSingleton<SaveVideo>(); services.AddSingleton<SaveVideo>();
//services.AddSingleton<Detection>(); services.AddSingleton<Detection>();
services.AddSingleton<IAzureCV, AzureCV>(); services.AddSingleton<IAzureCV, AzureCV>();
services.AddSingleton<DbContext>(); services.AddSingleton<DbContext>();
services.AddSingleton<GaleryService>(); services.AddSingleton<GaleryService>();
services.AddSingleton<Bloob>(); services.AddSingleton<Bloob>();
services.AddSingleton<VideoQ>(); services.AddSingleton<VideoQ>();
services.AddSignalR(x => x.MaximumReceiveMessageSize = ((int)(int.MaxValue / 2))); services.AddSignalR(x => x.MaximumReceiveMessageSize = ((int)(int.MaxValue / 2))).AddMessagePackProtocol();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

Binary file not shown.

View File

@ -9,6 +9,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="CNTK.Deps.OpenCV.Zip" Version="2.8.0-rc0.dev20200201" /> <PackageReference Include="CNTK.Deps.OpenCV.Zip" Version="2.8.0-rc0.dev20200201" />
<PackageReference Include="DevExpress.Blazor" Version="19.2.4-preview" /> <PackageReference Include="DevExpress.Blazor" Version="19.2.4-preview" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.5" />
<PackageReference Include="Microsoft.Azure.CognitiveServices.Vision.ComputerVision" Version="6.0.0-dev.20190919.3" /> <PackageReference Include="Microsoft.Azure.CognitiveServices.Vision.ComputerVision" Version="6.0.0-dev.20190919.3" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
<PackageReference Include="OpenCvSharp4" Version="4.2.0.20200208" /> <PackageReference Include="OpenCvSharp4" Version="4.2.0.20200208" />
@ -24,6 +27,12 @@
<None Update="StaticFiles\haarcascade_frontalface_alt.xml"> <None Update="StaticFiles\haarcascade_frontalface_alt.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<None Update="StaticFiles\haarcascade_lowerbody.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="StaticFiles\haarcascade_upperbody.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<ProjectExtensions> <ProjectExtensions>