Log in or register to post comments

AR Camera Problem Has A Few Issue

August 23, 2016 - 3:50am #1

Hello, Today, i have found out a problem in my project with the AR Camera. I get the coordinates of the ImageTargets with this script on the following link: https://developer.vuforia.com/forum/faq/unity-how-can-i-get-target-screen-coordinates with the AR Camera Settings below: And, I debug all image targets position.x when there is one or more image targets on the screen.

The problem is, some of the image targets are not being recognized by screen coordinate script and i can't get their position.x. Right now, i have eleven image targets with my project and 5 of them gives me position.x but the rest doesn't give me position.x.

When i change the World Center Mode to "FIRST_TARGET", i can get all image targets position but this also doesn't work correctly. When i show one image target to camera, it shows all image targets position.x as the position of that image target i show.

For example; When i show one image target with "FIRST_TARGET" setting in AR Camera, the debug seems like this:

</p>
Debug.Log("First Image Position X = " + firstImagePositionX); - seems as 1000(according to position of it in screen)</p>
Debug.Log("Second Image Position X = " + secondImagePositionX); - this one also seems as 1000</p>
Debug.Log("Third Image Position X = " + thirdImagePositionX); - this one also seems as 1000</p>
Debug.Log("Fourth Image Position X = " + fourthImagePositionX); - this one also seems as 1000</p>
Debug.Log("Fifth Image Position X = " + fifthImagePositionX); - this one also seems as 1000</p>
<p>

But when i change the "WORLD CENTER MODE" to "CAMERA", debugs are changed like that and show the first image target to the camera, it seems like that;

</p>
Debug.Log("First Image Position X = " + firstImagePositionX);- seems as 1000(according to position of it in screen)</p>
Debug.Log("Second Image Position X = " + secondImagePositionX); - this one also seems as 0 (That's what it needs to be)</p>
Debug.Log("Third Image Position X = " + thirdImagePositionX); - this one also seems as 0 (That's what it needs to be)</p>
Debug.Log("Fourth Image Position X = " + fourthImagePositionX); - this one also seems as 0 (That's what it needs to be)</p>
Debug.Log("Fifth Image Position X = " + fifthImagePositionX); - this one also seems as 0 (That's what it needs to be)</p>
<p>

But this time, i can't get the all image targets position. Like i said before, the script gives me only five image targets position. It doesn't read the rest of the image targets position even if they are being rode and they are spawn their 3D objects onto them.

Here is my script:

using UnityEngine;
using System.Collections;
using Vuforia;
using System.Collections.Generic;

public class Test : MonoBehaviour {

	private ImageTargetBehaviour mImageTargetBehaviour = null;

	public static List<string> firstImages = new List<string>{ "mp4", "mg3", "pistol"};
	public static List<string> secondImages = new List<string>{ "apple", "meat", "banana"};
	public static List<string> thirdImages = new List<string>{"car1","car2","car3", "car4", "car5"};
	public static List<string> fourthImages = new List<string>{ "character1", "character2", "character3", "character4", "character5", "character6"};
	public static List<string> fifthImages = new List<string>{ "knife", "sword"};

	public Manager manager;

	// Use this for initialization
	void Start () {
		// We retrieve the ImageTargetBehaviour component
		// Note: This only works if this script is attached to an ImageTarget
		mImageTargetBehaviour = GetComponent<ImageTargetBehaviour>();

		if (mImageTargetBehaviour == null)
		{
			Debug.Log ("ImageTargetBehaviour not found ");
		}
	}

	// Update is called once per frame
	void Update () {
		if (mImageTargetBehaviour == null)
		{
			Debug.Log ("ImageTargetBehaviour not found");
			return;
		}

		Vector2 targetSize = mImageTargetBehaviour.GetSize();
		float targetAspect = targetSize.x / targetSize.y;

		// We define a point in the target local reference 
		// we take the bottom-left corner of the target, 
		// just as an example
		// Note: the target reference plane in Unity is X-Z, 
		// while Y is the normal direction to the target plane
		Vector3 pointOnTarget = new Vector3(-0.5f, 0, -0.5f/targetAspect); 

		// We convert the local point to world coordinates
		Vector3 targetPointInWorldRef = transform.TransformPoint(pointOnTarget);

		// We project the world coordinates to screen coords (pixels)
		Vector3 screenPoint = Camera.main.WorldToScreenPoint(targetPointInWorldRef);

		if(firstImages.Contains(this.gameObject.name))
		{
			Manager.firstImagePositionX = screenPoint.x;
		}

		if(secondImages.Contains(this.gameObject.name))
		{
			Manager.secondImagePositionX = screenPoint.x;
		}

		if(thirdImages.Contains(this.gameObject.name))
		{
			Manager.thirdImagePositionX = screenPoint.x;
		}

		if(fourthImages.Contains(this.gameObject.name))
		{
			Manager.fourthImagePositionX = screenPoint.x;

		}
		if(fifthImages.Contains(this.gameObject.name))
		{
			Manager.fifthImagePositionX = screenPoint.x;
		}
	}
}

I hope i could tell my problem. If you have any part that you couldn't understand, please ask me. I will be waiting for your helps. Thanks.

AR Camera Problem Has A Few Issue

September 1, 2016 - 7:49am #3

Kudos to you for having an interesting problem. 2 things...

- The coordinates changing issue. This is probably because...the order that the targets are being checked depends on the order that Vuforia recognizes them. If you line them up left to right, it doesn't mean Vuforia will recognize them in that order, or any order. You should consider that the order that Vuforia has, is random and changing all the time.

- An easier way to know which target is which is to simply check the target name. I see you're working with ImageTargetBehaviour...so you can just use MyTarget.ImageTarget.Name to know the internal name of that target...which does not change...it will be the name you used when you created the target on the website. If that name isn't useful to you...you can use a "tag" (this is a unity thing not a vuforia thing): https://docs.unity3d.com/Manual/Tags.html and do something like MyTarget.gameObject.tag to get the tag you assigned to it. 

 

AR Camera Problem Has A Few Issue

August 24, 2016 - 12:16am #2

Besides of this issue, i have one another issue. After i placed for targets onto the camera and after the camera recognized them, i get their coordinates. But, if i move my hand(opened) over the image targets left to right and right to left for a few times, the coordinates of the targets changes. For example, the coordinate of the target which is at the end, becomes the coordinate of the target which is at the beginning. For short, their coordinates shifts within each other. I think this could be a bug of vuforia. Why could it be? The Targets must stay at the previous coordinates even if i move my hand over them. Can you please look for it, vuforia developers? Thank you!

Log in or register to post comments