🖼️

Setting Up Image Recognition in AR Foundation Unity Project

Jul 13, 2024

How to Set Up Image Recognition in AR Foundation Unity Project

Project Preparation

  • **Ensure AI Deployment Readiness: **
    • Go to build settings and check iOS
    • Import all XR packages from the package manager

Package Version

  • Minimum Required Version:
    • Version 2.2.0 for using image recognition
    • Preview versions can be used if necessary

Adding AR Tracked Image Manager

  1. **Navigate to Session Origin: **
  • Add component "AR Tracked Image Manager"
  1. AR Tracked Image Manager Options:
  • Reference Library: Defines which images to track
    • Max number of moving images: Set how many images to detect
    • AR Tracked Image Prefab: Prefab instantiated when image recognized

Creating XR Reference Image Library

  1. **Create Scriptable Object: **
  • Right-click: Create > XR > Reference Image Library
    • Add images from your desktop to this library
  1. **Specify Image Properties: **
  • Set size (e.g., 30 cm) and Keep Texture Runtime option

Scripting the Image Recognition

  1. Create C# Script:
  • Name it ImageRecognitionExample
  1. Script Edits:
  • Add references for AR Tracked Image Manager and necessary Unity libraries
    • Implement the OnEnable and OnDisable methods for event subscription
    • Write OnImageChanged method to handle image recognition events
    • Iterate through the list of arcs.added to handle recognized images

Instantiating Recognized Images

  1. **Create Prefab: **
  • Create a 3D cube in the hierarchy
    • Adjust position and size, then convert it into a prefab
  1. **Assign Prefab: **
  • Assign this prefab in the AR Tracked Image Prefab

Building the Project

  1. **Build Settings: **
  • Switch to iOS or Android depending on requirements
    • Build and save the project

Final Steps

  • **Test Image Recognition: **
    • Open the recognized image, and observe the instantiation and movement of the prefab (e.g., a cube)
  • **Customization: **
    • Use animations, add sounds, or implement additional functionalities as needed

Conclusion

  • Wrap Up:
    • Like and subscribe if the video was helpful
    • Leave questions or video suggestions in the comments