private void button6_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { Vector3[,] val = Procedurs.Medium(openFileDialog1.FileName); Morf morf = Morf.GenerateKMean(val, 5); morf.RemoveEmptyRegions(); List <Vector3> avrs = new List <Vector3>(); for (int i = 0; i < morf.regions.Count; i++) { avrs.Add(morf.regions[i].GetAverage(val)); } float[,] temp = new float[val.GetLength(0), val.GetLength(1)]; float[,] temp2 = new float[val.GetLength(0), val.GetLength(1)]; VideoProcessig videoProcessig = new VideoProcessig(openFileDialog1.FileName, (map) => { val.WriteRGB(map); Procedurs.MorfSubtract(morf, avrs, val, temp); temp2.ForEach(() => 0); Procedurs.BlockSum(temp, temp2, 5); temp2.RegMaximum(); return(temp2); }); videoProcessig.Show(); } }
private void button12_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { Image <Gray, Byte> last = null; Image <Gray, float> flowX = null; Image <Gray, float> flowY = null; Image <Gray, float> draw = null; Vector3[,] val = Procedurs.Medium(openFileDialog1.FileName); Morf morf = Morf.GenerateKMean(val, 5); morf.RemoveEmptyRegions(); List <Vector3> avrs = new List <Vector3>(); for (int i = 0; i < morf.regions.Count; i++) { avrs.Add(morf.regions[i].GetAverage(val)); } float[,] temp = new float[val.GetLength(0), val.GetLength(1)]; VideoProcessig videoProcessig = new VideoProcessig(openFileDialog1.FileName, (map) => { val.WriteRGB(map); Procedurs.MorfSubtract(morf, avrs, val, temp); Image <Gray, byte> image = new Image <Gray, byte>(map.Size); temp.RegMaximum(); for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { Gray g = image[y, x]; g.Intensity = temp[x, y] * 255; image[y, x] = g; } } if (last == null) { last = image; flowX = new Image <Gray, float>(map.Size); flowY = new Image <Gray, float>(map.Size); draw = new Image <Gray, float>(map.Size); } else { CvInvoke.CalcOpticalFlowFarneback(last, image, flowX, flowY, 0.5, 3, 10, 3, 5, 1.5, Emgu.CV.CvEnum.OpticalflowFarnebackFlag.Default); last = image; } double max = 0; for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { Gray g = draw[y, x]; double value = Math.Abs(flowX[y, x].Intensity) + Math.Abs(flowY[y, x].Intensity); max = Math.Max(value, max); g.Intensity = value; draw[y, x] = g; } } for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { Gray g = draw[y, x]; g.Intensity /= max; g.Intensity *= 255; draw[y, x] = g; } } var result = draw.Bitmap; return(result); }); videoProcessig.Show(); } }