Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
asiryan committed Jul 1, 2024
1 parent b4c0ba5 commit 6d8ffa7
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 0 deletions.
31 changes: 31 additions & 0 deletions netstandard/Examples/DepthEstimation/DepthEstimation.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>disable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.9.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\DepthONNX\DepthONNX.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="example.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Runtime.Loader.UseRidGraph" Value="true" />
</ItemGroup>

</Project>
47 changes: 47 additions & 0 deletions netstandard/Examples/DepthEstimation/Form1.Designer.cs

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

56 changes: 56 additions & 0 deletions netstandard/Examples/DepthEstimation/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using DepthONNX;
using UMapx.Core;
using UMapx.Imaging;

namespace DepthSegmentation
{
public partial class Form1 : Form
{
private readonly DepthEstimator _depthSegmentator;

public Form1()
{
InitializeComponent();

BackgroundImageLayout = ImageLayout.Zoom;
DragDrop += Form1_DragDrop;
DragEnter += Form1_DragEnter;
AllowDrop = true;
Text = "DepthONNX: Depth estimation";

_depthSegmentator = new DepthEstimator(DepthEstimatorQuality.High);
var image = new Bitmap("example.png");
Process(image);
}

private void Form1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.All : DragDropEffects.None;
}

private void Form1_DragDrop(object sender, DragEventArgs e)
{
Cursor = Cursors.WaitCursor;
var file = ((string[])e.Data.GetData(DataFormats.FileDrop, true))[0];
var image = new Bitmap(file);
Process(image);
Cursor = Cursors.Default;
}

private void Process(Bitmap image)
{
var results = _depthSegmentator.Forward(
image: image,
interpolationMode: InterpolationMode.Bicubic);

var mask = results.Normalized().FromGrayscale();
image?.Dispose();

//mask.Save("output.png", System.Drawing.Imaging.ImageFormat.Png);

BackgroundImage?.Dispose();
BackgroundImage = mask;
}

}
}
60 changes: 60 additions & 0 deletions netstandard/Examples/DepthEstimation/Form1.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
19 changes: 19 additions & 0 deletions netstandard/Examples/DepthEstimation/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using DepthSegmentation;

namespace DepthEstimation
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
}
Binary file added netstandard/Examples/DepthEstimation/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added netstandard/Examples/DepthEstimation/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions netstandard/Examples/DepthONNX.Examples.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{78C89484-425E-4487-916C-6600BCA7DB8A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DepthONNX", "..\DepthONNX\DepthONNX.csproj", "{F8DB7D70-A6D2-4D78-A4EB-7346588B64CD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DepthEstimation", "DepthEstimation\DepthEstimation.csproj", "{9CD316D8-1A96-4A66-8F46-EF927ECA9F4D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F8DB7D70-A6D2-4D78-A4EB-7346588B64CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F8DB7D70-A6D2-4D78-A4EB-7346588B64CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8DB7D70-A6D2-4D78-A4EB-7346588B64CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F8DB7D70-A6D2-4D78-A4EB-7346588B64CD}.Release|Any CPU.Build.0 = Release|Any CPU
{9CD316D8-1A96-4A66-8F46-EF927ECA9F4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9CD316D8-1A96-4A66-8F46-EF927ECA9F4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9CD316D8-1A96-4A66-8F46-EF927ECA9F4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9CD316D8-1A96-4A66-8F46-EF927ECA9F4D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9CD316D8-1A96-4A66-8F46-EF927ECA9F4D} = {78C89484-425E-4487-916C-6600BCA7DB8A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {049EC67F-030B-4133-A200-36D943F0FAC6}
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions netstandard/Examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p align="center"><img width="25%" src="../../docs/depthonnx_logo.png" /></p>
<p align="center"> Monocular depth estimation library based on deep neural networks and <b>ONNX</b> runtime </p>

# Depth estimation
Build and run [DepthEstimation.csproj](DepthEstimation) to produce results.
<p align="center"><img width="50%" src="DepthEstimation/example.png" /><img width="50%" src="DepthEstimation/output.png" /></p>
<p align="center"><b>Figure 1.</b> Results for <i>example.png</i></p>

0 comments on commit 6d8ffa7

Please sign in to comment.