public void PixelMatrix_skips() { try { List <int> dimensions = ReturnPixelJumps(); Stopwatch sw = new Stopwatch(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"f:\temp\runtime\pixelmatrixanalysis_jumps.txt", true)) { for (int i = 0; i < dimensions.Count; i++) { for (int n = 0; n < 200; n++) { BitmapWrapper bm1 = new BitmapWrapper(@"F:\temp\analysis\640x480\test_0.jpg"); BitmapWrapper bm2 = new BitmapWrapper(@"F:\temp\analysis\640x480\test_1.jpg"); sw.Restart(); PixelMatrix matrix = new PixelMatrix(); matrix.WidthSearchOffset = dimensions[i]; matrix.Populate(bm1, bm2); sw.Stop(); file.WriteLine(i + " - " + n + " - " + " grid - " + sw.Elapsed.TotalMilliseconds); } } } Assert.IsTrue(true); } catch { Assert.IsTrue(false); } }
public void Motion2aMultipleCompare() { try { //images in memory when sent to the ByteWrapper image1 = ImageConvert.ReturnByteWrapper(@"F:\temp\analysis\640x480\test_0.jpg"); ByteWrapper image2 = ImageConvert.ReturnByteWrapper(@"F:\temp\analysis\640x480\test_1.jpg"); PixelMatrix dummy = new PixelMatrix(); dummy.LinkCompare = true; dummy.Populate(new BitmapWrapper(ImageConvert.ReturnBitmap(image1.bytes)), new BitmapWrapper(ImageConvert.ReturnBitmap(image2.bytes))); MotionSensor_2a motion = new MotionSensor_2a(); motion.ThresholdSet = true; motion.settings.linkCompare = true; motion.Comparison = dummy.Comparision; motion.ImageCreated(image1, EventArgs.Empty); motion.ImageCreated(image2, EventArgs.Empty); motion.ImageCreated(image1, EventArgs.Empty); motion.ImageCreated(image2, EventArgs.Empty); Assert.IsTrue(true); } catch { Assert.IsTrue(false); } }
} //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 Grid() { PixelMatrix matrix = new PixelMatrix(); matrix.GridSystemOn = true; matrix.Populate(@"d:\temp\MotionSensor\2.2\test_101.jpg", @"d:\temp\MotionSensor\2.2\test_128.jpg"); Assert.IsNotNull(matrix.imageGrid.Columns); Assert.IsTrue(matrix.imageGrid.Columns.Count == 4); Assert.IsTrue(matrix.imageGrid.Columns[0].grids.Count == 4); Assert.IsTrue(matrix.imageGrid.Columns[1].grids.Count == 4); Assert.IsTrue(matrix.imageGrid.Columns[2].grids.Count == 4); Assert.IsTrue(matrix.imageGrid.Columns[3].grids.Count == 4); }
public void Motion2aSubequent() { try { List <int> dimensions = ReturnDimensions(); Stopwatch sw = new Stopwatch(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"f:\temp\runtime\motion_analysis.txt", true)) { for (int i = 0; i < dimensions.Count; i++) { for (int n = 0; n < 200; n++) { //images in memory when sent to the ByteWrapper image1 = ImageConvert.ReturnByteWrapper(@"F:\temp\analysis\640x480\test_0.jpg"); image1.sequenceNumber = i; ByteWrapper image2 = ImageConvert.ReturnByteWrapper(@"F:\temp\analysis\640x480\test_1.jpg"); image2.sequenceNumber = i; PixelMatrix dummy = new PixelMatrix(); dummy.LinkCompare = true; dummy.SearchWidth = dimensions[i]; dummy.Populate(new BitmapWrapper(ImageConvert.ReturnBitmap(image1.bytes)), new BitmapWrapper(ImageConvert.ReturnBitmap(image2.bytes))); sw.Restart(); MotionSensor_2a motion = new MotionSensor_2a(); motion.ThresholdSet = true; motion.settings.linkCompare = true; motion.settings.searchWidth = dimensions[i]; motion.Comparison = dummy.Comparision; motion.ImageCreated(image1, EventArgs.Empty); motion.ImageCreated(image2, EventArgs.Empty); motion.ImageCreated(image1, EventArgs.Empty); motion.ImageCreated(image2, EventArgs.Empty); sw.Stop(); file.WriteLine(i + " - " + n + " - " + " no grid - " + sw.Elapsed.TotalMilliseconds); } } } Assert.IsTrue(true); } catch { Assert.IsTrue(false); } }
public void GridPopulation() { PixelMatrix matrix = new PixelMatrix(); matrix.GridSystemOn = true; matrix.Populate(@"d:\temp\MotionSensor\2.2\test_101.jpg", @"d:\temp\MotionSensor\2.2\test_128.jpg"); for (int i = 0; i < matrix.imageGrid.Columns.Count; i++) { for (int n = 0; n < matrix.imageGrid.Columns[i].grids.Count; n++) { Assert.IsTrue(matrix.imageGrid.Columns[i].grids[n].change != 0); } } }//GridPopulation
public void LinqTesting() { try { List <int> dimensions = ReturnDimensions(); Stopwatch sw = new Stopwatch(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"f:\temp\runtime\linqanalysis.txt", true)) { for (int m = 0; m < dimensions.Count; m++) { for (int i = 0; i < 30; i++) { //do the minimum BitmapWrapper bm1 = new BitmapWrapper(@"F:\temp\analysis\640x480\test_0.jpg"); BitmapWrapper bm2 = new BitmapWrapper(@"F:\temp\analysis\640x480\test_1.jpg"); PixelMatrix matrix = new PixelMatrix(); matrix.SearchWidth = dimensions[m]; matrix.Populate(bm1, bm2); //LINQ sw.Restart(); double min = matrix.MinChanged; sw.Stop(); file.WriteLine("LINQ - min - " + m + " - " + sw.Elapsed.TotalMilliseconds); sw.Restart(); double max = matrix.MaxChanged; sw.Stop(); file.WriteLine("LINQ - max - " + m + " - " + sw.Elapsed.TotalMilliseconds); sw.Restart(); double sum = matrix.SumChangedPixels; sw.Stop(); file.WriteLine("LINQ - sum - " + m + " - " + sw.Elapsed.TotalMilliseconds); //ITERATION sw.Restart(); double min2 = 0; for (int n = 0; n < matrix.Columns.Count; n++) { for (int k = 0; k < matrix.Columns[n].Cells.Count; k++) { if (matrix.Columns[n].Cells[k].change < min2) { min2 = matrix.Columns[n].Cells[k].change; } } } sw.Stop(); file.WriteLine("ITERATION - min - " + m + " - " + sw.Elapsed.TotalMilliseconds); sw.Restart(); double max2 = 0; for (int n = 0; n < matrix.Columns.Count; n++) { for (int k = 0; k < matrix.Columns[n].Cells.Count; k++) { if (matrix.Columns[n].Cells[k].change > max2) { max2 = matrix.Columns[n].Cells[k].change; } } } sw.Stop(); file.WriteLine("ITERATION - max - " + m + " - " + sw.Elapsed.TotalMilliseconds); sw.Restart(); double sum2 = 0; for (int n = 0; n < matrix.Columns.Count; n++) { for (int k = 0; k < matrix.Columns[n].Cells.Count; k++) { sum2 += matrix.Columns[n].Cells[k].change; } } sw.Stop(); file.WriteLine("ITERATION - sum - " + m + " - " + sw.Elapsed.TotalMilliseconds); } } } Assert.IsTrue(true); } catch { Assert.IsTrue(false); } }
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