forked from homuler/MediaPipeUnityPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultGraphOnCPU.cs
More file actions
50 lines (42 loc) · 1.74 KB
/
Copy pathDefaultGraphOnCPU.cs
File metadata and controls
50 lines (42 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2019 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Mediapipe;
using UnityEngine;
/// <summary>
/// This class is a translated version of
/// <see href="https://github.com/google/mediapipe/blob/v0.7.10/mediapipe/examples/desktop/demo_run_graph_main.cc">
/// demo_run_graph_main.cc
/// </see>
/// in the official repository.
/// </summary>
public class DefaultGraphOnCPU : DemoGraph {
private const string outputStream = "output_video";
private OutputStreamPoller<ImageFrame> outputStreamPoller;
private ImageFramePacket outputPacket;
public override Status StartRun() {
outputStreamPoller = graph.AddOutputStreamPoller<ImageFrame>(outputStream).ConsumeValueOrDie();
outputPacket = new ImageFramePacket();
return graph.StartRun();
}
public override void RenderOutput(WebCamScreenController screenController, TextureFrame textureFrame) {
var texture = screenController.GetScreen();
if (!outputStreamPoller.Next(outputPacket)) {
Debug.LogWarning("Failed to fetch an output packet, rendering the input image");
texture.SetPixels32(textureFrame.GetPixels32());
} else {
texture.SetPixels32(outputPacket.Get().GetColor32s());
}
texture.Apply();
}
}