Skip to content

Commit 5c498f0

Browse files
committed
added some GUI
1 parent fb6c939 commit 5c498f0

7 files changed

Lines changed: 152 additions & 87 deletions

File tree

Assets/Prefabs.meta

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &100000
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_PrefabParentObject: {fileID: 0}
7+
m_PrefabInternal: {fileID: 100100000}
8+
serializedVersion: 4
9+
m_Component:
10+
- 4: {fileID: 400000}
11+
- 120: {fileID: 12000000}
12+
m_Layer: 0
13+
m_Name: GestureOnScreen
14+
m_TagString: Untagged
15+
m_Icon: {fileID: 0}
16+
m_NavMeshLayer: 0
17+
m_StaticEditorFlags: 0
18+
m_IsActive: 1
19+
--- !u!4 &400000
20+
Transform:
21+
m_ObjectHideFlags: 1
22+
m_PrefabParentObject: {fileID: 0}
23+
m_PrefabInternal: {fileID: 100100000}
24+
m_GameObject: {fileID: 100000}
25+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
26+
m_LocalPosition: {x: 0, y: 0, z: 0}
27+
m_LocalScale: {x: 1, y: 1, z: 1}
28+
m_Children: []
29+
m_Father: {fileID: 0}
30+
m_RootOrder: 0
31+
--- !u!120 &12000000
32+
LineRenderer:
33+
m_ObjectHideFlags: 1
34+
m_PrefabParentObject: {fileID: 0}
35+
m_PrefabInternal: {fileID: 100100000}
36+
m_GameObject: {fileID: 100000}
37+
m_Enabled: 1
38+
m_CastShadows: 1
39+
m_ReceiveShadows: 1
40+
m_LightmapIndex: 255
41+
m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0}
42+
m_Materials:
43+
- {fileID: 10754, guid: 0000000000000000e000000000000000, type: 0}
44+
m_SubsetIndices:
45+
m_StaticBatchRoot: {fileID: 0}
46+
m_UseLightProbes: 0
47+
m_LightProbeAnchor: {fileID: 0}
48+
m_ScaleInLightmap: 1
49+
m_SortingLayerID: 0
50+
m_SortingOrder: 0
51+
m_Positions:
52+
- {x: 0, y: 0, z: 0}
53+
- {x: 0, y: 0, z: 1}
54+
m_Parameters:
55+
startWidth: .100000001
56+
endWidth: .100000001
57+
m_StartColor:
58+
serializedVersion: 2
59+
rgba: 4294967295
60+
m_EndColor:
61+
serializedVersion: 2
62+
rgba: 4294967295
63+
m_UseWorldSpace: 1
64+
--- !u!1001 &100100000
65+
Prefab:
66+
m_ObjectHideFlags: 1
67+
serializedVersion: 2
68+
m_Modification:
69+
m_TransformParent: {fileID: 0}
70+
m_Modifications: []
71+
m_RemovedComponents: []
72+
m_ParentPrefab: {fileID: 0}
73+
m_RootGameObject: {fileID: 100000}
74+
m_IsPrefabParent: 1
75+
m_IsExploded: 1

Assets/Prefabs/GestureOnScreen.prefab.meta

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -74,75 +74,6 @@ NavMeshSettings:
7474
widthInaccuracy: 16.666666
7575
heightInaccuracy: 10
7676
m_NavMesh: {fileID: 0}
77-
--- !u!1 &1899094282
78-
GameObject:
79-
m_ObjectHideFlags: 0
80-
m_PrefabParentObject: {fileID: 0}
81-
m_PrefabInternal: {fileID: 0}
82-
serializedVersion: 4
83-
m_Component:
84-
- 4: {fileID: 1899094284}
85-
- 96: {fileID: 1899094283}
86-
m_Layer: 0
87-
m_Name: GestureOnScreen
88-
m_TagString: Untagged
89-
m_Icon: {fileID: 0}
90-
m_NavMeshLayer: 0
91-
m_StaticEditorFlags: 0
92-
m_IsActive: 1
93-
--- !u!96 &1899094283
94-
TrailRenderer:
95-
m_ObjectHideFlags: 0
96-
m_PrefabParentObject: {fileID: 0}
97-
m_PrefabInternal: {fileID: 0}
98-
m_GameObject: {fileID: 1899094282}
99-
m_Enabled: 1
100-
m_CastShadows: 1
101-
m_ReceiveShadows: 1
102-
m_LightmapIndex: 255
103-
m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0}
104-
m_Materials:
105-
- {fileID: 10301, guid: 0000000000000000f000000000000000, type: 0}
106-
m_SubsetIndices:
107-
m_StaticBatchRoot: {fileID: 0}
108-
m_UseLightProbes: 0
109-
m_LightProbeAnchor: {fileID: 0}
110-
m_ScaleInLightmap: 1
111-
m_SortingLayerID: 0
112-
m_SortingOrder: 0
113-
m_Time: 1
114-
m_StartWidth: .5
115-
m_EndWidth: .5
116-
m_Colors:
117-
m_Color[0]:
118-
serializedVersion: 2
119-
rgba: 4294967295
120-
m_Color[1]:
121-
serializedVersion: 2
122-
rgba: 4294967295
123-
m_Color[2]:
124-
serializedVersion: 2
125-
rgba: 4294967295
126-
m_Color[3]:
127-
serializedVersion: 2
128-
rgba: 4294967295
129-
m_Color[4]:
130-
serializedVersion: 2
131-
rgba: 16777215
132-
m_MinVertexDistance: .100000001
133-
m_Autodestruct: 0
134-
--- !u!4 &1899094284
135-
Transform:
136-
m_ObjectHideFlags: 0
137-
m_PrefabParentObject: {fileID: 0}
138-
m_PrefabInternal: {fileID: 0}
139-
m_GameObject: {fileID: 1899094282}
140-
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
141-
m_LocalPosition: {x: 0, y: 0, z: 0}
142-
m_LocalScale: {x: 1, y: 1, z: 1}
143-
m_Children: []
144-
m_Father: {fileID: 0}
145-
m_RootOrder: 1
14677
--- !u!1 &1907031143
14778
GameObject:
14879
m_ObjectHideFlags: 0
@@ -239,4 +170,5 @@ MonoBehaviour:
239170
m_Script: {fileID: 11500000, guid: 63465958d7bcc403e89a14826c19f7bc, type: 3}
240171
m_Name:
241172
m_EditorClassIdentifier:
242-
gestureOnScreen: {fileID: 1899094284}
173+
gestureOnScreenPrefab: {fileID: 400000, guid: 971129baafd304455a111daa5207b8a1,
174+
type: 2}

Assets/Scripts/CapturePoints.cs

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,37 @@
77

88
public class CapturePoints : MonoBehaviour {
99

10-
public Transform gestureOnScreen;
10+
public Transform gestureOnScreenPrefab;
1111

1212
private List<Gesture> trainingSet = new List<Gesture>();
1313

1414
private List<Point> points = new List<Point>();
1515
private int strokeId = -1;
16+
1617
private Vector3 virtualKeyPosition = Vector2.zero;
18+
private Rect drawArea;
1719

1820
private RuntimePlatform platform;
21+
private int vertexCount = 0;
22+
23+
private List<LineRenderer> gestureLinesRenderer = new List<LineRenderer>();
24+
private LineRenderer currentGestureLineRenderer;
25+
26+
//GUI
27+
private string message;
28+
private bool recognized;
1929

20-
// Use this for initialization
2130
void Start () {
2231

2332
platform = Application.platform;
33+
drawArea = new Rect(0, 0, Screen.width - Screen.width / 3, Screen.height);
2434

2535
TextAsset[] gesturesXml = Resources.LoadAll<TextAsset>("GestureSet/10-stylus-MEDIUM/");
2636

2737
foreach (TextAsset gestureXml in gesturesXml)
2838
trainingSet.Add(GestureIO.ReadGesture(gestureXml.text));
2939
}
30-
31-
// Update is called once per frame
40+
3241
void Update () {
3342

3443
if (platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer) {
@@ -41,25 +50,61 @@ void Update () {
4150
}
4251
}
4352

44-
if (Input.GetMouseButtonDown(0)) {
45-
points.Clear();
46-
++strokeId;
47-
}
48-
49-
if (Input.GetMouseButton(0)) {
50-
points.Add(new Point(virtualKeyPosition.x, -virtualKeyPosition.y, strokeId));
51-
gestureOnScreen.position = WorldCoordinateForGesturePoint(virtualKeyPosition);
53+
if (drawArea.Contains(virtualKeyPosition)) {
54+
55+
if (Input.GetMouseButtonDown(0)) {
56+
57+
if (recognized) {
58+
59+
recognized = false;
60+
61+
points.Clear();
62+
63+
foreach (LineRenderer lineRenderer in gestureLinesRenderer) {
64+
65+
lineRenderer.SetVertexCount(0);
66+
Destroy(lineRenderer);
67+
}
68+
69+
gestureLinesRenderer.Clear();
70+
71+
}
72+
73+
++strokeId;
74+
75+
Transform tmpGesture = Instantiate(gestureOnScreenPrefab, transform.position, transform.rotation) as Transform;
76+
currentGestureLineRenderer = tmpGesture.GetComponent<LineRenderer>();
77+
78+
gestureLinesRenderer.Add(currentGestureLineRenderer);
79+
80+
vertexCount = 0;
81+
}
82+
83+
if (Input.GetMouseButton(0)) {
84+
points.Add(new Point(virtualKeyPosition.x, -virtualKeyPosition.y, strokeId));
85+
86+
currentGestureLineRenderer.SetVertexCount(++vertexCount);
87+
currentGestureLineRenderer.SetPosition(vertexCount - 1, WorldCoordinateForGesturePoint(virtualKeyPosition));
88+
}
5289
}
53-
54-
if (Input.GetMouseButtonUp(0)) {
90+
}
91+
92+
void OnGUI() {
93+
94+
GUI.Box(drawArea, "Draw Area");
95+
96+
GUI.Label(new Rect(10, Screen.height - 40, 500, 50), message);
97+
98+
if (GUI.Button(new Rect(Screen.width - 100, 10, 100, 30), "Recognize")) {
99+
100+
recognized = true;
55101

56102
Gesture candidate = new Gesture(points.ToArray());
57103

58104
Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray());
59105

60-
Debug.Log(gestureResult.GestureClass);
61-
Debug.Log(gestureResult.Score);
62-
106+
message = gestureResult.GestureClass + " " + gestureResult.Score;
107+
63108
strokeId = -1;
64109
}
65110
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ $P Point-Cloud Recognizer
22
=========================
33
[Web demo](http://depts.washington.edu/aimgroup/proj/dollar/pdollar.html).
44

5+
In the demo, only one point-cloud template is loaded for each of the 16 gesture types. You can add additional templates as you wish, and even define your own custom gesture templates.
6+
7+
![](http://aymericlamboley.fr/blog/wp-content/uploads/2014/07/multistrokes.gif)
8+
59
About
610
-----
711
The [$P](http://depts.washington.edu/aimgroup/proj/dollar/pdollar.html) Point-Cloud Recognizer is a 2-D gesture recognizer designed for rapid prototyping of gesture-based user interfaces. In machine learning terms, $P is an instance-based nearest-neighbor classifier with a Euclidean scoring function, i.e., a geometric template matcher. $P is the latest in the dollar family of recognizers that includes [$1](http://depts.washington.edu/aimgroup/proj/dollar/index.html) for unistrokes and [$N](http://depts.washington.edu/aimgroup/proj/dollar/ndollar.html) for multistrokes. Although about half of $P's code is from $1, unlike both $1 and $N, $P does not represent gestures as ordered series of points (i.e., strokes), but as unordered point-clouds. By representing gestures as point-clouds, $P can handle both unistrokes and multistrokes equivalently and without the combinatoric overhead of $N. When comparing two point-clouds, $P solves the classic [assignment problem](http://en.wikipedia.org/wiki/Assignment_problem) between two bipartite graphs using an approximation of the [Hungarian algorithm](http://en.wikipedia.org/wiki/Hungarian_algorithm). The $P recognizer is distributed under the [New BSD License](http://en.wikipedia.org/wiki/BSD_licenses#3-clause_license_.28.22Revised_BSD_License.22.2C_.22New_BSD_License.22.2C_or_.22Modified_BSD_License.22.29) agreement.

0 commit comments

Comments
 (0)