private double measure(ColorParticle p) { double[] distanceVector = new double[] { 255, 255, 255 }; var location = p.Position.Round(); //check if a particle got outside the image boundaries if (location.X >= 0 && location.X < imgSize.Width && location.Y >= 0 && location.Y < imgSize.Height) { Bgr <byte> particleColor; unsafe { particleColor = frame[location.Y, location.X]; } distanceVector = new double[] { referenceColor.R - particleColor.R, referenceColor.G - particleColor.G, referenceColor.B - particleColor.B }; } var distance = distanceVector.Multiply(distanceVector.Transpose())[0]; //applied log function on normal distribution: /*double constAddFactor = -Math.Log(Math.Sqrt(2 * Math.PI) * stdDev); * double constMulFactor = -1 / (2 * stdDev * stdDev); * double probability = constAddFactor + constMulFactor * distance;*/ var probability = prob.ProbabilityDensityFunction(Math.Sqrt(distance)); return(probability); }
private void updateParticleWeight(ColorParticle p) { double[] distanceVector = new double[] { 255, 255, 255 }; var location = p.Position.Round(); //check if a particle got outside the image boundaries if (location.X >= 0 && location.X < imgSize.Width && location.Y >= 0 && location.Y < imgSize.Height) { Bgr8 particleColor; unsafe { particleColor = *(Bgr8 *)frame.GetData(location.Y, location.X); //much faster than frame[row, col] } distanceVector = new double[] { referenceColor.R - particleColor.R, referenceColor.G - particleColor.G, referenceColor.B - particleColor.B }; } var distance = distanceVector.Multiply(distanceVector.Transpose())[0]; //applied log function on normal distribution: /*double constAddFactor = -Math.Log(Math.Sqrt(2 * Math.PI) * stdDev); * double constMulFactor = -1 / (2 * stdDev * stdDev); * double probability = constAddFactor + constMulFactor * distance;*/ var probability = prob.ProbabilityDensityFunction(Math.Sqrt(distance)); p.Weight = probability; }
private void updateParticleWeight(ColorParticle p) { double[] distanceVector = new double[] { 255, 255, 255 }; var location = p.Position.Round(); //check if a particle got outside the image boundaries if (location.X >= 0 && location.X < imgSize.Width && location.Y >= 0 && location.Y < imgSize.Height) { Bgr8 particleColor; unsafe { particleColor = *(Bgr8*)frame.GetData(location.Y, location.X); //much faster than frame[row, col] } distanceVector = new double[]{referenceColor.R - particleColor.R, referenceColor.G - particleColor.G, referenceColor.B - particleColor.B}; } var distance = distanceVector.Multiply(distanceVector.Transpose())[0]; //applied log function on normal distribution: /*double constAddFactor = -Math.Log(Math.Sqrt(2 * Math.PI) * stdDev); double constMulFactor = -1 / (2 * stdDev * stdDev); double probability = constAddFactor + constMulFactor * distance;*/ var probability = prob.ProbabilityDensityFunction(Math.Sqrt(distance)); p.Weight = probability; }
private double measure(ColorParticle p) { double[] distanceVector = new double[] { 255, 255, 255 }; var location = p.Position.Round(); //check if a particle got outside the image boundaries if (location.X >= 0 && location.X < imgSize.Width && location.Y >= 0 && location.Y < imgSize.Height) { Bgr<byte> particleColor; unsafe { particleColor = frame[location.Y, location.X]; } distanceVector = new double[]{referenceColor.R - particleColor.R, referenceColor.G - particleColor.G, referenceColor.B - particleColor.B}; } var distance = distanceVector.Multiply(distanceVector.Transpose())[0]; //applied log function on normal distribution: /*double constAddFactor = -Math.Log(Math.Sqrt(2 * Math.PI) * stdDev); double constMulFactor = -1 / (2 * stdDev * stdDev); double probability = constAddFactor + constMulFactor * distance;*/ var probability = prob.ProbabilityDensityFunction(Math.Sqrt(distance)); return probability; }