Skip to content

nmetulev/PeekABoo

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

Visual State Triggers in Windows 10

Developers writing UWP apps in XAML have the capability to create VisualState triggers that can automatically trigger a VisualState change. One example is the AdaptiveTrigger that can be triggered by changing the size of the window

<VisualState>
  <VisualState.StateTriggers>
  <!--VisualState to be triggered when window width is >=720 effective pixels.-->
      <AdaptiveTrigger MinWindowWidth="720" />
  </VisualState.StateTriggers>

  <VisualState.Setters>
      <Setter Target="myPanel.Orientation" Value="Horizontal" />
  </VisualState.Setters>
</VisualState>

PeekABoo

PeekABoo is an app that uses the StateTriggerBase class to create a PeekTrigger for detecting when a face is present in the view of the camera

<VisualState.StateTriggers>
    <local:PeekTrigger Mode="FaceDetected"></local:PeekTrigger>
</VisualState.StateTriggers>

By creating a property Mode on the PeekTrigger class, we can allow the developer to choose if the trigger is active when a face is detected (FaceDetected) or when a face is not detected (FaceNotDetected).

FaceDetection is done by using the new FaceDetectionEffect class in Windows 10 to detect faces in a video stream, in this case the camera.

var definition = new FaceDetectionEffectDefinition();
definition.SynchronousDetectionEnabled = false;
definition.DetectionMode = FaceDetectionMode.HighPerformance;

_faceDetectionEffect = (FaceDetectionEffect) await _mediaCapture.AddVideoEffectAsync(definition, MediaStreamType.VideoPreview);

// detect 30 frames/second
_faceDetectionEffect.DesiredDetectionInterval = TimeSpan.FromMilliseconds(33);
_faceDetectionEffect.Enabled = true;
_faceDetectionEffect.FaceDetected += FaceDetectionEffect_FaceDetected;

We set the trigger to active by using the SetActive(true) method of the StateTriggerBase when the condition is satisfied

private async void FaceDetectionEffect_FaceDetected(FaceDetectionEffect sender, FaceDetectedEventArgs args)
{
    if (args.ResultFrame.DetectedFaces.Count > 0 && mode.ToLower() == "facedetected" ||
        args.ResultFrame.DetectedFaces.Count == 0 && mode.ToLower() == "facenotdetected")
    {
        await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            SetActive(true);
        });
    }
}

###Images Sad dog
Happy dog

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages