Commit f7f33da4 LN

判断检测料盘有无功能

1 个父辈 99d0d6f3
此文件类型无法预览
此文件类型无法预览
此文件的差异太大,无法显示。
此文件类型无法预览
此文件的差异太大,无法显示。
此文件类型无法预览
<?xml version="1.0" encoding="utf-8"?><doc>
<assembly>
<name>System.Buffers</name>
</assembly>
<members>
<member name="T:System.Buffers.ArrayPool`1">
<summary>Provides a resource pool that enables reusing instances of type <see cref="T[]"></see>.</summary>
<typeparam name="T">The type of the objects that are in the resource pool.</typeparam>
</member>
<member name="M:System.Buffers.ArrayPool`1.#ctor">
<summary>Initializes a new instance of the <see cref="T:System.Buffers.ArrayPool`1"></see> class.</summary>
</member>
<member name="M:System.Buffers.ArrayPool`1.Create">
<summary>Creates a new instance of the <see cref="T:System.Buffers.ArrayPool`1"></see> class.</summary>
<returns>A new instance of the <see cref="System.Buffers.ArrayPool`1"></see> class.</returns>
</member>
<member name="M:System.Buffers.ArrayPool`1.Create(System.Int32,System.Int32)">
<summary>Creates a new instance of the <see cref="T:System.Buffers.ArrayPool`1"></see> class using the specifed configuration.</summary>
<param name="maxArrayLength">The maximum length of an array instance that may be stored in the pool.</param>
<param name="maxArraysPerBucket">The maximum number of array instances that may be stored in each bucket in the pool. The pool groups arrays of similar lengths into buckets for faster access.</param>
<returns>A new instance of the <see cref="System.Buffers.ArrayPool`1"></see> class with the specified configuration.</returns>
</member>
<member name="M:System.Buffers.ArrayPool`1.Rent(System.Int32)">
<summary>Retrieves a buffer that is at least the requested length.</summary>
<param name="minimumLength">The minimum length of the array.</param>
<returns>An array of type <see cref="T[]"></see> that is at least <paramref name="minimumLength">minimumLength</paramref> in length.</returns>
</member>
<member name="M:System.Buffers.ArrayPool`1.Return(`0[],System.Boolean)">
<summary>Returns an array to the pool that was previously obtained using the <see cref="M:System.Buffers.ArrayPool`1.Rent(System.Int32)"></see> method on the same <see cref="T:System.Buffers.ArrayPool`1"></see> instance.</summary>
<param name="array">A buffer to return to the pool that was previously obtained using the <see cref="M:System.Buffers.ArrayPool`1.Rent(System.Int32)"></see> method.</param>
<param name="clearArray">Indicates whether the contents of the buffer should be cleared before reuse. If <paramref name="clearArray">clearArray</paramref> is set to true, and if the pool will store the buffer to enable subsequent reuse, the <see cref="M:System.Buffers.ArrayPool`1.Return(`0[],System.Boolean)"></see> method will clear the <paramref name="array">array</paramref> of its contents so that a subsequent caller using the <see cref="M:System.Buffers.ArrayPool`1.Rent(System.Int32)"></see> method will not see the content of the previous caller. If <paramref name="clearArray">clearArray</paramref> is set to false or if the pool will release the buffer, the array&amp;#39;s contents are left unchanged.</param>
</member>
<member name="P:System.Buffers.ArrayPool`1.Shared">
<summary>Gets a shared <see cref="T:System.Buffers.ArrayPool`1"></see> instance.</summary>
<returns>A shared <see cref="System.Buffers.ArrayPool`1"></see> instance.</returns>
</member>
</members>
</doc>
\ No newline at end of file
此文件类型无法预览
此文件的差异太大,无法显示。
此文件类型无法预览
此文件的差异被折叠, 点击展开。
此文件类型无法预览
此文件的差异太大,无法显示。
此文件类型无法预览
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</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>
\ No newline at end of file
此文件太大,无法显示。
此文件类型无法预览
......@@ -53,13 +53,26 @@
<Reference Include="log4net">
<HintPath>..\DLL\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ML.OnnxRuntime">
<HintPath>..\DLL\Microsoft.ML.OnnxRuntime.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="OpenCvSharp">
<HintPath>..\DLL\OpenCvSharp.dll</HintPath>
</Reference>
<Reference Include="SkiaSharp">
<HintPath>..\DLL\SkiaSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\DLL\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.ServiceProcess" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
......@@ -144,6 +157,9 @@
<None Include="Config\coverroi.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="model\PanDian_RoCut_320.onnx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="StoreConfig\fixPositions.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
......@@ -155,6 +171,23 @@
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="model\test_image\1.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="model\test_image\11573.jpg" />
<Content Include="model\test_image\1580.jpg" />
<Content Include="model\test_image\1609.jpg" />
<Content Include="model\test_image\1839.jpg" />
<Content Include="model\test_image\1985.jpg" />
<Content Include="model\test_image\2.jpg" />
<Content Include="model\test_image\2193.jpg" />
<Content Include="model\test_image\2358.jpg" />
<Content Include="model\test_image\2842.jpg" />
<Content Include="model\test_image\2986.jpg" />
<Content Include="model\test_image\3.jpg" />
<Content Include="model\test_image\3190.jpg" />
<Content Include="model\test_image\3759.jpg" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using Newtonsoft.Json;
using OnlineStore.Common;
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace DeviceLibrary
{
public class ReelCheckUtil
{
[DllImport("reelCheck.dll", CharSet = CharSet.Ansi)]
internal static extern string ReadX(string json);
private static bool HasNeox()
{
if (File.Exists("reelCheck.dll"))
return true;
if (File.Exists(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "reelCheck.dll")))
return true;
return false;
}
public static int ReelCheck(string equipName, string currImg)
{
if (!HasNeox())
{
LogUtil.info($"{equipName} ReelCheck 未找到NeoX.dll,直接返回原位置");
return -1;
}
try
{
var d = new NeoXData();
d.imgPath = currImg;
var s = JsonConvert.SerializeObject(d);
string result = ReadX(s);
NeoRData data = JsonConvert.DeserializeObject<NeoRData>(result);
LogUtil.info($"{equipName} 图片[{currImg}] ReelCheck ,返回:{result}");
if (data.result1 >= 0)
{
return data.result1;
}
}
catch (Exception ex)
{
LogUtil.error($"{equipName} ReelCheck ,{currImg} 出错:{ex.ToString()}");
}
return -1;
}
}
internal class NeoXData
{
//输入图像路径
public string imgPath;
//料盘宽度
public int plateW = 0;
//输出图像路径
public string outPath;
//算法名称
public string Algo;
//剪裁像素
public int shrinkOffset;
//剪裁角落
public int Corner = 0;
}
internal class NeoRData
{
/// <summary>
/// Result1 =1有料盘,=0无料盘
/// </summary>
public int result1 = 0;
public int result2 = 0;
public int code = -1;
public string msg = "";
}
}
using Newtonsoft.Json;
using System;
using System.Linq;
using SkiaSharp;
using OpenCvSharp; //注:OpenCvSharp4 和 OpenCvSharp4.runtime.win
using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
using System.IO;
using OnlineStore.Common;
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace DeviceLibrary
{
public class ReelCheckUtil
public class ReelCheckUtil
{
[DllImport("reelCheck.dll", CharSet = CharSet.Ansi)]
internal static extern string ReadX(string json);
private static bool HasNeox()
{
if (File.Exists("reelCheck.dll"))
return true;
if (File.Exists(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "reelCheck.dll")))
return true;
return false;
}
public static int ReelCheck(string equipName, string currImg)
private static string Model_Path = @"model/PanDian_RoCut_320.onnx";
private static string Test_ImgPath = @"model/test_image/1.jpg";
//推测函数
public static int ReelCheck( string imagePath, string modelPath="")
{
if (!HasNeox())
{
LogUtil.info($"{equipName} ReelCheck 未找到NeoX.dll,直接返回原位置");
return -1;
}
try
{
if (modelPath == "")
{
modelPath = Model_Path;
}
if(!File.Exists(imagePath)&&File.Exists(Test_ImgPath))
{
LogUtil.info($"ReelCheck 未找到文件{imagePath} ,使用测试文件:{Test_ImgPath}");
imagePath = Test_ImgPath;
}
else
{
imagePath = Test_ImgPath;
}
float score_0 = 0.8f; //判断为 “ 无 ” 的得分阈值
float score_1 = 0.8f; //判断为 “ 有 ” 的得分阈值
Mat src = Cv2.ImRead(imagePath);
Point2f center = new Point2f(src.Cols / 2.0f, src.Rows / 2.0f);
double angle = 4.0;
Mat rotMat = Cv2.GetRotationMatrix2D(center, angle, 1.0);
Mat dst = new Mat();
Cv2.WarpAffine(src, dst, rotMat, src.Size());
Rect rect = new Rect(200, 590, 300, 100);
Mat roi = new Mat(dst, rect);
var d = new NeoXData();
d.imgPath = currImg;
var s = JsonConvert.SerializeObject(d);
string result = ReadX(s);
NeoRData data = JsonConvert.DeserializeObject<NeoRData>(result);
LogUtil.info($"{equipName} 图片[{currImg}] ReelCheck ,返回:{result}");
if (data.result1 >= 0)
using (var session = new InferenceSession(modelPath))
{
return data.result1;
var images = NamedOnnxValue.CreateFromTensor("images", LoadImageAsTensor(roi));
using (var results = session.Run(new[] { images }))
{
var output = results.FirstOrDefault(r => r.Name == "output0")?.AsTensor<float>();
if (output != null)
{
var outputArray = output.ToArray();
float probabilityClass0 = outputArray[0];
float probabilityClass1 = outputArray[1];
int predictedClass;
if (probabilityClass1 > score_1) { predictedClass = 1; }
else if (probabilityClass0 > score_0) { predictedClass = 0; }
else { predictedClass = 2; }
for (int i = 0; i < outputArray.Length; i++)
{
Console.WriteLine("Class " + i + ": " + outputArray[i].ToString("F2"));
}
return predictedClass;
}
else
{
Console.WriteLine("No output found with the name 'output0'.");
return -1;
}
}
}
}
catch (Exception ex)
{
LogUtil.error($"{equipName} ReelCheck ,{currImg} 出错:{ex.ToString()}");
Console.WriteLine("An error occurred: " + ex.Message);
Console.WriteLine("Stack Trace: " + ex.StackTrace);
return -1;
}
return -1;
}
}
internal class NeoXData
{
//输入图像路径
public string imgPath;
//料盘宽度
public int plateW = 0;
//输出图像路径
public string outPath;
//算法名称
public string Algo;
//剪裁像素
public int shrinkOffset;
//剪裁角落
public int Corner = 0;
}
internal class NeoRData
{
/// <summary>
/// Result1 =1有料盘,=0无料盘
/// </summary>
public int result1 = 0;
public int result2 = 0;
public int code = -1;
public string msg = "";
//张量变换函数
static Tensor<float> LoadImageAsTensor(Mat roi)
{
using (var bitmap = SKBitmap.Decode(roi.ToMemoryStream()))
{
int targetWidth = 320;
int targetHeight = 320;
using (var resizedBitmap = bitmap.Resize(new SKImageInfo(targetWidth, targetHeight), SKFilterQuality.High))
{
var tensor = new DenseTensor<float>(new[] { 1, 3, targetHeight, targetWidth });
for (int y = 0; y < targetHeight; y++)
{
for (int x = 0; x < targetWidth; x++)
{
SKColor color = resizedBitmap.GetPixel(x, y);
tensor[0, 0, y, x] = color.Red / 255.0f;
tensor[0, 1, y, x] = color.Green / 255.0f;
tensor[0, 2, y, x] = color.Blue / 255.0f;
}
}
return tensor;
}
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.12.0" newVersion="2.0.12.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
......@@ -66,6 +66,10 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.12.0" newVersion="2.0.12.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.web>
......
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
......@@ -66,6 +66,10 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.12.0" newVersion="2.0.12.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.web>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!