Commit 29168cb4 刘韬

CountTemplateX

1 个父辈 31fa496f
......@@ -68,7 +68,7 @@ public static class NeoX
}
[HandleProcessCorruptedStateExceptions]
internal static bool AlgoC(string filename, int shrinkOffset, int Corner, string type, out int count, out Bitmap bitmap)
internal static bool AlgoC(string filename,string templateFile, int shrinkOffset, int Corner, string type, out int count, out Bitmap bitmap)
{
var d = new NeoXData();
......@@ -76,6 +76,7 @@ public static class NeoX
d.outPath = Corner + "-Mark.png";
d.shrinkOffset = shrinkOffset;
d.Corner = Corner;
d.temPath = templateFile;
d.Algo = type;
var s = JsonConvert.SerializeObject(d);
count = 0;
......@@ -197,6 +198,8 @@ internal class NeoXData
public string imgPath;
//输出图像路径
public string outPath;
//输入模版路径
public string temPath;
//算法名称
public string Algo;
//剪裁像素
......
......@@ -254,7 +254,10 @@ namespace Asa
type = NeoX.ConverterType(type,true);
if (NeoX.HasNeox() && type.StartsWith("ID"))
{
var result = NeoX.AlgoC(path, ShrinkOffset,0, type, out int c, out Bitmap bitmap);
var tf = GetTemplateFile(path);
if (!string.IsNullOrEmpty(tf))
type = "ID_TYPE_T";
var result = NeoX.AlgoC(path, tf, ShrinkOffset,0, type, out int c, out Bitmap bitmap);
count = new int[4] { c, 0, 0, 0 };
BmpDstImg = bitmap;
return result?0:-1;
......@@ -272,6 +275,51 @@ namespace Asa
eyemImageFree(ref eyem);
return n;
}
private static string GetTemplateFile(string path)
{
try
{
// 提取文件名中等于号前面的部分
string fileName = Path.GetFileNameWithoutExtension(path);
var splitchar = ConfigHelper.Config.Get("PN_Split_Char", "-");
int index = fileName.IndexOf(splitchar); // 找到等于号的位置
string pn;
if (index != -1)
{
pn = fileName.Substring(0, index); // 截取等于号前面的部分
}
else
{
pn = fileName; // 如果没有等号,则直接使用整个文件名
}
// 拼接目标路径和文件名
string directoryPath = CommonLib.GetPath("CountTemplateX");
string targetFile = $"{pn}.png";
string fullPath = Path.Combine(directoryPath, targetFile);
string subfullPath = Path.Combine(CommonLib.GetPath("..\\CountTemplateX"), targetFile);
// 检查目标文件是否存在
if (File.Exists(fullPath))
{
return fullPath; // 返回文件的完整路径
}else if (File.Exists(subfullPath))
{
return subfullPath; // 返回文件的完整路径
}
else
{
return ""; // 文件不存在,返回空
}
}
catch (Exception ex)
{
// 处理异常,如路径无法访问、文件名无效等
Console.WriteLine($"Error: {ex}");
return "";
}
}
[HandleProcessCorruptedStateExceptions]
public static int GetLocalCountIrregular(EyemImage eyem, int ShrinkOffset, string outfilename, string type, out int[] count, out Bitmap BmpDstImg)
......@@ -329,7 +377,11 @@ namespace Asa
int Corner = ck;
try
{
NeoX.AlgoC(path, ShrinkOffset, Corner + 1, ccdata[ck], out int c, out Bitmap bitmap);
var type1 = ccdata[ck];
var tf = GetTemplateFile(path);
if (!string.IsNullOrEmpty(tf))
type1 = "ID_TYPE_T";
NeoX.AlgoC(path, tf, ShrinkOffset, Corner + 1, type1, out int c, out Bitmap bitmap);
lock (ccresult)
{
ccresult.Add(Corner, (c, bitmap));
......
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!