How to achieve the user defined target in Rajawali-Vufoira android?

1k views Asked by At

I am currently using Rajawali sdk(https://github.com/Rajawali/RajawaliVuforia) for developing my android augmented reality application. Here i am able to change the targets like Frame marker,Image targets and its working perfectly. But i would like to implement the user defined target in my application. Is there any options or features available in rajawali to implement the user defined targets. Thanks for helping

1

There are 1 answers

6
Augmented Jacob On

Using the Image class

  • Register for the desired image format using the CameraDevice.SetFrameFormat method: CameraDevice.Instance.SetFrameFormat(Image.PIXEL_FORMAT.RGB888, true);

  • Call this method after QCARBehaviour has a chance to run its Start method.

  • Use the Unity script-ordering feature, or do this once in an Update callback.

  • Retrieve the image using the CameraDevice.GetCameraImage method.

  • Take this action from the ITrackerEventHandler.OnTrackablesUpdated callback. That way you can ensure that you retrieve the latest camera image that matches the current frame.

Always make sure that the camera image is not null, since it can take a few frames for the image to become available after registering for an image format.

Here is the full script:

using UnityEngine;
using System.Collections;
public class CameraImageAccess : MonoBehaviour 
{
    private Image.PIXEL_FORMAT m_PixelFormat = Image.PIXEL_FORMAT.RGB888;
    private bool m_RegisteredFormat = false;
    private bool m_LogInfo = true;
    void Start()
    {
        QCARBehaviour qcarBehaviour = (QCARBehaviour) FindObjectOfType(typeof(QCARBehaviour));
        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated);
        }
    }
    public void OnTrackablesUpdated()
    {
        if (!m_RegisteredFormat)
        {
            CameraDevice.Instance.SetFrameFormat(m_PixelFormat, true);
            m_RegisteredFormat = true;
        }
        if (m_LogInfo)
        {
            CameraDevice cam = CameraDevice.Instance;
            Image image = cam.GetCameraImage(m_PixelFormat);
            if (image == null)
            {
                Debug.Log(m_PixelFormat + " image is not available yet");
            }
            else
            {
                string s = m_PixelFormat + " image: \n";
                s += "  size: " + image.Width + "x" + image.Height + "\n";
                s += "  bufferSize: " + image.BufferWidth + "x" + image.BufferHeight + "\n";
                s += "  stride: " + image.Stride;
                Debug.Log(s);
                m_LogInfo = false;
            }
        }
    }
}