Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf46a6e

Browse files
author
satoo air
committed
update 1.0.4
1 parent edc6471 commit cf46a6e

5 files changed

Lines changed: 68 additions & 20 deletions

File tree

MarkerBasedAR/Marker.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,23 @@ public static int hammDistMarker (Mat bits)
5656
{
5757
int[][] ids = new int[][]
5858
{
59+
// (1)
5960
new int[]{1,0,0,0,0},
6061
new int[]{1,0,1,1,1},
61-
new int[]{0,1,0,0,1},
62+
new int[]{0,1,0,0,1}, //dummy data
6263
new int[]{0,1,1,1,0}
64+
65+
// (2)
66+
// new int[]{0,0,1,0,0},
67+
// new int[]{1,1,1,1,1},
68+
// new int[]{1,0,1,0,1},
69+
// new int[]{1,1,0,1,1}
70+
71+
// (3)
72+
// new int[]{1,1,1,1,1},
73+
// new int[]{1,0,0,0,1},
74+
// new int[]{1,1,1,1,0},
75+
// new int[]{0,1,1,1,1}
6376
};
6477

6578
int dist = 0;

ReadMe.pdf

18.2 KB
Binary file not shown.
152 Bytes
Binary file not shown.

Scripts/Texture2DMarkerBasedARSample.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ namespace MarkerBasedARSample
1111
/// </summary>
1212
public class Texture2DMarkerBasedARSample : MonoBehaviour
1313
{
14+
/// <summary>
15+
/// The image texture.
16+
/// </summary>
17+
public Texture2D imgTexture;
1418

1519
/// <summary>
1620
/// The AR camera.
@@ -21,8 +25,6 @@ public class Texture2DMarkerBasedARSample : MonoBehaviour
2125
// Use this for initialization
2226
void Start ()
2327
{
24-
Texture2D imgTexture = Resources.Load ("MarkerTest") as Texture2D;
25-
2628

2729
gameObject.transform.localScale = new Vector3 (imgTexture.width, imgTexture.height, 1);
2830
Camera.main.orthographicSize = imgTexture.height / 2;

Scripts/WebCamTextureMarkerBasedARSample.cs

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public class WebCamTextureMarkerBasedARSample : MonoBehaviour
1616
/// </summary>
1717
WebCamTexture webCamTexture;
1818

19+
/// <summary>
20+
/// The web cam device.
21+
/// </summary>
22+
WebCamDevice webCamDevice;
23+
1924
/// <summary>
2025
/// The colors.
2126
/// </summary>
@@ -98,13 +103,9 @@ public class WebCamTextureMarkerBasedARSample : MonoBehaviour
98103
// Use this for initialization
99104
void Start ()
100105
{
101-
102-
103106

104107
StartCoroutine (init ());
105-
106-
107-
108+
108109
}
109110

110111
/// <summary>
@@ -127,9 +128,10 @@ private IEnumerator init ()
127128

128129

129130
Debug.Log (cameraIndex + " name " + WebCamTexture.devices [cameraIndex].name + " isFrontFacing " + WebCamTexture.devices [cameraIndex].isFrontFacing);
130-
131+
132+
webCamDevice = WebCamTexture.devices [cameraIndex];
131133

132-
webCamTexture = new WebCamTexture (WebCamTexture.devices [cameraIndex].name, width, height);
134+
webCamTexture = new WebCamTexture (webCamDevice.name, width, height);
133135

134136

135137
break;
@@ -139,7 +141,8 @@ private IEnumerator init ()
139141
}
140142

141143
if (webCamTexture == null) {
142-
webCamTexture = new WebCamTexture (width, height);
144+
webCamDevice = WebCamTexture.devices [0];
145+
webCamTexture = new WebCamTexture (webCamDevice.name, width, height);
143146
}
144147

145148
Debug.Log ("width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);
@@ -151,9 +154,13 @@ private IEnumerator init ()
151154

152155
while (true) {
153156
//If you want to use webcamTexture.width and webcamTexture.height on iOS, you have to wait until webcamTexture.didUpdateThisFrame == 1, otherwise these two values will be equal to 16. (http://forum.unity3d.com/threads/webcamtexture-and-error-0x0502.123922/)
154-
if (webCamTexture.width > 16 && webCamTexture.height > 16) {
157+
#if UNITY_IPHONE && !UNITY_EDITOR
158+
if (webCamTexture.width > 16 && webCamTexture.height > 16) {
159+
#else
160+
if (webCamTexture.didUpdateThisFrame) {
161+
#endif
155162
Debug.Log ("width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);
156-
Debug.Log ("videoRotationAngle " + webCamTexture.videoRotationAngle + " videoVerticallyMirrored " + webCamTexture.videoVerticallyMirrored);
163+
Debug.Log ("videoRotationAngle " + webCamTexture.videoRotationAngle + " videoVerticallyMirrored " + webCamTexture.videoVerticallyMirrored + " isFrongFacing " + webCamDevice.isFrontFacing);
157164

158165

159166
colors = new Color32[webCamTexture.width * webCamTexture.height];
@@ -261,18 +268,44 @@ void Update ()
261268
if (!initDone)
262269
return;
263270

264-
if (webCamTexture.width > 16 && webCamTexture.height > 16) {
271+
#if UNITY_IPHONE && !UNITY_EDITOR
272+
if (webCamTexture.width > 16 && webCamTexture.height > 16) {
273+
#else
274+
if (webCamTexture.didUpdateThisFrame) {
275+
#endif
265276

266277

267278
Utils.webCamTextureToMat (webCamTexture, rgbaMat, colors);
268279

269280
//flip to correct direction.
270-
if (webCamTexture.videoRotationAngle == 180 && webCamTexture.videoVerticallyMirrored) {
271-
Core.flip (rgbaMat, rgbaMat, 1);
272-
} else if (webCamTexture.videoRotationAngle == 180) {
273-
Core.flip (rgbaMat, rgbaMat, -1);
274-
} else if (webCamTexture.videoVerticallyMirrored) {
275-
Core.flip (rgbaMat, rgbaMat, 0);
281+
if (webCamTexture.videoVerticallyMirrored) {
282+
if (webCamDevice.isFrontFacing) {
283+
if (webCamTexture.videoRotationAngle == 0) {
284+
Core.flip (rgbaMat, rgbaMat, -1);
285+
} else if (webCamTexture.videoRotationAngle == 180) {
286+
287+
}
288+
} else {
289+
if (webCamTexture.videoRotationAngle == 0) {
290+
Core.flip (rgbaMat, rgbaMat, 0);
291+
} else if (webCamTexture.videoRotationAngle == 180) {
292+
Core.flip (rgbaMat, rgbaMat, 1);
293+
}
294+
}
295+
} else {
296+
if (webCamDevice.isFrontFacing) {
297+
if (webCamTexture.videoRotationAngle == 0) {
298+
Core.flip (rgbaMat, rgbaMat, 1);
299+
} else if (webCamTexture.videoRotationAngle == 180) {
300+
Core.flip (rgbaMat, rgbaMat, 0);
301+
}
302+
} else {
303+
if (webCamTexture.videoRotationAngle == 0) {
304+
305+
} else if (webCamTexture.videoRotationAngle == 180) {
306+
Core.flip (rgbaMat, rgbaMat, -1);
307+
}
308+
}
276309
}
277310

278311
markerDetector.processFrame (rgbaMat, 1);

0 commit comments

Comments
 (0)