// Todo: Make into array returning task public static void Run3(Scan scan) { //Scanning = true; var deltas = new float[FEATURE_COUNT_LIMIT]; using (var fileImageBase = new MagickImage(scan.CurrentFrame.Bitmap)) { Parallel.ForEach(CompiledFeatures.CWatchZones, (CWatchZone) => { var thumbGeo = CWatchZone.MagickGeometry; using (var fileImageCropped = fileImageBase.Clone(CWatchZone.MagickGeometry)) { Parallel.ForEach(CWatchZone.CWatches, (CWatcher) => { fileImageCropped.ColorSpace = CWatcher.ColorSpace; // Can safely change since it doesn't directly affect pixel data. using (var fileImageComposed = GetComposedImage(fileImageCropped, CWatcher.Channel)) { if (CWatcher.Equalize) { fileImageComposed.Equalize(); } if (CWatcher.IsStandardCheck) { Parallel.ForEach(CWatcher.CWatchImages, (CWatchImage) => { using (var deltaImage = CWatchImage.MagickImage.Clone()) using (var fileImageCompare = fileImageComposed.Clone()) { if (CWatchImage.HasAlpha) { fileImageCompare.Composite(deltaImage, CompositeOperator.CopyAlpha); } var imageDelta = (float)deltaImage.Compare(fileImageCompare, CWatcher.ErrorMetric); deltas[CWatchImage.Index] = imageDelta; /* * if (CurrentIndex % 300 == 0 && CWatchImage.Index == 0) * { * fileImageCompare.Write(@"E:\test2.png"); * deltaImage.Write(@"E:\test3.png"); * fileImageComposed.Write(@"E:\test4.png"); * fileImageCropped.Write(@"E:\test5.png"); * fileImageBase.Write(@"E:\test6.png"); * } */ } }); } else if (CWatcher.IsDuplicateFrameCheck) { using (var deltaImagePre = new MagickImage((Bitmap)scan.PreviousFrame.Bitmap.Clone())) using (var fileImageCompare = (MagickImage)fileImageComposed.Clone()) { if (NeedExtent) { deltaImagePre.Extent(TrueCropGeometry.ToMagick(), Gravity.Northwest, MagickColor.FromRgba(0, 0, 0, 0)); } else { deltaImagePre.Crop(TrueCropGeometry.ToMagick(), Gravity.Northwest); } deltaImagePre.RePage(); deltaImagePre.Crop(thumbGeo, Gravity.Northwest); deltaImagePre.ColorSpace = CWatcher.ColorSpace; using (var deltaImage = GetComposedImage(deltaImagePre, CWatcher.Channel)) { if (CWatcher.Equalize) { fileImageCompare.Equalize(); } var imageDelta = (float)deltaImage.Compare(fileImageCompare, CWatcher.ErrorMetric); deltas[31] = imageDelta; } } } } }); } }); } Scanning = false; deltas[19] = 456.789F; Interlocked.Exchange(ref Program.floatArray, deltas); Interlocked.Exchange(ref Program.timeDelta, scan.TimeDelta); Interlocked.Increment(ref Program.count); scan.Clean(); }