Video Tracker

Related documentations
Target Manager
Recommended Conditions for Target Images
Tracker Coordinate System in Unity
Image Tracker in Unity

Instead of camera stream video, you can recognize and track flat images from external video files to enhance 3D content, video images, and chroma key images.

Video Setting

GitHub Unity Scene Example

Video Setting

  1. All settings are the same as Image Tracker.

  2. SceneManager has a VideoTrackerSample.

  3. Use the CameraDevice.GetInstance (). SetNewFrame function to input .mp4.

CameraDevice.GetInstance().SetNewFrame(texture2D.GetRawTextureData(), texture2D.GetRawTextureData().Length, texture2D.width, texture2D.height, ColorFormat.RGBA8888);

  • texture2D.GetRawTextureData() image data.
  • texture2D.GetRawTextureData().Length Length of image data.
  • texture2D.width The width of the image data.
  • texture2D.height The height of the image data.
  • ColorFormat.RGBA8888 Format of image data.

To use the above functions, you need to get a Free or Enterprise license.

  1. How to enter an external image using the VideoPlayer in UnityEngine.Video.

     videoPlayer.playOnAwake = false;
     videoPlayer.isLooping = true;
     videoPlayer.sendFrameReadyEvents = true;
     videoPlayer.frameReady += OnNewFrame;
    
     if (Application.platform == RuntimePlatform.Android)
     {
         StartCoroutine(MaxstARUtil.ExtractAssets("MaxstAR/tracking_video.mp4", (filePah) =>
         {
             videoPlayer.url = filePah;
             SwitchCameraToVideo(CameraMode);
         }));
     }
     else
     {
         videoPlayer.url = Application.streamingAssetsPath + "/MaxstAR/tracking_video.mp4";
         SwitchCameraToVideo(CameraMode);
     }
    

The process of creating videoPlayer and inputting information to the object to obtain video data.

when it start video,

void OnNewFrame(VideoPlayer source, long frameIdx)
{
    RenderTexture renderTexture = source.texture as RenderTexture;

    if (texture2D == null)
    {
        texture2D = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGBA32, false);
    }

    RenderTexture.active = renderTexture;
    texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
    texture2D.Apply();
    RenderTexture.active = null;
CameraDevice.GetInstance().SetNewFrame(texture2D.GetRawTextureData(), texture2D.GetRawTextureData().Length, texture2D.width, texture2D.height, ColorFormat.RGBA8888);
}

This function takes an image with CameraDevice.GetInstance(). SetNewFrame().

Do not use the CameraDevice.GetInstance().Start() function when using images as input.

GitHub Unity Scene Example

GitHub Unity Scene Example: https://github.com/maxstdev/MaxstARSDK_Unity_Sample.git