Unity uses vuforia to develop AR entry

Overview:

  Reference: http://www.chinaar.com/Vuforia/5192.html According to this article, you can basically do it, but you will still encounter some problems

1. Plug-in download

  Go to the official website: https://developer.vuforia.com/downloads/sdk Select Download Unity Extension (legacy), register to download

  image

Second, the use of plug-ins

  1. Build the project in Unity and import the plugin

  2. Delete the MainCamera in the scene, and drag the ARCamera camera in the Vuforia/Prefabs directory to the scene

  3. Drag the ImageTarget under the Vuforia/Prefabs directory to the scene, and adjust the camera position and angle until the following view appears on the browse page:

  image

  4. Then add the image we want to identify to this panel, then we need to upload the image to Qualcomm's internal image library

3. Background preparation

  1. Click Develop on the vuforia official website to go to the developer background

  2. Click Target Manager, Add Database to create a Database

  image

  3. Enter the name, select Device as Type

  image

  4. Create Target in Database

  image

  image

  Note that the Width unit here is meters. In addition, there is a requirement for the uploaded image. If the image is colored, it can only be 24-bit RGB color.

  image

  If the image you want to upload is 32-bit, you can use Paint or PS to modify it: create a new image in PS, select RGB8-bit for the color mode, and white for the background content. Here, if you choose white, the picture will be 24-bit, and if you choose transparent, it will be 32-bit. Then drag your image in, crop it, and save it as a png

  image

  5. After the picture is uploaded successfully, you will find that the system has a score for the picture. The higher the score, the clearer the picture features and the easier it is to identify. It is said that pictures with at least 3 stars can be used.

  image

  6. Select the image you want, click Download Database, and then select Unity Editor to download the resource pack

  image

  7. Go to Licence Manager, click Get Development Key

  image

  8. Enter the name of the project to get the Licence Key

Fourth, return to the unity project

  1. Import the just generated test.unitypackage into the project

  2. Go to the Image Target Behaviour component of the ImageTarget object and set its Database and Image Target

  image

  3. After this operation, if you find that the ImageTarget is still white, find the image you just imported into the project, change its Texture Shape to 2D, and then you can see that the ImageTarget has displayed the image to be recognized.

  image

  image

  4. Drag the model into the scene and use it as a child of ImageTarget. When the device recognizes the image, the model will appear in the same position

  image

  5. Open the Vuforia configuration in ARCamera, fill in the Licence Key obtained before into the App License Key, and then check Load test Database and Activate

  image

  image

  6. Publish the project to Android, and it can run on the mobile phone. If the computer has a camera, running it in the editor can also get the same effect

  7. If you feel that the image displayed on the mobile phone is very blurry, you can use the following method to focus: create a new script CameraMode.cs, copy the following code, and then hang it on ARCamera, click the mobile phone screen to focus when the APP is running

using UnityEngine;
using System.Collections;

public class CameraMode : MonoBehaviour
{
    void Start()
    {
        Vuforia.CameraDevice.Instance.SetFocusMode(Vuforia.CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
    }

    void Update()
    {
#if UNITY_EDITOR
        if (Input.GetMouseButtonUp(0))
#elif UNITY_ANDROID || UNITY_IPHONE
            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)  
#endif
        {
            Vuforia.CameraDevice.Instance.SetFocusMode(Vuforia.CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
        }
    }
}

Screenshot of the last running on the phone:

  image


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325209064&siteId=291194637
Recommended