public OpenFaceVisualizer(Pipeline pipeline) : base(pipeline) { DataInConnector = CreateInputConnectorFrom <HeadPoseAndGaze>(pipeline, nameof(DataIn)); ImageInConnector = CreateInputConnectorFrom <Shared <Image> >(pipeline, nameof(ImageIn)); Out = pipeline.CreateEmitter <Shared <Image> >(this, nameof(Out)); var joined = DataInConnector.Out.Join(ImageInConnector.Out, Reproducible.Exact <Shared <Image> >()); joined.Do(Process); pipeline.PipelineCompleted += OnPipelineCompleted; display.PropertyChanged += (sender, e) => { if (e.PropertyName == nameof(display.VideoImage)) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Image))); } }; display.ReceivedFrames.PropertyChanged += (sender, e) => { if (e.PropertyName == nameof(display.RenderedFrames.Rate)) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FrameRate))); } }; }
private void InitializePipeline() { pipeline = Pipeline.Create(); var webcamConfig = MediaCaptureConfiguration.Default; webcamConfig.DeviceId = WebcamSymbolicLink; webcamConfig.Width = WebcamWidth; webcamConfig.Height = WebcamHeight; webcamConfig.Framerate = 30; webcamConfig.UseInSharedMode = true; var source = new MediaCapture(pipeline, webcamConfig); var flip = new FlipColorVideo(pipeline) { FlipHorizontal = FlipX, FlipVertical = FlipY }; source.PipeTo(flip.In, DeliveryPolicy.LatestMessage); var openface = new OpenFace(pipeline) { CameraCalibFx = WebcamFx, CameraCalibFy = WebcamFy, CameraCalibCx = WebcamCx, CameraCalibCy = WebcamCy }; flip.PipeTo(openface.In, DeliveryPolicy.LatestMessage); var dispFlip = new FlipColorVideo(pipeline) { FlipHorizontal = !FlipX, FlipVertical = FlipY }; // mirror display source.PipeTo(dispFlip.In, DeliveryPolicy.LatestMessage); var joinedVideoFrame = openface.Out.Join(dispFlip.Out, Reproducible.Exact <Shared <Microsoft.Psi.Imaging.Image> >(), (dataPoint, frame) => new Tuple <PoseAndEyeAndFace, Shared <Microsoft.Psi.Imaging.Image> >(dataPoint, frame), DeliveryPolicy.LatestMessage, DeliveryPolicy.LatestMessage); joinedVideoFrame.Do(UpdateDisplay, DeliveryPolicy.LatestMessage); pipeline.RunAsync(); }
/// <summary> /// Initializes a new instance of the <see cref="ParallelFixedLength{TIn, TOut}"/> class. /// </summary> /// <param name="pipeline">The pipeline to add the component to.</param> /// <param name="vectorSize">Vector size.</param> /// <param name="transform">Function mapping keyed input producers to output producers.</param> /// <param name="outputDefaultIfDropped">When true, a result is produced even if a message is dropped in processing one of the input elements. In this case the corresponding output element is set to a default value.</param> /// <param name="defaultValue">Default value to use when messages are dropped in processing one of the input elements.</param> /// <param name="name">Name for this component (defaults to ParallelFixedLength).</param> /// <param name="defaultDeliveryPolicy">Pipeline-level default delivery policy to be used by this component (defaults to <see cref="DeliveryPolicy.Unlimited"/> if unspecified).</param> public ParallelFixedLength(Pipeline pipeline, int vectorSize, Func <int, IProducer <TIn>, IProducer <TOut> > transform, bool outputDefaultIfDropped, TOut defaultValue = default, string name = null, DeliveryPolicy defaultDeliveryPolicy = null) : base(pipeline, name ?? nameof(ParallelFixedLength <TIn, TOut>), defaultDeliveryPolicy) { this.inConnector = this.CreateInputConnectorFrom <TIn[]>(pipeline, nameof(this.inConnector)); this.splitter = this.CreateReceiver <TIn[]>(this, this.Receive, nameof(this.splitter)); this.inConnector.PipeTo(this.splitter); this.branches = new Emitter <TIn> [vectorSize]; var branchResults = new IProducer <TOut> [vectorSize]; for (int i = 0; i < vectorSize; i++) { var subpipeline = Subpipeline.Create(this, $"subpipeline{i}"); var connectorIn = new Connector <TIn>(this, subpipeline, $"connectorIn{i}"); var connectorOut = new Connector <TOut>(subpipeline, this, $"connectorOut{i}"); this.branches[i] = this.CreateEmitter <TIn>(this, $"branch{i}"); this.branches[i].PipeTo(connectorIn); transform(i, connectorIn.Out).PipeTo(connectorOut.In); branchResults[i] = connectorOut; } var interpolator = outputDefaultIfDropped ? Reproducible.ExactOrDefault <TOut>(defaultValue) : Reproducible.Exact <TOut>(); this.join = Operators.Join(branchResults, interpolator); this.outConnector = this.CreateOutputConnectorTo <TOut[]>(pipeline, nameof(this.outConnector)); this.join.PipeTo(this.outConnector); }
/// <summary> /// Initializes a new instance of the <see cref="ParallelVariableLength{TIn, TOut}"/> class. /// </summary> /// <param name="pipeline">Pipeline to which this component belongs.</param> /// <param name="transform">Function mapping keyed input producers to output producers.</param> /// <param name="outputDefaultIfDropped">When true, a result is produced even if a message is dropped in processing one of the input elements. In this case the corresponding output element is set to a default value.</param> /// <param name="defaultValue">Default value to use when messages are dropped in processing one of the input elements.</param> public ParallelVariableLength(Pipeline pipeline, Func <int, IProducer <TIn>, IProducer <TOut> > transform, bool outputDefaultIfDropped = false, TOut defaultValue = default) { this.pipeline = pipeline; this.parallelTransform = transform; this.In = pipeline.CreateReceiver <TIn[]>(this, this.Receive, nameof(this.In)); this.activeBranchesEmitter = pipeline.CreateEmitter <int>(this, nameof(this.activeBranchesEmitter)); var interpolator = outputDefaultIfDropped ? Reproducible.ExactOrDefault <TOut>(defaultValue) : Reproducible.Exact <TOut>(); this.join = new Join <int, TOut, TOut[]>( pipeline, interpolator, (count, values) => values, 0, count => Enumerable.Range(0, count)); this.activeBranchesEmitter.PipeTo(this.join.InPrimary); }
/// <summary> /// Initializes a new instance of the <see cref="ParallelVariableLength{TIn, TOut}"/> class. /// </summary> /// <param name="pipeline">Pipeline to which this component belongs.</param> /// <param name="transform">Function mapping keyed input producers to output producers.</param> /// <param name="outputDefaultIfDropped">When true, a result is produced even if a message is dropped in processing one of the input elements. In this case the corresponding output element is set to a default value.</param> /// <param name="defaultValue">Default value to use when messages are dropped in processing one of the input elements.</param> /// <param name="name">Name for this component (defaults to ParallelVariableLength).</param> /// <param name="defaultDeliveryPolicy">Pipeline-level default delivery policy to be used by this component (defaults to <see cref="DeliveryPolicy.Unlimited"/> if unspecified).</param> public ParallelVariableLength(Pipeline pipeline, Func <int, IProducer <TIn>, IProducer <TOut> > transform, bool outputDefaultIfDropped = false, TOut defaultValue = default, string name = null, DeliveryPolicy defaultDeliveryPolicy = null) : base(pipeline, name ?? nameof(ParallelVariableLength <TIn, TOut>), defaultDeliveryPolicy) { this.parallelTransform = transform; this.inConnector = this.CreateInputConnectorFrom <TIn[]>(pipeline, nameof(this.inConnector)); this.splitter = this.CreateReceiver <TIn[]>(this, this.Receive, nameof(this.splitter)); this.inConnector.PipeTo(this.splitter); this.activeBranchesEmitter = this.CreateEmitter <int>(this, nameof(this.activeBranchesEmitter)); var interpolator = outputDefaultIfDropped ? Reproducible.ExactOrDefault <TOut>(defaultValue) : Reproducible.Exact <TOut>(); this.join = new Join <int, TOut, TOut[]>( this, interpolator, (count, values) => values, 0, count => Enumerable.Range(0, count)); this.activeBranchesEmitter.PipeTo(this.join.InPrimary); this.outConnector = this.CreateOutputConnectorTo <TOut[]>(pipeline, nameof(this.outConnector)); this.join.PipeTo(this.outConnector); }
/// <summary> /// Initializes a new instance of the <see cref="ParallelFixedLength{TIn, TOut}"/> class. /// </summary> /// <param name="pipeline">Pipeline to which this component belongs.</param> /// <param name="vectorSize">Vector size.</param> /// <param name="transform">Function mapping keyed input producers to output producers.</param> /// <param name="outputDefaultIfDropped">When true, a result is produced even if a message is dropped in processing one of the input elements. In this case the corresponding output element is set to a default value.</param> /// <param name="defaultValue">Default value to use when messages are dropped in processing one of the input elements.</param> public ParallelFixedLength(Pipeline pipeline, int vectorSize, Func <int, IProducer <TIn>, IProducer <TOut> > transform, bool outputDefaultIfDropped, TOut defaultValue = default) { this.In = pipeline.CreateReceiver <TIn[]>(this, this.Receive, nameof(this.In)); this.branches = new Emitter <TIn> [vectorSize]; var branchResults = new IProducer <TOut> [vectorSize]; for (int i = 0; i < vectorSize; i++) { var subpipeline = Subpipeline.Create(pipeline, $"subpipeline{i}"); var connectorIn = new Connector <TIn>(pipeline, subpipeline, $"connectorIn{i}"); var connectorOut = new Connector <TOut>(subpipeline, pipeline, $"connectorOut{i}"); this.branches[i] = pipeline.CreateEmitter <TIn>(this, $"branch{i}"); this.branches[i].PipeTo(connectorIn); transform(i, connectorIn.Out).PipeTo(connectorOut.In); branchResults[i] = connectorOut; } var interpolator = outputDefaultIfDropped ? Reproducible.ExactOrDefault <TOut>(defaultValue) : Reproducible.Exact <TOut>(); this.join = Operators.Join(branchResults, interpolator); }