Log in or register to post comments

Error in script (Failed to set frame format)

August 4, 2016 - 8:53am #1

Hi,

I am trying to get the camera frames as described in the article here:

https://developer.vuforia.com/library/articles/Solution/How-To-Access-the-Camera-Image-in-Unity

But everytime i run this script it gives an error where it sets the camera frame instance

I am attaching the code as well.
I have also commented the line where it gives an error.
kindly help if anyone knows about this issue.
 

Type your code in the box. To create a new line within the box use SHIFT + ENTER. using UnityEngine;
using System.Collections;
using Vuforia;

public class CameraFrame : MonoBehaviour {

private Image.PIXEL_FORMAT m_PixelFormat = Image.PIXEL_FORMAT.RGB888;
private bool m_RegisteredFormat = false;
private bool m_LogInfo = false;
public Image image;
// Use this for initialization
void Start () {
  VuforiaBehaviour vuforiaBehaviour = (VuforiaBehaviour)FindObjectOfType (typeof(VuforiaBehaviour));
  if (vuforiaBehaviour)
  {
   vuforiaBehaviour.RegisterTrackablesUpdatedCallback (OnTrackablesUpdated);
   Debug.Log ("registered vuforia behaviour");
  }
}

// Update is called once per frame
void Update () {

}
public void OnTrackablesUpdated()
{
  Debug.Log ("Trackable updated called");
  if (!m_RegisteredFormat)
  {
   CameraDevice.Instance.SetFrameFormat(m_PixelFormat, true); //HERE IT GIVES THE ERROR
   m_RegisteredFormat = true;
  }
  if (m_LogInfo) {
   CameraDevice cam = CameraDevice.Instance;
   image = cam.GetCameraImage (m_PixelFormat);
   if (image == null) {
    Debug.Log (m_PixelFormat + " image is not available yet");
    //boxMesh.material.mainTexture = tx;

   } 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);
   }
  }
}
}


 

Error in script (Failed to set frame format)

March 20, 2018 - 3:11am #3

Hi! I have resolved this issue (Failed to set frame format) just used this construction

private Image.PIXEL_FORMAT _mPixelFormat = Image.PIXEL_FORMAT.UNKNOWN_FORMAT;
 
void Start()
{     
#if UNITY_EDITOR
_mPixelFormat = Image.PIXEL_FORMAT.GRAYSCALE;        //Need Grayscale for Editor
#else
_mPixelFormat = Image.PIXEL_FORMAT.RGB888;               //Need RGB888 for mobile
#endif       
VuforiaARController.Instance.RegisterVuforiaStartedCallback (OnVuforiaStarted);
}
 
private void OnVuforiaStarted()
{
    var isFrameFormatSet = CameraDevice.Instance.SetFrameFormat(_mPixelFormat, true);
    Debug.Log("FormatSet : " + isFrameFormatSet);
    //your code
}

Error in script (Failed to set frame format)

May 11, 2017 - 4:57am #2

Did you find what was wrong? I'm having the same issue and I can't find any solution :(

Log in or register to post comments