Commit 5d801ec0 张士柳

1 个父辈 5fb7556d
......@@ -780,6 +780,9 @@ namespace eyemLib_Sharp
//插件机
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, IntPtr tpArray, int iArraySize);
//跳过程序执行
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int setSkipProcessID(int pid);
#endregion
#region 日志功能
......@@ -794,8 +797,12 @@ namespace eyemLib_Sharp
OnNewLogCallback?.Invoke(msg);
}
public static log4cpp.LogManager logcpp = null;
public static void Init()
{
logcpp = new log4cpp.LogManager("D:\\日志\\", "_运行日志", log4cpp.GenerateMode.ByEveryDay);
setLogCallback(sld);
OnNewLogCallback += new TCallBack(EyemLib_OnNewLogCallback);
......@@ -809,7 +816,13 @@ namespace eyemLib_Sharp
//记录日志
private static void EyemLib_OnNewLogCallback(string msg)
{
Console.WriteLine(msg);
logcpp.WriteLog("[" + Thread.CurrentThread.ManagedThreadId.ToString("X16") + "]" + msg);
}
//设置跳过程序执行
public static void setSkipProcess(int pid)
{
setSkipProcessID(pid);
}
#endregion
......@@ -1024,9 +1037,17 @@ namespace eyemLib_Sharp
//插入模板
flag = eyemInsertModel(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
string[] tpModels = selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (tpModels.Length <= 0)
{
logcpp.WriteLog("选择模板少于0");
return;
}
//根据名称获取模板
EyemModelID tpModelID = new EyemModelID();
eyemAchvModelByName(selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0], hModelID, ref tpModelID);
eyemAchvModelByName(tpModels[0], hModelID, ref tpModelID);
//EyemImage tpModeImg = new EyemImage();
//tpModeImg.iChannels = 1; tpModeImg.iDepth = 0;
......@@ -1046,7 +1067,7 @@ namespace eyemLib_Sharp
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), 35, 0, 100, 5, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), 0.1, "IP_LARGE_PARTS", 100, 7, ref pNumObj, out tpDstImg);
//eyemCountObjectE(image, tpRoi, fileName, ref pNumObj, out tpDstImg);
eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0], hModelID, ref pNumObj, out tpDstImg);
eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), tpModels[0], hModelID, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + /*file.Replace(".png", ".tpl")*/"74d571ed-9fd4-4959-85dd-3195261e4b48.tpl", ref pNumObj, out tpDstImg);
//移除模板
......
......@@ -10,27 +10,32 @@ namespace eyemLib_Sharp
{
static void Main(string[] args)
{
DirectoryInfo di = new DirectoryInfo("D:\\日志\\");
if (!di.Exists)
{
di.Create();
}
//初始化
EyemLib.Init();
string[] fileNames = Directory.GetFiles(@"D:\批量测试图像\", "*.*", SearchOption.AllDirectories);
//for (int j = 0; j < 250; j++)
//{
// ParallelOptions po = new ParallelOptions();
// po.MaxDegreeOfParallelism = 2;
// Parallel.ForEach(fileNames, po, fn =>
// {
// EyemLib.eyemReadImageTool(fn);
// });
// Console.Write("请按任意键继续。。。");
//}
//EyemLib.eyemTest2(fileNames);
foreach (var item in fileNames)
for (int j = 0; j < 1250; j++)
{
EyemLib.eyemReadImageTool(item);
ParallelOptions po = new ParallelOptions();
po.MaxDegreeOfParallelism = 1;
Parallel.ForEach(fileNames, po, fn =>
{
EyemLib.eyemReadImageTool(fn);
});
Console.Write("请按任意键继续。。。");
}
//foreach (var item in fileNames)
//{
// EyemLib.eyemReadImageTool(item);
//}
//for (int i = 0; i < 1; i++)
//{
// EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\cap5.mp4");
......
......@@ -50,6 +50,9 @@
<ItemGroup>
<Compile Include="EyemLib.cs" />
<Compile Include="EyemLibDemo.cs" />
<Compile Include="log4cpp\ILog4CPP.cs" />
<Compile Include="log4cpp\Log4CPPBase.cs" />
<Compile Include="log4cpp\LogManager.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
......
#define HAS_READERWRITELOCK
using System;
using System.Threading;
namespace eyemLib_Sharp.log4cpp
{
interface ILog4CPP
{
/// <summary>
/// 记录日志
/// </summary>
/// <param name="text">日志内容</param>
void WriteLog(string text);
string[] GetExistLogFileNames();
}
/// <summary>
/// 生成日志模式
/// </summary>
public enum GenerateMode
{
/// <summary>
/// 按每分钟生成日志文件
/// </summary>
ByEveryMinitues = 0,
/// <summary>
/// 按每个小时生成日志文件
/// </summary>
ByEveryHour = 1,
/// <summary>
/// 按每天生成日志文件
/// </summary>
ByEveryDay = 2,
}
public enum CreateFileMode
{
/// <summary>
/// 生成.csv文件
/// </summary>
CSV,
/// <summary>
/// 生成.txt文件
/// </summary>
TXT
}
public sealed class ReaderWriteLock
{
public ReaderWriteLock()
{
m_lock = new System.Threading.ReaderWriterLock();
}
public void EnterReaderLock()
{
#if HAS_READERWRITELOCK
m_lock.AcquireReaderLock(-1);
#else
System.Threading.Monitor.Enter(this);
#endif
}
public void ReleaseReaderLock()
{
#if HAS_READERWRITELOCK
m_lock.ReleaseReaderLock();
#else
System.Threading.Monitor.Exit(this);
#endif
}
public void EnterWriterLock()
{
#if HAS_READERWRITELOCK
m_lock.AcquireWriterLock(-1);
#else
System.Threading.Monitor.Enter(this);
#endif
}
public void ReleaseWriterLock()
{
#if HAS_READERWRITELOCK
m_lock.ReleaseWriterLock();
#else
System.Threading.Monitor.Exit(this);
#endif
}
#if HAS_READERWRITELOCK
private System.Threading.ReaderWriterLock m_lock;
#endif
}
}
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Text;
using System.Threading;
namespace eyemLib_Sharp.log4cpp
{
public abstract class Log4CPPBase : IDisposable
{
public Log4CPPBase()
{
m_FileLock = new ReaderWriteLock();
m_vec4Write = new ConcurrentQueue<string>();
ThreadPool.QueueUserWorkItem(new WaitCallback(Write), null);
}
private ReaderWriteLock m_FileLock;//文件锁
private ConcurrentQueue<string> m_vec4Write;
private CreateFileMode m_fileMode;
private int m_WriteStatus = 0;
//添加日志
public void WriteLog(string text)
{
m_vec4Write.Enqueue(text);
}
//写日志
private void Write(object obj)
{
while (true)
{
if (m_vec4Write.Count > 0)
{
string text = "";
m_vec4Write.TryDequeue(out text);
if (Interlocked.CompareExchange(ref m_WriteStatus, 1, 0) == 0)
{
WriteLogToFile(text);
}
}
Thread.Sleep(1);
}
}
protected virtual string GetLogFilePath()
{
return string.Empty;
}
private void WriteLogToFile(string text)
{
try
{
//进入文件锁
m_FileLock.EnterWriterLock();
//获取文件名
string logFullPath = GetLogFilePath();
if (!string.IsNullOrEmpty(logFullPath))
{
StreamWriter sw = null;
try
{
sw = new StreamWriter(logFullPath, true, Encoding.UTF8);
if (text != null)
{
sw.WriteLine(text);
sw.Flush();
}
}
catch (Exception) { }
finally
{
if (sw != null)
{
sw.Close();
sw.Dispose();
sw = null;
}
m_FileLock.ReleaseWriterLock();
}
}
}
catch (Exception) { }
finally
{
Interlocked.Exchange(ref m_WriteStatus, 0);
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);//防止Finalize调用
}
private bool m_disposed = false;//标识资源是否被释放过
protected virtual void Dispose(bool disposing)
{
if (!m_disposed)
{
if (disposing)
{
//释放托管资源
if (m_FileLock != null)
{
m_FileLock = null;
}
}
//释放非托管资源
m_disposed = true;
}
}
~Log4CPPBase()
{
Dispose(false);
}
}
}
using System;
namespace eyemLib_Sharp.log4cpp
{
public class LogManager : Log4CPPBase, ILog4CPP
{
public LogManager(string filepath, string filename, GenerateMode generateMode = GenerateMode.ByEveryHour)
{
m_filePath = filepath;
m_fileName = filename;
m_generateMode = generateMode;
}
/// <summary>
/// 文件的路径
/// </summary>
private string m_filePath = string.Empty;
/// <summary>
/// 文件名称
/// </summary>
private string m_fileName = string.Empty;
private GenerateMode m_generateMode = GenerateMode.ByEveryHour;
protected override string GetLogFilePath()
{
if (string.IsNullOrEmpty(m_filePath)) return string.Empty;
switch (m_generateMode)
{
case GenerateMode.ByEveryMinitues:
return m_filePath + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分") + m_fileName + ".txt";
case GenerateMode.ByEveryHour:
return m_filePath + DateTime.Now.ToString("yyyy年MM月dd日HH时") + m_fileName + ".txt";
case GenerateMode.ByEveryDay:
return m_filePath + DateTime.Now.ToString("yyyy年MM月dd日") + m_fileName + ".txt";
default: return string.Empty;
}
}
public string[] GetExistLogFileNames()
{
if (!string.IsNullOrEmpty(m_filePath))
{
return System.IO.Directory.GetFiles(m_filePath, "*.txt");
}
else
{
return new string[] { };
}
}
}
}
......@@ -18,15 +18,43 @@ void setLogCallback(TCallback cb)
}
}
int killProcessID = -1;
void main()
void setSkipProcessID(int pid)
{
killProcessID = pid;
}
static char *get_option()
{
return NULL;
}
Logger logger;
int main(int argc, char **argv)
{
char* filename = "D:\\Matlab测试图像\\circle_plate_04.png";
cv::Mat src = cv::imread(filename, cv::IMREAD_UNCHANGED);
if (src.empty()) {
return;
logger.t("图像文件不存在!");
return 0;
}
return;
EyemRect tpRoi;
tpRoi.iXs = tpRoi.iYs = 50;
tpRoi.iWidth = src.cols; tpRoi.iHeight = src.rows;
EyemImage image;
image.iChannels = src.channels(); image.iDepth = 0; image.iHeight = src.rows; image.iWidth = src.cols; image.vpImage = src.data;
//获取结果图像
EyemImage tpDstImg;
int flag = eyemAchvTemplateImage(image, tpRoi, &tpDstImg);
//加载模板
IntPtr tpModelID = NULL;
eyemInitModel("D:\\模板文件", &tpModelID);
return 0;
}
\ No newline at end of file
......@@ -864,6 +864,9 @@ extern "C" {
}
#endif
//跳过某接口执行
extern "C" __declspec(dllexport) void setSkipProcessID(int pid);
// 日志回调定义
typedef void(__stdcall*TCallback)(const char* msg);
......
此文件类型无法预览
......@@ -16,7 +16,9 @@ constexpr double c = PI / 180.;
std::mutex mtx_misc;
Logger logger;
extern Logger logger;
extern int killProcessID;
#endif/* __EYEM_MISC_H */
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!