public int CompareFile(string fileName, bool fullScan = false) { ImageInfo isrc = new ImageInfo(); if (!isrc.SetData(fileName)) { return(-1); } //ハッシュレベルで一致ならそのまま返却 if (!fullScan) { int itp = CompareHash(isrc); if (itp >= 0) { isrc.Dispose(); return(itp); } } int idx = -1; double maxVal = 0; Mat src = Mat.FromStream(isrc.DataStream, ImreadModes.AnyColor); foreach (ImageInfo ii in ImageStack) { OpenCvSharp.Mat m = OpenCvSharp.Mat.FromStream(ii.DataStream, ImreadModes.AnyColor); OpenCvSharp.Mat roi = m[0, src.Height > m.Height ? m.Height : src.Height, 0, src.Width > m.Width ? m.Width : src.Width]; OpenCvSharp.Mat res = new Mat(); Cv2.MatchTemplate(src, roi, res, TemplateMatchModes.CCoeffNormed); double min, max; Cv2.MinMaxLoc(res, out min, out max); if (maxVal < max) { idx = ii.id; maxVal = max; } if (!fullScan && max > thresh) { src.Dispose(); return(ii.id); } roi.Dispose(); m.Dispose(); } src.Dispose(); isrc.Dispose(); return(idx); }
/// <summary> /// Image pipeline phase 4: Invoke the user-provided delegate (for example, to display the result in a UI) /// </summary> public static void SavePipelinedImages(IEnumerable <ImageInfo> filteredImages, CancellationTokenSource cts) { int count = 1; var token = cts.Token; ImageInfo info = null; try { foreach (ImageInfo infoTmp in filteredImages) { info = infoTmp; if (token.IsCancellationRequested) { break; } ImageLogic.SaveImage(info, count); count = count + 1; info = null; } } catch (Exception e) { cts.Cancel(); if (!(e is OperationCanceledException)) { throw; } } finally { info?.Dispose(); } }
public bool Convert(FilterRequest req) { string source = req.Current.LocalPath; Uri dest = req.TempUri(Path.GetExtension(source)); using (ImageFile img = ImageFile.Create(source)) { using (Pixbuf pixbuf = img.Load()) { using (ImageInfo info = new ImageInfo(pixbuf)) { MemorySurface surface = new MemorySurface(Format.Argb32, pixbuf.Width, pixbuf.Height); Context ctx = new Context(surface); ctx.Matrix = info.Fill(info.Bounds, angle); Pattern p = new SurfacePattern(info.Surface); ctx.Source = p; ctx.Paint(); ((IDisposable)ctx).Dispose(); p.Destroy(); using (Pixbuf result = CairoUtils.CreatePixbuf(surface)) { using (Stream output = File.OpenWrite(dest.LocalPath)) { img.Save(result, output); } } surface.Flush(); info.Dispose(); req.Current = dest; return(true); } } } }
public void TestDeepCopyCOns() { ImageInfo from = new ImageInfo(PATH_160_120_RGB); from.getHist(); from.getImb(); from.getImF(); ImageInfo to = new ImageInfo(from); from.Dispose(); from = null; Debug.WriteLine("B:{0},F:{1}, W:{2}, H:{3}, HISTMEAN:{4}, P:{5}", to.getImb().Length, to.getImF().Length, to.Width, to.Height, to.getHist().Mean, to.getPath()); }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing) { _toolImages.Dispose(); if (ImageInfo != null) { ImageInfo.Disposed = true; ImageInfo.Dispose(); } if (components != null) { components.Dispose(); } } base.Dispose(disposing); }
/// <summary> /// Image pipeline phase 3: Filter images (give them a speckled appearance by adding Gaussian noise) /// </summary> public static void FilterPipelinedImages( BlockingCollection <ImageInfo> thumbnailImages, BlockingCollection <ImageInfo> filteredImages, CancellationTokenSource cts) { ImageInfo info = null; try { var token = cts.Token; foreach (ImageInfo infoTmp in thumbnailImages.GetConsumingEnumerable()) { info = infoTmp; if (token.IsCancellationRequested) { break; } ImageLogic.FilterImage(info); filteredImages.Add(info, token); info = null; } } catch (Exception e) { cts.Cancel(); if (!(e is OperationCanceledException)) { throw; } } finally { filteredImages.CompleteAdding(); if (info != null) { info.Dispose(); } } }
/// <summary> /// Image pipeline phase 1: Load images from disk and put them a queue. /// </summary> public static void LoadPipelinedImages(IEnumerable <string> fileNames, string sourceDir, BlockingCollection <ImageInfo> original, CancellationTokenSource cts) { int count = 0; var token = cts.Token; ImageInfo info = null; try { foreach (var fileName in fileNames) { if (token.IsCancellationRequested) { break; } info = ImageLogic.LoadImage(fileName, sourceDir, count); original.Add(info, token); count += 1; info = null; } } catch (Exception e) { // in case of exception, signal shutdown to other pipeline tasks cts.Cancel(); if (!(e is OperationCanceledException)) { throw; } } finally { original.CompleteAdding(); if (info != null) { info.Dispose(); } } }