public Frame Process(Frame[] input) { Frame result = new Frame(input[0].Size); AnnotatedFrame frameWithLogs = (AnnotatedFrame)input[0]; /* Create Bitmap to draw the vectors on */ using (Bitmap drawableFrame = new Bitmap(input[0].Size.Width, input[0].Size.Width)) { for (int x = 0; x < input[0].Size.Width; x++) { for (int y = 0; y < input[0].Size.Height; y++) { Rgb pixel = input[0][x, y]; drawableFrame.SetPixel(x, y, Color.FromArgb(pixel.R, pixel.G, pixel.B)); } } /* Draw the movementvector of each macroblock */ for (int x = 0; x < (input[0].Size.Width / 16); x++) { for (int y = 0; y < (input[0].Size.Height / 16); y++) { DrawVector(drawableFrame, x * 16, y * 16, GetScaledVector(14.0, frameWithLogs.Decisions[x, y].Movement)); } } /* Print the frame with vectors into the resultframe */ for (int x = 0; x < input[0].Size.Width; x++) { for (int y = 0; y < input[0].Size.Height; y++) { Rgb pixel = new Rgb(drawableFrame.GetPixel(x, y).R, drawableFrame.GetPixel(x, y).G, drawableFrame.GetPixel(x, y).B); result[x, y] = pixel; } } } return(result); }
private void LoadImagesEventHandler(string path) { var frame = new AnnotatedFrame(path); if (frame != null) { _eventAggregator.GetEvent <LoadFrameEvent>().Publish(frame); } }
private void LoadFrameEventHandler(AnnotatedFrame annotatedFrame) { Mat frame = annotatedFrame.GetFrame(); if (frame != null && !frame.IsEmpty) { FrameBitmapSource = frame.Bitmap.ToBitmapSource(); FrameBitmapSource.Freeze(); } }
/// <summary> /// Generates an AnnotatedFrame with randomly filled Data and the given Macroblock decisions. /// </summary> /// <returns> An annotated Frame with random Data and the given Macroblock decisions.</returns> public static AnnotatedFrame GenerateAnnFrame(MacroblockDecision[,] decisions) { var testSize = new YuvKA.VideoModel.Size(8, 8); var output = new AnnotatedFrame(testSize, decisions); for (int x = 0; x < testSize.Width; x++) { for (int y = 0; y < testSize.Height; y++) { output[x, y] = new Rgb((byte)(x + y), (byte)(x + y), (byte)(x + y)); } } return(output); }
public Frame Process(Frame[] input) { AnnotatedFrame frameWithLogs = (AnnotatedFrame)input[0]; Frame result = new Frame(input[0].Size); for (int x = 0; x < input[0].Size.Width; x++) { for (int y = 0; y < input[0].Size.Height; y++) { /* Make result black and white first to emphasize color highlighting */ byte average = (byte)((input[0][x, y].R + input[0][x, y].G + input[0][x, y].B) / 3); result[x, y] = new Rgb(average, average, average); result[x, y] = GetMaskedPixel(result[x, y], x + 1, y + 1, frameWithLogs.Decisions[x / 16, y / 16].PartitioningDecision); } } return(result); }
private void PlayVideo() { //open capture if not open if (_video.State == VideoStates.Stopped) { _video.Open(); int totalFrameCount = _video.GetTotalFrameNumber(); _eventAggregator.GetEvent <TotalFrameNumberEvent>().Publish(totalFrameCount); } _video.State = VideoStates.Running; Task.Factory.StartNew(() => { //setup AnnotatedFrame frame = new AnnotatedFrame(); int interval = 1000 / _video.GetFPS(); int currentFramePos = _video.GetCurrentFrameNumber(); Stopwatch s = new Stopwatch(); s.Start(); //retrieve frames, and publish to the canvas while (frame != null && interval > 0 && _video.State == VideoStates.Running) { //read frame frame = _video.GetAnnotatedFrame(); //increment position currentFramePos++; if (frame != null) { _eventAggregator.GetEvent <LoadFrameEvent>().Publish(frame); _eventAggregator.GetEvent <CurrentFrameNumberEvent>().Publish(currentFramePos); } var el = s.Elapsed; Thread.Sleep(Math.Max((interval - (int)el.TotalMilliseconds), 0)); s.Reset(); } //stop _video if (_video.State == VideoStates.Running) { StopVideo(); } }); }
/// <summary> /// Calculates the Data by counting the number of IntraBlocks in the given frame. /// </summary> /// <param name="frame">The frame to be compared to the reference frame</param> /// <param name="reference">The frame against which the given frame is compared. This parameter is unnused.</param> public double Process(Frame frame, Frame reference) { double intraBlocks = 0.0; if (frame is AnnotatedFrame) { AnnotatedFrame annFrame = (AnnotatedFrame)frame; foreach (MacroblockDecision d in annFrame.Decisions) { if (d.PartitioningDecision == MacroblockPartitioning.Intra16x16 | d.PartitioningDecision == MacroblockPartitioning.Intra4x4 | d.PartitioningDecision == MacroblockPartitioning.Intra8x8 | d.PartitioningDecision == MacroblockPartitioning.IntraPCM) { intraBlocks++; } } intraBlocks /= annFrame.Decisions.Length; intraBlocks *= 100; } return(intraBlocks); }
/// <summary> /// Calculates the Data by computing the number /// of similar Encoderdecisions between two frames. /// </summary> /// <param name="frame">The frame to be compared to the reference frame</param> /// <param name="reference">The frame against which the given frame is compared</param> public double Process(Frame frame, Frame reference) { double difference = 0.0; if (frame is AnnotatedFrame && reference is AnnotatedFrame && frame.Size.Height == reference.Size.Height && frame.Size.Width == reference.Size.Width) { AnnotatedFrame annFrame = (AnnotatedFrame)frame; AnnotatedFrame annRef = (AnnotatedFrame)reference; for (int i = 0; i < annFrame.Decisions.GetLength(0); i++) { for (int j = 0; j < annFrame.Decisions.GetLength(1); j++) { if (annFrame.Decisions[i, j].PartitioningDecision == annRef.Decisions[i, j].PartitioningDecision) { difference++; } } } difference /= annFrame.Decisions.Length; difference *= 100; } return(difference); }
public void TestDiagramNode() { // Add Input Node for DiagramNode with 3 Outputs. AnonymousNode sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); Frame[] inputs = sourceNode.Process(null, 0); // Generate DiagramNode and add referencevideo. Node.Input reference = new Node.Input(); reference.Source = sourceNode.Outputs[0]; DiagramNode diaNode = new DiagramNode(); diaNode.ReferenceVideo = reference; diaNode.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. Node.Input video = new Node.Input(); video.Source = sourceNode.Outputs[1]; diaNode.Inputs.Add(video); Node.Input annVid = new Node.Input(); annVid.Source = sourceNode.Outputs[2]; diaNode.Inputs.Add(annVid); // Generate and add all GraphTypes to DiagramGraph once. DiagramGraph pixDiff = new DiagramGraph(); pixDiff.Video = video; pixDiff.Type = new PixelDiff(); DiagramGraph pseudoNoiseRatio = new DiagramGraph(); pseudoNoiseRatio.Video = video; pseudoNoiseRatio.Type = new PeakSignalNoiseRatio(); DiagramGraph inBlFreq = new DiagramGraph(); inBlFreq.Video = annVid; inBlFreq.Type = new IntraBlockFrequency(); DiagramGraph decDiff = new DiagramGraph(); decDiff.Video = annVid; decDiff.Type = new DecisionDiff(); DiagramGraph art = new DiagramGraph(); art.Video = video; art.Type = new Artifacts(); diaNode.Graphs.Add(pixDiff); diaNode.Graphs.Add(pseudoNoiseRatio); diaNode.Graphs.Add(inBlFreq); diaNode.Graphs.Add(decDiff); diaNode.Graphs.Add(art); diaNode.Process(inputs, 0); // Calculate expected results independently from DiagramGraph methods. double mse = 0.0; double pixDifference = 0.0; double intrablocks = 0.0; double artifacts = 0.0; for (int x = 0; x < inputs[0].Size.Width; x++) { for (int y = 0; y < inputs[0].Size.Height; y++) { pixDifference += Math.Abs(inputs[0][x, y].R - inputs[1][x, y].R) + Math.Abs(inputs[0][x, y].G - inputs[1][x, y].G) + Math.Abs(inputs[0][x, y].B - inputs[1][x, y].B); mse += Math.Pow(((inputs[0][x, y].R + inputs[0][x, y].G + inputs[0][x, y].B) - (inputs[1][x, y].R + inputs[1][x, y].G + inputs[1][x, y].B)), 2); var difference = Math.Abs(inputs[0][x, y].R - inputs[1].GetPixelOrBlack(x, y).R); difference += Math.Abs(inputs[0][x, y].G - inputs[1].GetPixelOrBlack(x, y).G); difference += Math.Abs(inputs[0][x, y].B - inputs[1].GetPixelOrBlack(x, y).B); if (difference >= 40) { artifacts += 1; } } } foreach (MacroblockDecision d in ((AnnotatedFrame)inputs[2]).Decisions) { if (d.PartitioningDecision == MacroblockPartitioning.Intra16x16 | d.PartitioningDecision == MacroblockPartitioning.Intra4x4 | d.PartitioningDecision == MacroblockPartitioning.Intra8x8 | d.PartitioningDecision == MacroblockPartitioning.IntraPCM) { intrablocks++; } } double decDifference = 0.0; if (((AnnotatedFrame)inputs[0]) is AnnotatedFrame && ((AnnotatedFrame)inputs[2]) is AnnotatedFrame && ((AnnotatedFrame)inputs[0]).Size.Height == ((AnnotatedFrame)inputs[2]).Size.Height && ((AnnotatedFrame)inputs[0]).Size.Width == ((AnnotatedFrame)inputs[2]).Size.Width) { AnnotatedFrame annFrame = ((AnnotatedFrame)inputs[0]); AnnotatedFrame annRef = ((AnnotatedFrame)inputs[2]); for (int i = 0; i < annFrame.Decisions.GetLength(0); i++) { for (int j = 0; j < annFrame.Decisions.GetLength(1); j++) { if (annFrame.Decisions[i, j].PartitioningDecision == annRef.Decisions[i, j].PartitioningDecision) { decDifference++; } } } decDifference /= annFrame.Decisions.Length; decDifference *= 100; } intrablocks = 100 * intrablocks / ((AnnotatedFrame)inputs[2]).Decisions.Length; pixDifference = 100 * pixDifference / (765 * inputs[0].Size.Height * inputs[0].Size.Width); mse *= (double)1 / (3 * inputs[1].Size.Height * inputs[1].Size.Width); double psnr; if (mse == 0.0) { psnr = 0.0; } psnr = 10 * Math.Log10((Math.Pow((Math.Pow(2, 24) - 1), 2)) / mse); artifacts = 100 * artifacts / (inputs[0].Size.Height * inputs[0].Size.Width); Assert.Equal(pixDifference, diaNode.Graphs[0].Data[0].Value); Assert.Equal(psnr, diaNode.Graphs[1].Data[0].Value); Assert.Equal(intrablocks, diaNode.Graphs[2].Data[0].Value, 7); Assert.Equal(decDifference, diaNode.Graphs[3].Data[0].Value, 7); Assert.Equal(artifacts, diaNode.Graphs[4].Data[0].Value, 7); }