} //the thresholds, per grid public override void Compare(ByteWrapper image1, ByteWrapper image2) { var bm1 = new BitmapWrapper(ImageConvert.ReturnBitmap(image1.bytes)); var bm2 = new BitmapWrapper(ImageConvert.ReturnBitmap(image2.bytes)); PixelMatrix matrix = new PixelMatrix(); if (settings.searchHeight > 0) { matrix.SearchHeight = settings.searchHeight; } if (settings.searchWidth > 0) { matrix.SearchWidth = settings.searchWidth; } if (settings.linkCompare) { matrix.LinkCompare = true; } matrix.GridSystemOn = true; matrix.Populate(bm1, bm2); double sumChangedPixels = matrix.SumChangedPixels; //keep adding for threshold calculation, set the threshold, or monitor if (ThresholdSet) { //do the motion detection for (int i = 0; i < ThresholdImage.Columns.Count; i++) { for (int n = 0; n < ThresholdImage.Columns[i].grids.Count; n++) { if (matrix.imageGrid.Columns[i].grids[n].change > ThresholdImage.Columns[i].grids[n].threshold) { OnMotion(image1, image2, ThresholdImage.GridNumber(i, n)); return; } } } } else if (!ThresholdSet && gridImages.Count < ControlImageNumber) { gridImages.Add(matrix.imageGrid); //keep adding for the later threshold calculation } else { SetThreshold(); //enough images received to set the threshold and start monitoring } Comparison = matrix.Comparator; //clean up the memory matrix.Dispose(); bm1.bitmap.Dispose(); bm2.bitmap.Dispose(); bm1 = null; bm2 = null; }//Compare
public override void Compare(ByteWrapper image1, ByteWrapper image2) { var bm1 = new BitmapWrapper(ImageConvert.ReturnBitmap(image1.bytes)); bm1.sequenceNumber = logging.imagesReceived - 2; var bm2 = new BitmapWrapper(ImageConvert.ReturnBitmap(image2.bytes)); bm2.sequenceNumber = logging.imagesReceived - 1; PixelMatrix matrix = new PixelMatrix(); matrix.LinkCompare = settings.linkCompare; if (settings.searchHeight > 0) { matrix.SearchHeight = settings.searchHeight; } if (settings.searchWidth > 0) { matrix.SearchWidth = settings.searchWidth; } if (settings.horizontalPixelsToSkip > 0) { matrix.WidthSearchOffset = settings.horizontalPixelsToSkip + 1; } if (settings.verticalPixelsToSkip > 0) { matrix.WidthSearchOffset = settings.verticalPixelsToSkip + 1; } if (settings.linkCompare && Comparison != null) { matrix.Populate(Comparison, bm2); } else { matrix.Populate(bm1, bm2); } double sumChangedPixels = matrix.SumChangedPixelsPositive; //keep adding for threshold calculation, set the threshold, or monitor if (ThresholdSet) { //now scanning, compare the two images and see what the difference is if (sumChangedPixels > pixelChangeThreshold) { OnMotionAsync(image1, image2); } } else if (!ThresholdSet && pixelChange.Count < ControlImageNumber) { pixelChange.Add(sumChangedPixels); } else { SetThreshold(); //enough images received to set the threshold and start monitoring } Comparison = matrix.Comparator; if (logging.LoggingOn && logging.matrices != null) { logging.matrices.Add(matrix); } //clean up the memory matrix.Dispose(); bm1.bitmap.Dispose(); bm2.bitmap.Dispose(); bm1 = null; bm2 = null; }//Compare