public async Task Run(Scene worldScene) { WriteLine("Scanning..."); var scene = Projector.Scene; var size = Projector.Intrinsics.ImageSize; WriteLine("Black, White, Color, and Mask..."); var clearBlack = new Clear(Color.Black); await GetBlackWhiteAndMask(scene); WriteLine("Horizontal..."); var horSgc = new SafeGrayCode(size.Width); var horGcs = new GrayCodeSweep(horSgc, size.Height, GrayCodeSweep.Direction.Horizontal); scene.Clear(); scene.Add(horGcs); var horAssembly = await SweepGrayCode(horGcs); int[] verAssembly = null; WriteLine("Vertical..."); var verSgc = new SafeGrayCode(size.Height); var verGcs = new GrayCodeSweep(verSgc, size.Width, GrayCodeSweep.Direction.Vertical); scene.Clear(); scene.Add(verGcs); verAssembly = await SweepGrayCode(verGcs); scene.Clear(); scene.Add(new Clear(Color.White)); WriteLine("Making..."); await Make(horAssembly, verAssembly, worldScene); WriteLine("Done..."); }
private async Task<int[]> Assemble(IList<Picture<Gray, byte>> grays, SafeGrayCode sgc) { await Program.SwitchToCompute(); var width = Black.Width; var height = Black.Height; var accum = new int[height * width]; using (var asmbl = new Picture<Gray, byte>(width, height)) using (var clred = new Picture<Bgra, byte>(width, height)) { for (int g = 0; g < sgc.NumBits; ++g) { for (int b = 0; b < accum.Length; ++b) { var v = grays[g].Bytes[b] != 0 ? (1 << g) : 0; accum[b] = accum[b] | v; } } for (int b = 0; b < accum.Length; ++b) { accum[b] = sgc.ToBinary(accum[b]); asmbl.Bytes[b] = (byte)((accum[b] * 255) / sgc.Count); } WriteLine("Accumulated Min and Max is {0} {1}", accum.Min(), accum.Max()); asmbl.Emgu.Save(Global.TmpFileName("assembled", "png")); return accum; } }