Skip to content

Commit

Permalink
Fixed Emgu.TF.Lite MAUI demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Canming Huang committed Jun 27, 2023
1 parent 41454c1 commit f3d0435
Show file tree
Hide file tree
Showing 20 changed files with 797 additions and 87 deletions.
8 changes: 6 additions & 2 deletions Emgu.TF.Example/CVInterop.Lite/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ public MainForm()
_mobileNet.OnDownloadProgressChanged += OnDownloadProgressChangedEventHandler;
}

public void OnDownloadProgressChangedEventHandler(object sender, System.Net.DownloadProgressChangedEventArgs e)
public void OnDownloadProgressChangedEventHandler(long? totalBytesToReceive, long bytesReceived, double? progressPercentage)
{
String msg = String.Format("Downloading models, please wait... {0} of {1} bytes ({2}%) downloaded.", e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage);
String msg = String.Format("Downloading models, please wait... ");
if (totalBytesToReceive.HasValue && totalBytesToReceive > 0)
msg += String.Format("{0} of {1} bytes downloaded ({2}%)", bytesReceived, totalBytesToReceive, progressPercentage);
else
msg += String.Format("{0} bytes downloaded.", bytesReceived);
if (InvokeRequired)
{
this.Invoke((MethodInvoker)(() =>
Expand Down
8 changes: 4 additions & 4 deletions Emgu.TF.Example/Inception.Console.Lite.NetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ static async Task Main(string[] args)
System.Console.ReadKey();
}

private static void onDownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
private static void onDownloadProgressChanged(long? totalBytesToReceive, long bytesReceived, double? progressPercentage)
{
if (e.TotalBytesToReceive <= 0)
System.Console.WriteLine(String.Format("{0} bytes downloaded", e.BytesReceived, e.ProgressPercentage));
if (totalBytesToReceive.HasValue && totalBytesToReceive > 0)
System.Console.WriteLine(String.Format("{0} of {1} bytes downloaded ({2}%)", bytesReceived, totalBytesToReceive, progressPercentage));
else
System.Console.WriteLine(String.Format("{0} of {1} bytes downloaded ({2}%)", e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage));
System.Console.WriteLine(String.Format("{0} bytes downloaded.", bytesReceived));
}


Expand Down
8 changes: 4 additions & 4 deletions Emgu.TF.Example/Maui.Lite/CocoSsdMobilenetPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public CocoSsdMobilenetPage()
}


private void onDownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
private void onDownloadProgressChanged(long? totalBytesToReceive, long bytesReceived, double? progressPercentage)
{
if (e.TotalBytesToReceive <= 0)
SetMessage(String.Format("{0} bytes downloaded.", e.BytesReceived));
if (totalBytesToReceive.HasValue && totalBytesToReceive > 0)
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", bytesReceived, totalBytesToReceive, progressPercentage));
else
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage));
SetMessage(String.Format("{0} bytes downloaded.", bytesReceived));
}

private static Annotation[] GetAnnotations(CocoSsdMobilenetV3.RecognitionResult[] result)
Expand Down
8 changes: 4 additions & 4 deletions Emgu.TF.Example/Maui.Lite/InceptionPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public InceptionPage()

}

private void onDownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
private void onDownloadProgressChanged(long? totalBytesToReceive, long bytesReceived, double? progressPercentage)
{
if (e.TotalBytesToReceive <= 0)
SetMessage(String.Format("{0} bytes downloaded", e.BytesReceived));
if (totalBytesToReceive.HasValue && totalBytesToReceive > 0)
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", bytesReceived, totalBytesToReceive, progressPercentage));
else
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage));
SetMessage(String.Format("{0} bytes downloaded", bytesReceived, progressPercentage));
}

private void onDownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion Emgu.TF.Example/Maui.Lite/Maui.Demo.Lite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@


<ItemGroup>
<ProjectReference Include="..\..\Emgu.TF.Platform\Maui\UI\Emgu.TF.Lite.Platform.Maui.UI.csproj" />
<ProjectReference Include="..\..\Emgu.TF.Platform\Maui\UI\Lite\Emgu.TF.Lite.Platform.Maui.UI.csproj" />
<ProjectReference Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'" Include="..\..\Emgu.TF.Lite\Emgu.TF.Lite.Netstandard.IOS\Emgu.TF.Lite.Netstandard.IOS.csproj" />
<ProjectReference Condition="!($([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios')" Include="..\..\Emgu.TF.Lite\Emgu.TF.Lite.Netstandard\Emgu.TF.Lite.Netstandard.csproj" />

Expand Down
8 changes: 4 additions & 4 deletions Emgu.TF.Example/Maui.Lite/MobilenetPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ public MobilenetPage()
};
}

private void onDownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
private void onDownloadProgressChanged(long? totalBytesToReceive, long bytesReceived, double? progressPercentage)
{
if (e.TotalBytesToReceive <= 0)
SetMessage(String.Format("{0} bytes downloaded", e.BytesReceived, e.ProgressPercentage));
if (totalBytesToReceive.HasValue && totalBytesToReceive > 0)
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", bytesReceived, totalBytesToReceive, progressPercentage));
else
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage));
SetMessage(String.Format("{0} bytes downloaded", bytesReceived, progressPercentage));
}

private async void OnButtonClicked(Object sender, EventArgs args)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ private void OutputRecorder_BufferReceived(object sender, OutputRecorder.BufferR
}
#endif

private void onDownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
private void onDownloadProgressChanged(long? totalBytesToReceive, long bytesReceived, double? progressPercentage)
{
if (e.TotalBytesToReceive <= 0)
SetMessage(String.Format("{0} bytes downloaded.", e.BytesReceived));
if (totalBytesToReceive.HasValue && totalBytesToReceive > 0)
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", bytesReceived, totalBytesToReceive, progressPercentage));
else
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage));
SetMessage(String.Format("{0} bytes downloaded.", bytesReceived));
}

private static Annotation[] GetAnnotations(CocoSsdMobilenetV3.RecognitionResult[] result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public InceptionPage()

}

private void onDownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
private void onDownloadProgressChanged(long? totalBytesToReceive, long bytesReceived, double? progressPercentage)
{
if (e.TotalBytesToReceive <= 0)
SetMessage(String.Format("{0} bytes downloaded", e.BytesReceived, e.ProgressPercentage));
if (totalBytesToReceive.HasValue && totalBytesToReceive > 0)
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", bytesReceived, totalBytesToReceive, progressPercentage));
else
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage));
SetMessage(String.Format("{0} bytes downloaded", bytesReceived, progressPercentage));
}

private void onDownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public MobilenetPage()
};
}

private void onDownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
private void onDownloadProgressChanged(long? totalBytesToReceive, long bytesReceived, double? progressPercentage)
{
if (e.TotalBytesToReceive <= 0)
SetMessage(String.Format("{0} bytes downloaded", e.BytesReceived, e.ProgressPercentage));
if (totalBytesToReceive.HasValue && totalBytesToReceive > 0)
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", bytesReceived, totalBytesToReceive, progressPercentage));
else
SetMessage(String.Format("{0} of {1} bytes downloaded ({2}%)", e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage));
SetMessage(String.Format("{0} bytes downloaded.", bytesReceived));
}

private async void OnButtonClicked(Object sender, EventArgs args)
Expand Down
9 changes: 4 additions & 5 deletions Emgu.TF.Lite.Models/CocoSsdMobilenet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,16 @@ public CocoSsdMobilenet()
_downloadManager = new FileDownloadManager();
_downloadManager.OnDownloadProgressChanged += onDownloadProgressChanged;
}

private void onDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
private void onDownloadProgressChanged(long? totalBytesToReceive, long bytesReceived, double? progressPercentage)
{
if (OnDownloadProgressChanged != null)
OnDownloadProgressChanged(sender, e);
OnDownloadProgressChanged(totalBytesToReceive, bytesReceived, progressPercentage);
}

/// <summary>
/// Event handler that triggers when download progress changed.
/// Callback when model download progress is changed.
/// </summary>
public event System.Net.DownloadProgressChangedEventHandler OnDownloadProgressChanged;
public event FileDownloadManager.DownloadProgressChangedEventHandler OnDownloadProgressChanged;

/// <summary>
/// Initialize the CocoSSDMobileNet model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" />
Expand Down
9 changes: 4 additions & 5 deletions Emgu.TF.Lite.Models/Inception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,16 @@ public Inception()

_downloadManager.OnDownloadProgressChanged += onDownloadProgressChanged;
}

private void onDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
private void onDownloadProgressChanged(long? totalBytesToReceive, long bytesReceived, double? progressPercentage)
{
if (OnDownloadProgressChanged != null)
OnDownloadProgressChanged(sender, e);
OnDownloadProgressChanged(totalBytesToReceive, bytesReceived, progressPercentage);
}

/// <summary>
/// Callback when the download progress has been changed.
/// Callback when model download progress is changed.
/// </summary>
public event System.Net.DownloadProgressChangedEventHandler OnDownloadProgressChanged;
public event FileDownloadManager.DownloadProgressChangedEventHandler OnDownloadProgressChanged;

/// <summary>
/// Initialize the graph by downloading the model from the Internet
Expand Down
9 changes: 5 additions & 4 deletions Emgu.TF.Lite.Models/Mobilenet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,17 @@ public Mobilenet()
_downloadManager.OnDownloadProgressChanged += onDownloadProgressChanged;
}

private void onDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
private void onDownloadProgressChanged(long? totalBytesToReceive, long bytesReceived, double? progressPercentage)
{
if (OnDownloadProgressChanged != null)
OnDownloadProgressChanged(sender, e);
OnDownloadProgressChanged(totalBytesToReceive, bytesReceived, progressPercentage);
}

/// <summary>
/// Callback when the download progress has been changed.
/// Callback when model download progress is changed.
/// </summary>
public event System.Net.DownloadProgressChangedEventHandler OnDownloadProgressChanged;
public event FileDownloadManager.DownloadProgressChangedEventHandler OnDownloadProgressChanged;


/// <summary>
/// Initialize the graph by downloading the model from the internet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<Compile Include="$(MSBuildThisFileDirectory)\..\..\Android\*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Emgu.TF.Lite\Emgu.TF.Lite.NetStandard\Emgu.TF.Lite.Netstandard.csproj" />
<ProjectReference Include="..\..\..\..\Emgu.TF.Lite\Emgu.TF.Lite.NetStandard\Emgu.TF.Lite.Netstandard.csproj" />
</ItemGroup>
<Target Name="EmguTfLiteMauiAndroidPackageBuildImports" BeforeTargets="PrepareForBuild">
<Warning Text="'$(EmguTfLiteMauiAndroidErrorMessage)'" Condition="'$(EmguTfLiteMauiAndroidErrorMessage)'!=''" />
Expand Down
Loading

0 comments on commit f3d0435

Please sign in to comment.