Skip to content

Commit

Permalink
😎
Browse files Browse the repository at this point in the history
  • Loading branch information
nenoNaninu committed Oct 16, 2020
1 parent beafaf9 commit 04eaba1
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 102 deletions.
10 changes: 2 additions & 8 deletions HomographySharp/HomographyHelper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Collections.Generic;
using System.Numerics;
using System.Collections.Generic;
using HomographySharp.Double;
using HomographySharp.Single;
#if NETSTANDARD2_1
using System.Numerics;
#endif

namespace HomographySharp
{
Expand All @@ -12,10 +10,8 @@ public static class HomographyHelper
public static HomographyMatrix<float> FindHomography(IReadOnlyList<Point2<float>> srcPoints, IReadOnlyList<Point2<float>> dstPoints)
=> SingleHomographyHelper.FindHomography(srcPoints, dstPoints);

#if NETSTANDARD2_1
public static HomographyMatrix<float> FindHomography(IReadOnlyList<Vector2> srcPoints, IReadOnlyList<Vector2> dstPoints)
=> SingleHomographyHelper.FindHomography(srcPoints, dstPoints);
#endif

public static HomographyMatrix<double> FindHomography(IReadOnlyList<Point2<double>> srcPoints, IReadOnlyList<Point2<double>> dstPoints)
=> DoubleHomographyHelper.FindHomography(srcPoints, dstPoints);
Expand All @@ -26,8 +22,6 @@ public static Point2<float> Translate(HomographyMatrix<float> homographyMatrix,
public static Point2<double> Translate(HomographyMatrix<double> homographyMatrix, double srcX, double srcY)
=> homographyMatrix.Translate(srcX, srcY);

#if NETSTANDARD2_1
public static Vector2 AsVector2(this Point2<float> source) => new Vector2(source.X, source.Y);
#endif
}
}
10 changes: 7 additions & 3 deletions HomographySharp/HomographySharp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;</TargetFrameworks>
<PackageId>HomographySharp</PackageId>
<AssemblyName>HomographySharp</AssemblyName>
<Version>1.5.0</Version>
Expand All @@ -12,11 +12,15 @@
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<None Include="LICENSE.txt" Pack="true" PackagePath="$(PackageLicenseFile)" />
</ItemGroup>


<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Numerics.Vectors" Version="4.5.*" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="MathNet.Numerics" Version="4.12.*" />
</ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions HomographySharp/Matrix.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace HomographySharp
{
public abstract class HomographyMatrix<T> where T : struct
public abstract class HomographyMatrix<T> where T : struct, IEquatable<T>
{
public abstract Point2<T> Translate(T srcX, T srcY);

Expand Down
6 changes: 3 additions & 3 deletions HomographySharp/Point2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
#if NETSTANDARD2_1
return HashCode.Combine(X, Y);
#else
#if NETSTANDARD2_0
return X.GetHashCode() ^ Y.GetHashCode();
#else
return HashCode.Combine(X, Y);
#endif
}

Expand Down
6 changes: 1 addition & 5 deletions HomographySharp/Single/SingleHomographyHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Numerics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using MathNet.Numerics.LinearAlgebra.Single;
#if NETSTANDARD2_1
using System.Numerics;
#endif

namespace HomographySharp.Single
{
Expand Down Expand Up @@ -118,7 +116,6 @@ public static HomographySingleMatrix FindHomography(IReadOnlyList<Point2<float>>
return new HomographySingleMatrix(elements);
}

#if NETSTANDARD2_1
/// <summary>
/// </summary>
/// <param name="srcPoints">need 4 or more points before translate </param>
Expand Down Expand Up @@ -180,6 +177,5 @@ public static HomographySingleMatrix FindHomography(IReadOnlyList<Vector2> srcPo

return new HomographySingleMatrix(elements);
}
#endif
}
}
51 changes: 24 additions & 27 deletions HomographySharpTest/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,14 @@ public void FindHomographyTest3()
var srcList = new List<Point2<double>>(4);
var dstList = new List<Point2<double>>(4);

srcList.Add(new Point2<double> { X = 10, Y = 10 });
srcList.Add(new Point2<double> { X = 100, Y = 10 });
srcList.Add(new Point2<double> { X = 100, Y = 150 });
srcList.Add(new Point2<double> { X = 10, Y = 150 });

dstList.Add(new Point2<double> { X = 11, Y = 11 });
dstList.Add(new Point2<double> { X = 500, Y = 11 });
dstList.Add(new Point2<double> { X = 500, Y = 200 });
dstList.Add(new Point2<double> { X = 11, Y = 200 });
srcList.Add(new Point2<double>(10, 10));
srcList.Add(new Point2<double>(100, 10));
srcList.Add(new Point2<double>(100, 150));
srcList.Add(new Point2<double>(10, 150));
dstList.Add(new Point2<double>(11, 11));
dstList.Add(new Point2<double>(500, 11));
dstList.Add(new Point2<double>(500, 200));
dstList.Add(new Point2<double>(11, 200));

var homo = HomographyHelper.FindHomography(srcList, dstList);
stopWatch.Stop();
Expand Down Expand Up @@ -121,15 +120,14 @@ public void FindHomographyTest4()
var srcList = new List<Point2<double>>(4);
var dstList = new List<Point2<double>>(4);

srcList.Add(new Point2<double> { X = -152, Y = 394 });
srcList.Add(new Point2<double> { X = 218, Y = 521 });
srcList.Add(new Point2<double> { X = 223, Y = -331 });
srcList.Add(new Point2<double> { X = -163, Y = -219 });

dstList.Add(new Point2<double> { X = -666, Y = 431 });
dstList.Add(new Point2<double> { X = 500, Y = 300 });
dstList.Add(new Point2<double> { X = 480, Y = -308 });
dstList.Add(new Point2<double> { X = -580, Y = -280 });
srcList.Add(new Point2<double>(-152, 394));
srcList.Add(new Point2<double>(218, 521));
srcList.Add(new Point2<double>(223, -331));
srcList.Add(new Point2<double>(-163, -219));
dstList.Add(new Point2<double>(-666, 431));
dstList.Add(new Point2<double>(500, 300));
dstList.Add(new Point2<double>(480, -308));
dstList.Add(new Point2<double>(-580, -280));

var homo = HomographyHelper.FindHomography(srcList, dstList);
stopWatch.Stop();
Expand Down Expand Up @@ -164,15 +162,14 @@ public void FindHomographyTestForSetUp()
var srcList = new List<Point2<double>>(4);
var dstList = new List<Point2<double>>(4);

srcList.Add(new Point2<double> { X = -152, Y = 394 });
srcList.Add(new Point2<double> { X = 218, Y = 521 });
srcList.Add(new Point2<double> { X = 223, Y = -331 });
srcList.Add(new Point2<double> { X = -163, Y = -219 });

dstList.Add(new Point2<double> { X = -666, Y = 431 });
dstList.Add(new Point2<double> { X = 500, Y = 300 });
dstList.Add(new Point2<double> { X = 480, Y = -308 });
dstList.Add(new Point2<double> { X = -580, Y = -280 });
srcList.Add(new Point2<double>(-152, 394));
srcList.Add(new Point2<double>(218, 521));
srcList.Add(new Point2<double>(223, -331));
srcList.Add(new Point2<double>(-163, -219));
dstList.Add(new Point2<double>(-666, 431));
dstList.Add(new Point2<double>(500, 300));
dstList.Add(new Point2<double>(480, -308));
dstList.Add(new Point2<double>(-580, -280));

var homo = HomographyHelper.FindHomography(srcList, dstList);
stopWatch.Stop();
Expand Down
10 changes: 5 additions & 5 deletions HomographyVisualizer/App.config
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
</configuration>
6 changes: 5 additions & 1 deletion HomographyVisualizer/HomographyVisualizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
<OutputType>WinExe</OutputType>
<RootNamespace>HomographyVisualizer</RootNamespace>
<AssemblyName>HomographyVisualizer</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -52,6 +53,9 @@
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Reactive, Version=4.1.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reactive.4.1.2\lib\net46\System.Reactive.dll</HintPath>
</Reference>
Expand Down
52 changes: 22 additions & 30 deletions HomographyVisualizer/Properties/Resources.Designer.cs

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

30 changes: 13 additions & 17 deletions HomographyVisualizer/Properties/Settings.Designer.cs

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

2 changes: 1 addition & 1 deletion HomographyVisualizer/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<package id="MathNet.Numerics" version="4.7.0" targetFramework="net471" />
<package id="ReactiveProperty" version="5.3.2" targetFramework="net471" />
<package id="System.ComponentModel.Annotations" version="4.5.0" targetFramework="net471" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net471" />
<package id="System.ObjectModel" version="4.3.0" targetFramework="net471" />
<package id="System.Reactive" version="4.1.2" targetFramework="net471" />
<package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net471" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net471" />
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net471" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net471" />
</packages>

<!--ReactiveProperty is
Copyright (c) 2018 neuecc, xin9le, okazuki
Released under the MIT license.
Expand Down

0 comments on commit 04eaba1

Please sign in to comment.