Commit f84d1e72 刘韬

变更使用SURF对齐图像

1 个父辈 564cadce
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props" Condition="Exists('..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props')" /> <Import Project="..\packages\OpenCvSharp4.runtime.win.4.8.0.20230708\build\netstandard\OpenCvSharp4.runtime.win.props" Condition="Exists('..\packages\OpenCvSharp4.runtime.win.4.8.0.20230708\build\netstandard\OpenCvSharp4.runtime.win.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
...@@ -42,20 +42,34 @@ ...@@ -42,20 +42,34 @@
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> <Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.dll</HintPath> <HintPath>..\packages\OpenCvSharp4.4.8.0.20230708\lib\netstandard2.0\OpenCvSharp.dll</HintPath>
</Reference> </Reference>
<Reference Include="OpenCvSharp.Blob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> <Reference Include="OpenCvSharp.Blob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.Blob.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\AccAOI\bin\Debug\OpenCvSharp.Blob.dll</HintPath>
</Reference> </Reference>
<Reference Include="OpenCvSharp.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> <Reference Include="OpenCvSharp.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.Extensions.dll</HintPath> <HintPath>..\packages\OpenCvSharp4.Extensions.4.8.0.20230708\lib\netstandard2.0\OpenCvSharp.Extensions.dll</HintPath>
</Reference>
<Reference Include="OpenCvSharp.UserInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.UserInterface.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Common, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Drawing.Common.7.0.0\lib\net462\System.Drawing.Common.dll</HintPath>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
<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.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath> <HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference> </Reference>
...@@ -85,6 +99,7 @@ ...@@ -85,6 +99,7 @@
<Compile Include="util\JsonUtil.cs" /> <Compile Include="util\JsonUtil.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
...@@ -92,6 +107,6 @@ ...@@ -92,6 +107,6 @@
<PropertyGroup> <PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText> <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props'))" /> <Error Condition="!Exists('..\packages\OpenCvSharp4.runtime.win.4.8.0.20230708\build\netstandard\OpenCvSharp4.runtime.win.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp4.runtime.win.4.8.0.20230708\build\netstandard\OpenCvSharp4.runtime.win.props'))" />
</Target> </Target>
</Project> </Project>
\ No newline at end of file \ No newline at end of file
using OpenCvSharp; using OpenCvSharp;
using OpenCvSharp.Extensions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file \ No newline at end of file
...@@ -7,6 +7,7 @@ using System.Runtime.InteropServices; ...@@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using OpenCvSharp; using OpenCvSharp;
using OpenCvSharp.Features2D;
using OpenCvSharp.XFeatures2D; using OpenCvSharp.XFeatures2D;
using static AOI.Eyemlib; using static AOI.Eyemlib;
...@@ -190,8 +191,8 @@ namespace AOI ...@@ -190,8 +191,8 @@ namespace AOI
//提取特征点 //提取特征点
SIFT sift = SIFT.Create(200); SIFT sift = SIFT.Create(200);
KeyPoint[] markKeyPoints, srcKeyPoints; KeyPoint[] markKeyPoints, srcKeyPoints;
MatOfFloat roiDescriptors = new MatOfFloat(); Mat roiDescriptors = new Mat();
MatOfFloat srcDescriptors = new MatOfFloat(); Mat srcDescriptors = new Mat();
sift.DetectAndCompute(markMat, null, out markKeyPoints, roiDescriptors); sift.DetectAndCompute(markMat, null, out markKeyPoints, roiDescriptors);
sift.DetectAndCompute(srcMat, null, out srcKeyPoints, srcDescriptors); sift.DetectAndCompute(srcMat, null, out srcKeyPoints, srcDescriptors);
......
...@@ -3,6 +3,7 @@ using System.Collections.Generic; ...@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq; using System.Linq;
using System.Net.Http.Headers;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -59,22 +60,28 @@ namespace AOI ...@@ -59,22 +60,28 @@ namespace AOI
/// <returns></returns> /// <returns></returns>
public (double,double) GetTemplateMatchPercent(Image standardImage, Image imageToCheck, out Image cutImg) public (double,double) GetTemplateMatchPercent(Image standardImage, Image imageToCheck, out Image cutImg)
{ {
var template = Eyemlib.eyemCvtToEyemImage((Bitmap)standardImage); cutImg = null;
if (RoiPath == null)
return (0d, 0d);
var rect = RoiPath.GetBounds();
if (rect == RectangleF.Empty)
return (0d, 0d);
float MatchRoi_Inflate = ConfigHelper.Config.Get("SURF_MatchRect_Inflate", 0.3f);
var newroi = new RectangleF(rect.Location,rect.Size);
newroi.Inflate(rect.Width * MatchRoi_Inflate, rect.Height * MatchRoi_Inflate);
var bitmap1 = AoiProject.CropBitmap((Bitmap)standardImage, newroi);
var template = Eyemlib.eyemCvtToEyemImage(bitmap1);
var search = Eyemlib.eyemCvtToEyemImage((Bitmap)imageToCheck); var search = Eyemlib.eyemCvtToEyemImage((Bitmap)imageToCheck);
int iNumMatches = 15;//目标个数 int iNumMatches = 5;//目标个数
double dToleranceAngle = 0.0;//要检测目标容忍角度 double dToleranceAngle = 0.0;//要检测目标容忍角度
double dMaxOverlap = 0.0;//重叠比例 double dMaxOverlap = 0.0;//重叠比例
double dScore = 0.8;//最小分数 double dScore = 0.8;//最小分数
cutImg = null;
//模板匹配 //模板匹配
EyemTargetMatch[] tpResults = new EyemTargetMatch[iNumMatches]; EyemTargetMatch[] tpResults = new EyemTargetMatch[iNumMatches];
IntPtr ResultHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(EyemTargetMatch)) * tpResults.Length); IntPtr ResultHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(EyemTargetMatch)) * tpResults.Length);
if (RoiPath==null)
return (0d, 0d);
var rect = RoiPath.GetBounds();
if (rect== RectangleF.Empty)
return (0d, 0d);
rect.X -= CenterOffsetX; rect.X -= CenterOffsetX;
rect.Y -= CenterOffsetY; rect.Y -= CenterOffsetY;
//框选模板匹配位置(通常左上角位置选一块) //框选模板匹配位置(通常左上角位置选一块)
...@@ -108,14 +115,16 @@ namespace AOI ...@@ -108,14 +115,16 @@ namespace AOI
int matchscore = 0; int matchscore = 0;
double anglescore = 0; double anglescore = 0;
double maxscore = 0;
//检测到目标 //检测到目标
for (int i = 0; i < tpResults.Length; i++) for (int i = 0; i < tpResults.Length; i++)
{ {
if (tpResults[i].fMatchScore > 0 && rect.Contains(tpResults[i].fCenterX, tpResults[i].fCenterY)) if (tpResults[i].fMatchScore > 0 && tpResults[i].fMatchScore>maxscore)// && rect.Contains(tpResults[i].fCenterX, tpResults[i].fCenterY))
{ {
matchscore = (int)(tpResults[i].fMatchScore*100); matchscore = (int)(tpResults[i].fMatchScore*100);
anglescore = Math.Abs(tpResults[i].fMatchAngle); anglescore = Math.Abs(tpResults[i].fMatchAngle);
maxscore = matchscore;
Console.WriteLine(string.Format("目标{0},位置({1},{2}),匹配分数{3}", Console.WriteLine(string.Format("目标{0},位置({1},{2}),匹配分数{3}",
i, tpResults[i].fCenterX.ToString("F3"), tpResults[i].fCenterY.ToString("F3"), tpResults[i].fMatchScore.ToString("F3"))); i, tpResults[i].fCenterX.ToString("F3"), tpResults[i].fCenterY.ToString("F3"), tpResults[i].fMatchScore.ToString("F3")));
......
...@@ -6,6 +6,7 @@ using System.Linq; ...@@ -6,6 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using OpenCvSharp; using OpenCvSharp;
using OpenCvSharp.Features2D;
using OpenCvSharp.XFeatures2D; using OpenCvSharp.XFeatures2D;
namespace AOI namespace AOI
...@@ -216,8 +217,8 @@ namespace AOI ...@@ -216,8 +217,8 @@ namespace AOI
//提取特征点 //提取特征点
SIFT sift = SIFT.Create(200); SIFT sift = SIFT.Create(200);
KeyPoint[] markKeyPoints, srcKeyPoints; KeyPoint[] markKeyPoints, srcKeyPoints;
MatOfFloat roiDescriptors = new MatOfFloat(); Mat roiDescriptors = new Mat();
MatOfFloat srcDescriptors = new MatOfFloat(); Mat srcDescriptors = new Mat();
sift.DetectAndCompute(markMat, null, out markKeyPoints, roiDescriptors); sift.DetectAndCompute(markMat, null, out markKeyPoints, roiDescriptors);
sift.DetectAndCompute(srcMat, null, out srcKeyPoints, srcDescriptors); sift.DetectAndCompute(srcMat, null, out srcKeyPoints, srcDescriptors);
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net45" /> <package id="Newtonsoft.Json" version="12.0.2" targetFramework="net45" />
<package id="OpenCvSharp3-AnyCPU" version="4.0.0.20181129" targetFramework="net45" requireReinstallation="true" /> <package id="OpenCvSharp4" version="4.8.0.20230708" targetFramework="net472" />
<package id="OpenCvSharp4.Extensions" version="4.8.0.20230708" targetFramework="net472" />
<package id="OpenCvSharp4.runtime.win" version="4.8.0.20230708" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.Drawing.Common" version="7.0.0" targetFramework="net472" />
<package id="System.Memory" version="4.5.5" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net46" requireReinstallation="true" /> <package id="System.ValueTuple" version="4.5.0" targetFramework="net46" requireReinstallation="true" />
</packages> </packages>
\ No newline at end of file \ No newline at end of file
...@@ -36,8 +36,7 @@ namespace AOI ...@@ -36,8 +36,7 @@ namespace AOI
int[] channels = new int[] { 0 };//一个通道,初始化为通道0 int[] channels = new int[] { 0 };//一个通道,初始化为通道0
int[] histsize = new int[] { 256 };//一个通道,初始化为256箱子 int[] histsize = new int[] { 256 };//一个通道,初始化为256箱子
Rangef[] range = new Rangef[1];//一个通道,值范围 Rangef[] range = new Rangef[1];//一个通道,值范围
range[0].Start = 0.0F;//从0开始(含) range[0] = new Rangef(0.0F, 256.0F);
range[0].End = 256.0F;//到256结束(不含)
Mat mask = new Mat();//不做掩码 Mat mask = new Mat();//不做掩码
Cv2.CalcHist(mats, channels, mask, hist, 1, histsize, range);//计算灰度图,dim为1 1维 Cv2.CalcHist(mats, channels, mask, hist, 1, histsize, range);//计算灰度图,dim为1 1维
return hist; return hist;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<TargetFrameworkProfile /> <TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
...@@ -42,22 +42,6 @@ ...@@ -42,22 +42,6 @@
<Reference Include="Asa.Theme"> <Reference Include="Asa.Theme">
<HintPath>..\dll\Asa.Theme.dll</HintPath> <HintPath>..\dll\Asa.Theme.dll</HintPath>
</Reference> </Reference>
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.dll</HintPath>
</Reference>
<Reference Include="OpenCvSharp.Blob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.Blob.dll</HintPath>
</Reference>
<Reference Include="OpenCvSharp.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.Extensions.dll</HintPath>
</Reference>
<Reference Include="OpenCvSharp.UserInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.UserInterface.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup> </startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration> </configuration>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props" Condition="Exists('..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props')" /> <Import Project="..\packages\OpenCvSharp4.runtime.win.4.8.0.20230708\build\netstandard\OpenCvSharp4.runtime.win.props" Condition="Exists('..\packages\OpenCvSharp4.runtime.win.4.8.0.20230708\build\netstandard\OpenCvSharp4.runtime.win.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
...@@ -50,19 +50,30 @@ ...@@ -50,19 +50,30 @@
<HintPath>..\dll\MvCameraControl.Net.dll</HintPath> <HintPath>..\dll\MvCameraControl.Net.dll</HintPath>
</Reference> </Reference>
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> <Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.dll</HintPath> <HintPath>..\packages\OpenCvSharp4.4.8.0.20230708\lib\netstandard2.0\OpenCvSharp.dll</HintPath>
</Reference>
<Reference Include="OpenCvSharp.Blob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.Blob.dll</HintPath>
</Reference> </Reference>
<Reference Include="OpenCvSharp.Blob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099" />
<Reference Include="OpenCvSharp.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> <Reference Include="OpenCvSharp.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.Extensions.dll</HintPath> <HintPath>..\packages\OpenCvSharp4.Extensions.4.8.0.20230708\lib\netstandard2.0\OpenCvSharp.Extensions.dll</HintPath>
</Reference>
<Reference Include="OpenCvSharp.UserInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<HintPath>..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net40\OpenCvSharp.UserInterface.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing.Common, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Drawing.Common.7.0.0\lib\net462\System.Drawing.Common.dll</HintPath>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
<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.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" /> <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
...@@ -227,6 +238,6 @@ ...@@ -227,6 +238,6 @@
<PropertyGroup> <PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText> <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\build\OpenCvSharp3-AnyCPU.props'))" /> <Error Condition="!Exists('..\packages\OpenCvSharp4.runtime.win.4.8.0.20230708\build\netstandard\OpenCvSharp4.runtime.win.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp4.runtime.win.4.8.0.20230708\build\netstandard\OpenCvSharp4.runtime.win.props'))" />
</Target> </Target>
</Project> </Project>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup> </startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration> </configuration>
...@@ -54,6 +54,7 @@ namespace AccAOI ...@@ -54,6 +54,7 @@ namespace AccAOI
this.imageBox1 = new Acc.ImageBox.AccImageBox(); this.imageBox1 = new Acc.ImageBox.AccImageBox();
this.btnCopy = new Asa.Theme.FlatButton(); this.btnCopy = new Asa.Theme.FlatButton();
this.btnPCBRect = new Asa.Theme.FlatButton(); this.btnPCBRect = new Asa.Theme.FlatButton();
this.label1 = new System.Windows.Forms.Label();
this.panTest.SuspendLayout(); this.panTest.SuspendLayout();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
...@@ -331,10 +332,21 @@ namespace AccAOI ...@@ -331,10 +332,21 @@ namespace AccAOI
this.btnPCBRect.Text = "设置基准PCB范围"; this.btnPCBRect.Text = "设置基准PCB范围";
this.btnPCBRect.Click += new System.EventHandler(this.btnPCBRect_Click); this.btnPCBRect.Click += new System.EventHandler(this.btnPCBRect_Click);
// //
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label1.Location = new System.Drawing.Point(206, 588);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(29, 23);
this.label1.TabIndex = 23;
this.label1.Text = "label1";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// FrmAoiSetting // FrmAoiSetting
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(1307, 624); this.ClientSize = new System.Drawing.Size(1307, 624);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnPCBRect); this.Controls.Add(this.btnPCBRect);
this.Controls.Add(this.panel1); this.Controls.Add(this.panel1);
this.Controls.Add(this.btnCopy); this.Controls.Add(this.btnCopy);
...@@ -391,5 +403,6 @@ namespace AccAOI ...@@ -391,5 +403,6 @@ namespace AccAOI
private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel panel1;
private Asa.Theme.FlatButton btnCopy; private Asa.Theme.FlatButton btnCopy;
private Asa.Theme.FlatButton btnPCBRect; private Asa.Theme.FlatButton btnPCBRect;
private System.Windows.Forms.Label label1;
} }
} }
\ No newline at end of file \ No newline at end of file
using AccAOI.camera; using AccAOI.camera;
using AOI; using AOI;
using OpenCvSharp.Blob; using OpenCvSharp.XFeatures2D;
using OpenCvSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
...@@ -13,13 +14,20 @@ using System.Linq; ...@@ -13,13 +14,20 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using OpenCvSharp.Extensions;
namespace AccAOI namespace AccAOI
{ {
public partial class FrmAoiSetting : FrmBase public partial class FrmAoiSetting : FrmBase
{ {
private control.ABaseControl aoiControl = null; private control.ABaseControl aoiControl = null;
/// <summary>
/// 原始剪裁基准图
/// </summary>
public static Image BaseImg = null; public static Image BaseImg = null;
/// <summary>
/// 原始基准大图
/// </summary>
public static Image OrgBaseImg = null; public static Image OrgBaseImg = null;
public static Eyemlib.EyemImage EyemBaseImg = new Eyemlib.EyemImage(); public static Eyemlib.EyemImage EyemBaseImg = new Eyemlib.EyemImage();
public static Image TestImage = null; public static Image TestImage = null;
...@@ -223,15 +231,33 @@ namespace AccAOI ...@@ -223,15 +231,33 @@ namespace AccAOI
return Eyemlib.DeepClone(orgimage); return Eyemlib.DeepClone(orgimage);
} }
else { else {
var (BaseImg, EyemBaseImg,result) =Eyemlib.ExtractPCB(orgimage, markroi.RoiPath.GetBounds()); BaseImg = AoiProject.CropBitmap(orgimage, markroi.RoiPath.GetBounds());
if (!result) {
return (Bitmap)BaseImg;
}
}
public Bitmap ProcessTestImage(Bitmap targetimage)
{
var markroi = Project?.BaseROI;
if (markroi == null || markroi.RoiPath == null || markroi.RoiPath.GetBounds() == RectangleF.Empty)
{
return Eyemlib.DeepClone(targetimage);
}
else
{
RectangleF rectangleF = markroi.RoiPath.GetBounds();
var result = AoiProject.SURF_MatchTemplate((Bitmap)OrgBaseImg, targetimage, rectangleF, out Bitmap matchBitmap);
//var (BaseImg, EyemBaseImg, result) = Eyemlib.ExtractPCB(orgimage, markroi.RoiPath.GetBounds());
if (!result)
{
MessageBox.Show(AOIResourceCulture.GetValue("在框选区域内没有找到PCB")); MessageBox.Show(AOIResourceCulture.GetValue("在框选区域内没有找到PCB"));
return null; return null;
} }
return (Bitmap)BaseImg; return matchBitmap;
} }
} }
private void btnOpenPro_Click(object sender, EventArgs e) private void btnOpenPro_Click(object sender, EventArgs e)
{ {
if (Project != null) if (Project != null)
...@@ -434,7 +460,7 @@ namespace AccAOI ...@@ -434,7 +460,7 @@ namespace AccAOI
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
aoiControl.FormBorderStyle = FormBorderStyle.None; aoiControl.FormBorderStyle = FormBorderStyle.None;
aoiControl.StartPosition = FormStartPosition.CenterParent; aoiControl.StartPosition = FormStartPosition.CenterParent;
aoiControl.Location = new Point(0, 0); aoiControl.Location = new System.Drawing.Point(0, 0);
aoiControl.BImageBox = this.imageBox1; aoiControl.BImageBox = this.imageBox1;
aoiControl.AoiInfo = method; aoiControl.AoiInfo = method;
aoiControl.Size = panAoi.Size; aoiControl.Size = panAoi.Size;
...@@ -584,7 +610,7 @@ namespace AccAOI ...@@ -584,7 +610,7 @@ namespace AccAOI
} }
lblTestResult.Text = ""; lblTestResult.Text = "";
Image outImage = null; Image outImage = null;
List<ResultBean> result = Project.CheckAll(OrgTestImage, out outImage); List<ResultBean> result = Project.CheckAll(TestImage, out outImage);
if (outImage != null) if (outImage != null)
{ {
if (!this.panTest.Visible) if (!this.panTest.Visible)
...@@ -672,7 +698,7 @@ namespace AccAOI ...@@ -672,7 +698,7 @@ namespace AccAOI
//file.Dispose(); //file.Dispose();
var b = new Bitmap(fileName); var b = new Bitmap(fileName);
OrgTestImage = Eyemlib.DeepClone(b); OrgTestImage = Eyemlib.DeepClone(b);
TestImage = ProcessBaseImage(b); TestImage = ProcessTestImage(b);
b.Dispose(); b.Dispose();
testImageBox1.Image = TestImage; testImageBox1.Image = TestImage;
...@@ -726,7 +752,7 @@ namespace AccAOI ...@@ -726,7 +752,7 @@ namespace AccAOI
//file.Dispose(); //file.Dispose();
var bmp = new Bitmap(filePath + fileName); var bmp = new Bitmap(filePath + fileName);
OrgTestImage = Eyemlib.DeepClone(bmp); OrgTestImage = Eyemlib.DeepClone(bmp);
TestImage = ProcessBaseImage(Eyemlib.DeepClone(bmp)); TestImage = ProcessTestImage(Eyemlib.DeepClone(bmp));
bmp.Dispose(); bmp.Dispose();
//读取图片内容 //读取图片内容
testImageBox1.Image = TestImage; testImageBox1.Image = TestImage;
...@@ -922,5 +948,10 @@ namespace AccAOI ...@@ -922,5 +948,10 @@ namespace AccAOI
imageBox1.Image = OrgBaseImg; imageBox1.Image = OrgBaseImg;
} }
} }
private void label1_Click(object sender, EventArgs e)
{
ConfigHelper.AdvanceConfigForm.ShowEditDialog(this);
}
} }
} }
...@@ -76,7 +76,7 @@ namespace AccAOI.control ...@@ -76,7 +76,7 @@ namespace AccAOI.control
var heightdiff = Math.Abs(FrmAoiSetting.TestImage.Height - cutbounds.Height); var heightdiff = Math.Abs(FrmAoiSetting.TestImage.Height - cutbounds.Height);
if (widthdiff > 2 && heightdiff > 2) if (widthdiff > 2 && heightdiff > 2)
{ {
FrmAoiSetting.TestImage = FrmAoiSetting.Project.ProcessBaseImage((Bitmap)FrmAoiSetting.OrgTestImage,"测试图"); FrmAoiSetting.TestImage = FrmAoiSetting.Project.ProcessTestImage((Bitmap)FrmAoiSetting.OrgTestImage,"测试图");
} }
} }
......
...@@ -8,8 +8,8 @@ using System.Text; ...@@ -8,8 +8,8 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using AOI; using AOI;
using OpenCvSharp.Blob;
using System.Threading; using System.Threading;
using OpenCvSharp.Blob;
namespace AccAOI.control namespace AccAOI.control
{ {
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="OpenCvSharp3-AnyCPU" version="4.0.0.20181129" targetFramework="net46" requireReinstallation="true" /> <package id="OpenCvSharp4" version="4.8.0.20230708" targetFramework="net472" />
<package id="OpenCvSharp4.Extensions" version="4.8.0.20230708" targetFramework="net472" />
<package id="OpenCvSharp4.runtime.win" version="4.8.0.20230708" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.Drawing.Common" version="7.0.0" targetFramework="net472" />
<package id="System.Memory" version="4.5.5" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net472" />
</packages> </packages>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup> </startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration> </configuration>
\ No newline at end of file \ No newline at end of file
...@@ -57,7 +57,7 @@ namespace 园晶斑点分析测试 ...@@ -57,7 +57,7 @@ namespace 园晶斑点分析测试
Cv2.GaussianBlur(srcMat2, srcMat2, new OpenCvSharp.Size(3, 3), 200); Cv2.GaussianBlur(srcMat2, srcMat2, new OpenCvSharp.Size(3, 3), 200);
Cv2.Threshold(srcMat2, srcMat2, 30, 255, threshType); Cv2.Threshold(srcMat2, srcMat2, 30, 255, threshType);
Cv2.ImShow("www", srcMat2); Cv2.ImShow("www", srcMat2);
return; //return;
//CvBlobs blobs = new CvBlobs(); //CvBlobs blobs = new CvBlobs();
////blobs.FilterByArea(200, 255); ////blobs.FilterByArea(200, 255);
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!