/// <summary> /// Returns the millseconds to turn a in memory JPEG into a Bitmap /// </summary> /// <returns></returns> public double MsToBitmap(JPEG jpeg) { jpeg.Bytes(); //gets the bytes into memory Stopwatch sw = new Stopwatch(); sw.Start(); BitmapWrapper wrapper = new BitmapWrapper(jpeg.ReturnBitmap()); sw.Stop(); return sw.Elapsed.TotalMilliseconds; }
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
public BitmapWrapperList(List<Bitmap> bitmaps) { list = new List<BitmapWrapper>(); for (int i = 0; i < bitmaps.Count; i++) { BitmapWrapper b = new BitmapWrapper(bitmaps[i]); b.pixelAnalysis.SumRGB(); list.Add(b); } SortByPixelTotal(); }
public ImageGrid ThresholdImage{get; private set;} //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 void HexToInt() { BitmapWrapper bm1 = new BitmapWrapper(@"d:\temp\analysis\640x480\test_0.jpg"); for(int i = 0; i < bm1.bitmap.Width; i++) { for(int n = 0; n < bm1.bitmap.Height; n++) { Int64 num1 = Int64.Parse(bm1.bitmap.GetPixel(i, n).Name, System.Globalization.NumberStyles.HexNumber); Int64 num2 = (bm1.bitmap.GetPixel(i, n).Name.HexToLong()); Assert.IsTrue(num1.Equals(num2)); } } }
public double TotalPixels(JPEG jpeg) { jpeg.Bytes(); //gets the bytes into memory BitmapWrapper wrapper = new BitmapWrapper(jpeg.ReturnBitmap()); return wrapper.bitmap.Height * wrapper.bitmap.Width; }
public void TotalPixelsVersusSumPixel() { BitmapWrapper bitmap = new BitmapWrapper(@"d:\temp\analysis\multiple_movement\test_266.jpg"); Assert.IsFalse(bitmap.pixelAnalysis.SumPixelHex == bitmap.pixelAnalysis.totalPixelColors); }
}//Populate /// <summary> /// Takes a PixelMatrix as image 1, which is expected to have a numerical colour /// in each cell /// </summary> /// <param name="comparision"></param> /// <param name="image2"></param> public void Populate(List<PixelColumn> comparision, BitmapWrapper image2) { this.Comparision = comparision; this.image2 = image2; DoPopulate(); }
public PixelMatrix(BitmapWrapper image1, BitmapWrapper image2) { Populate(image1, image2); }
}//Populate /// <summary> /// Compares two images, pixel by pixel, with the analysis about the difference between pixels /// pixel by pixel analysis is set into pixelColumns. GridColumns are also populated if GridSystemOn /// </summary> /// <param name="image1"></param> /// <param name="image2"></param> public void Populate(BitmapWrapper image1, BitmapWrapper image2) { this.image1 = image1; this.image2 = image2; DoPopulate(); }//Populate