public static void Main(string[] args) { //红黑树 SortedDictionary <string, string> rbTree = new SortedDictionary <string, string>(); DirectoryHold.ResetCurrentDir(); NLogHelper.Info(GuidUtils.GetGuid32()); NLogHelper.Trace("Trace"); NLogHelper.Debug("Debug"); NLogHelper.Info("Info"); NLogHelper.Warn("Warn"); NLogHelper.Error("Error"); NLogHelper.Fatal("Fatal"); }
/// <summary> /// 自动加载log4net.config /// </summary> public static bool Init(Action <Exception> exceptionHandler = null) { try { if (isInited) { return(true); } //获取应用程序的目录,并查找log4net.config文件 //string dir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; string configFile = DirectoryHold.ResolveFile("log4net.config"); ILoggerRepository repository = LogManager.CreateRepository("CmluRepository");//该方法如果已经存在同名Repository,则抛出异常 if (!string.IsNullOrWhiteSpace(configFile)) { FileInfo file = new FileInfo(configFile); log4net.Config.XmlConfigurator.ConfigureAndWatch(repository, file); logger = log4net.LogManager.GetLogger(repository.Name, LOGGERNAME); isInited = true; return(true); } else { throw new Exception("未找到log4net.config配置文件"); } } catch (Exception ex) { if (exceptionHandler != null) { exceptionHandler(ex); } return(false); } }
static void Main(string[] args) { DirectoryHold.ResetAppDir(); NLogHelper.Info($"应用程序当前目录为:{Directory.GetCurrentDirectory()}"); Mat src = new Mat("Images/check1.jpg"); NLogHelper.Info("图片加载成功"); Bitmap bitmap = OpenCvSharpExample.ConvertToBitmap(src); Bitmap result1 = OpenCvSharpExample.EliminateYellow(bitmap); Mat tgt1 = OpenCvSharpExample.ConvertToMat(result1); Mat tgt2 = OpenCvSharpExample.ConvertToMat(OpenCvSharpExample.EliminateBlue(bitmap)); Mat tgt3 = OpenCvSharpExample.ConvertToMat(OpenCvSharpExample.ColorHighPenetrate(bitmap, 0.4)); Mat tgt4 = OpenCvSharpExample.ConvertToMat(OpenCvSharpExample.Gray(bitmap)); using (Window window = new Window("原图", src)) { using (Window window2 = new Window("有机物", tgt1)) { using (Window window3 = new Window("无机物", tgt2)) { using (Window window4 = new Window("高光", tgt3)) { using (Window window5 = new Window("黑白", tgt4)) { NLogHelper.Info("图片显示成功"); Cv2.WaitKey(); } } } } } //VideoCapture videoCapture = new VideoCapture(CaptureDevice.Any); //int frameWidth = ConfigUtils.GetInteger("FrameWidth", 0); //int frameHeight = ConfigUtils.GetInteger("FrameHeight", 0); //NLogHelper.Trace(String.Format("设置图像的大小 width={0} height={1}.",frameWidth,frameHeight)); ////videoCapture.Set(CaptureProperty.FrameWidth, 1280); ////videoCapture.Set(CaptureProperty.FrameHeight, 720); ////videoCapture.Open(CaptureDevice.Any); //if (frameWidth > 0 && frameHeight > 0) //{ // videoCapture.FrameWidth = frameWidth; // videoCapture.FrameHeight = frameHeight; //} //NLogHelper.Trace(videoCapture.Fps + "" + videoCapture.IsOpened()+videoCapture.CaptureType+" width="+videoCapture.FrameWidth + " height="+videoCapture.FrameHeight); //double fps = videoCapture.Fps; //fps = fps > 1 ? fps : 25; //int sleepTime = (int)Math.Round(1000 / fps); //sleepTime = 1500; //const string saveDir = "Pics"; //using (Window window = new Window("capture")) //{ // using (Mat image = new Mat()) // { // while (true) // { // videoCapture.Read(image); // if (image.Empty()) // { // Thread.Sleep(100); // continue; // } // window.ShowImage(image); // bool isNeedToSave = BlobUtils.IsNeedToSave(image); // if (isNeedToSave) // { // if (!Directory.Exists(saveDir)) // { // Directory.CreateDirectory(saveDir); // } // string dir = Path.Combine(saveDir, DateTime.Now.ToString("yyyyMMdd")); // if (!Directory.Exists(dir)) // { // Directory.CreateDirectory(dir); // } // string fileName = Path.Combine(dir, DateTime.Now.ToString("HHmmss")+"_"+Guid.NewGuid().ToString() + ".jpg"); // image.SaveImage(fileName); // } // Cv2.WaitKey(sleepTime); // //Console.ReadLine(); // } // } //} }