Commit d35469d2 刘韬

1

1 个父辈 f2dde140
......@@ -24,17 +24,35 @@ namespace Asa
static IntPtr hModelIDs = IntPtr.Zero;
static XrayImage()
{
if (!Directory.Exists("CountTemplate"))
Directory.CreateDirectory("CountTemplate");
var flag = eyemInitModel("CountTemplate", out hModelIDs);
if (flag != 0) {
throw new Exception("eyemInitModel:"+flag+","+hModelIDs);
}
AlgoIndex.Clear();
AlgoIndex.Add("NONE", -1);
for (int i = 0; i < sOptions.Length; i++)
{
AlgoIndex.Add(sOptions[i], i);
}
if (!Directory.Exists("CountTemplate"))
Directory.CreateDirectory("CountTemplate");
var flag = eyemInitModel("CountTemplate", out hModelIDs);
if (flag != 0)
{
if (!ReloadEyemlib())
throw new Exception("eyemInitModel:" + flag + "," + hModelIDs);
}
}
/// <summary>
/// 重载eyemLib.dll
/// </summary>
[HandleProcessCorruptedStateExceptions]
public static bool ReloadEyemlib() {
if (hModelIDs != IntPtr.Zero)
{
eyemReleaseModel(ref hModelIDs);
hModelIDs = IntPtr.Zero;
}
UnloadModule("eyemLib.dll");
Thread.Sleep(10);
LoadLibrary("eyemLib.dll");
return ReloadTpl()==0;
}
/// <summary>
/// 算法名称对索引应序号
......@@ -364,7 +382,11 @@ namespace Asa
count = ipReelNum;
if (n == 0)
BmpDstImg = eyemCvtToBitmap(tpDstImg);
eyemImageFree(ref tpDstImg);
//if (n != 0)
// ReloadEyemlib();
return n;
}
......@@ -435,6 +457,8 @@ namespace Asa
eyemImageFree(ref tpDstImg);
eyemImageFree(ref eyem);
count = ipReelNum;
//if(n!=0)
// ReloadEyemlib();
return true;
}
......@@ -468,9 +492,11 @@ namespace Asa
int result = -1;
try
{
Debug.WriteLine("hModelIDs:" + hModelIDs);
eyemReleaseModel(ref hModelIDs);
if (hModelIDs != IntPtr.Zero)
{
Debug.WriteLine("hModelIDs:" + hModelIDs);
eyemReleaseModel(ref hModelIDs);
}
result = eyemInitModel("CountTemplate", out hModelIDs);
return result;
}
......
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
......@@ -357,5 +358,24 @@ namespace Asa
float fY; // Y坐标
float fR; // 半径
}
[DllImport("kernel32", SetLastError = true)]
static extern bool FreeLibrary(IntPtr hModule);
[DllImport("kernel32", SetLastError = true)]
static extern bool FreeLibraryAndExitThread(IntPtr hModule, uint dwExitCode);
public static void UnloadModule(string moduleName)
{
foreach (ProcessModule mod in Process.GetCurrentProcess().Modules)
{
if (mod.ModuleName == moduleName)
{
FreeLibrary(mod.BaseAddress);
//FreeLibraryAndExitThread(mod.BaseAddress,0);
}
}
}
[DllImport("kernel32.dll")]
public extern static IntPtr LoadLibrary(string path);
}
}
......@@ -157,6 +157,7 @@ namespace CarerayImage_Test
private void button9_Click(object sender, EventArgs e)
{
//xrayImage.ReloadEyemlib();
for (int i = 0; i < 20; i++)
{
eyemLib.EyemImage eyemImage = xrayImage.GetRawBufferHandle();
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!