forked from homuler/MediaPipeUnityPlugin
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathObjectronConfig.cs
More file actions
169 lines (142 loc) · 5.63 KB
/
Copy pathObjectronConfig.cs
File metadata and controls
169 lines (142 loc) · 5.63 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Mediapipe.Unity.UI;
namespace Mediapipe.Unity.Objectron.UI
{
public class ObjectronConfig : ModalContents
{
private const string _CategoryPath = "Scroll View/Viewport/Contents/Category/Dropdown";
private const string _MaxNumObjectsPath = "Scroll View/Viewport/Contents/Max Num Objects/InputField";
private const string _MinDetectionConfidencePath = "Scroll View/Viewport/Contents/Min Detection Confidence/InputField";
private const string _MinTrackingConfidencePath = "Scroll View/Viewport/Contents/Min Tracking Confidence/InputField";
private const string _RunningModePath = "Scroll View/Viewport/Contents/Running Mode/Dropdown";
private const string _TimeoutMillisecPath = "Scroll View/Viewport/Contents/Timeout Millisec/InputField";
private ObjectronSolution _solution;
private Dropdown _categoryInput;
private InputField _maxNumObjectsInput;
private InputField _minDetectionConfidenceInput;
private InputField _minTrackingConfidenceInput;
private Dropdown _runningModeInput;
private InputField _timeoutMillisecInput;
private bool _isChanged;
private void Start()
{
_solution = GameObject.Find("Solution").GetComponent<ObjectronSolution>();
InitializeContents();
}
public override void Exit()
{
GetModal().CloseAndResume(_isChanged);
}
public void SwitchCategory()
{
_solution.category = (ObjectronGraph.Category)_categoryInput.value;
_isChanged = true;
}
public void UpdateMaxNumObjects()
{
if (int.TryParse(_maxNumObjectsInput.text, out var value))
{
_solution.maxNumObjects = Mathf.Max(0, value);
_isChanged = true;
}
}
public void SetMinDetectionConfidence()
{
if (float.TryParse(_minDetectionConfidenceInput.text, out var value))
{
_solution.minDetectionConfidence = value;
_isChanged = true;
}
}
public void SetMinTrackingConfidence()
{
if (float.TryParse(_minTrackingConfidenceInput.text, out var value))
{
_solution.minTrackingConfidence = value;
_isChanged = true;
}
}
public void SetTimeoutMillisec()
{
if (int.TryParse(_timeoutMillisecInput.text, out var value))
{
_solution.timeoutMillisec = value;
_isChanged = true;
}
}
public void SwitchRunningMode()
{
_solution.runningMode = (RunningMode)_runningModeInput.value;
_isChanged = true;
}
private void InitializeContents()
{
InitializeCategory();
InitializeRunningMode();
InitializeMaxNumObjects();
InitializeMinDetectionConfidence();
InitializeMinTrackingConfidence();
InitializeTimeoutMillisec();
}
private void InitializeCategory()
{
_categoryInput = gameObject.transform.Find(_CategoryPath).gameObject.GetComponent<Dropdown>();
_categoryInput.ClearOptions();
var options = new List<string>(Enum.GetNames(typeof(ObjectronGraph.Category)));
_categoryInput.AddOptions(options);
var currentCategory = _solution.category;
var defaultValue = options.FindIndex(option => option == currentCategory.ToString());
if (defaultValue >= 0)
{
_categoryInput.value = defaultValue;
}
_categoryInput.onValueChanged.AddListener(delegate { SwitchCategory(); });
}
private void InitializeMaxNumObjects()
{
_maxNumObjectsInput = gameObject.transform.Find(_MaxNumObjectsPath).gameObject.GetComponent<InputField>();
_maxNumObjectsInput.text = _solution.maxNumObjects.ToString();
_maxNumObjectsInput.onEndEdit.AddListener(delegate { UpdateMaxNumObjects(); });
}
private void InitializeMinDetectionConfidence()
{
_minDetectionConfidenceInput = gameObject.transform.Find(_MinDetectionConfidencePath).gameObject.GetComponent<InputField>();
_minDetectionConfidenceInput.text = _solution.minDetectionConfidence.ToString();
_minDetectionConfidenceInput.onValueChanged.AddListener(delegate { SetMinDetectionConfidence(); });
}
private void InitializeMinTrackingConfidence()
{
_minTrackingConfidenceInput = gameObject.transform.Find(_MinTrackingConfidencePath).gameObject.GetComponent<InputField>();
_minTrackingConfidenceInput.text = _solution.minTrackingConfidence.ToString();
_minTrackingConfidenceInput.onValueChanged.AddListener(delegate { SetMinTrackingConfidence(); });
}
private void InitializeRunningMode()
{
_runningModeInput = gameObject.transform.Find(_RunningModePath).gameObject.GetComponent<Dropdown>();
_runningModeInput.ClearOptions();
var options = new List<string>(Enum.GetNames(typeof(RunningMode)));
_runningModeInput.AddOptions(options);
var currentRunningMode = _solution.runningMode;
var defaultValue = options.FindIndex(option => option == currentRunningMode.ToString());
if (defaultValue >= 0)
{
_runningModeInput.value = defaultValue;
}
_runningModeInput.onValueChanged.AddListener(delegate { SwitchRunningMode(); });
}
private void InitializeTimeoutMillisec()
{
_timeoutMillisecInput = gameObject.transform.Find(_TimeoutMillisecPath).gameObject.GetComponent<InputField>();
_timeoutMillisecInput.text = _solution.timeoutMillisec.ToString();
_timeoutMillisecInput.onValueChanged.AddListener(delegate { SetTimeoutMillisec(); });
}
}
}