Advertisement
Guest User

vuforia camera picture

a guest
Apr 12th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. public class CameraImageAccess : MonoBehaviour, ITrackerEventHandler
  4. {
  5.     public QCARBehaviour qcarBehaviour;
  6.     private Image.PIXEL_FORMAT m_PixelFormat = Image.PIXEL_FORMAT.RGB888;
  7.     private bool m_RegisteredFormat = false;
  8.     private bool m_LogInfo = true;
  9.  
  10.     private bool takePictureNextTrackablesUpdated = false;
  11.  
  12.     public void OnInitialized()
  13.     {
  14.         Debug.Log(" OnInitialized CameraImageAccess " + Time.realtimeSinceStartup);
  15.     }
  16.  
  17.     void Start()
  18.     {
  19.         if (qcarBehaviour)
  20.         {
  21.             qcarBehaviour.RegisterTrackerEventHandler(this);
  22.         }
  23.     }
  24.  
  25.     public void SavePictureNextUpdate()
  26.     {
  27.         takePictureNextTrackablesUpdated = true;
  28.     }
  29.  
  30.     public void OnTrackablesUpdated()
  31.     {
  32.         if (takePictureNextTrackablesUpdated == true)
  33.         {
  34.             GetFrame();
  35.             takePictureNextTrackablesUpdated = false;
  36.         }
  37.     }
  38.  
  39.     private void GetFrame()
  40.     {
  41.         if (!m_RegisteredFormat)
  42.         {
  43.             bool formatOK = CameraDevice.Instance.SetFrameFormat(m_PixelFormat, true);
  44.             if (formatOK)
  45.             {
  46.                 m_RegisteredFormat = true;
  47.             }
  48.             else
  49.             {
  50.                 Debug.Log("Format NOT OK, failed to set " + m_PixelFormat);
  51.                 return;
  52.             }
  53.         }
  54.        
  55.         CameraDevice cam = CameraDevice.Instance;
  56.         Image image = cam.GetCameraImage(m_PixelFormat);
  57.         StartCoroutine(ImageSaver(image));
  58.  
  59.     }
  60.  
  61.     IEnumerator ImageSaver(Image image)
  62.     {
  63.         while (image == null)
  64.         {
  65.             yield return new WaitForSeconds(0.03f);
  66.             Debug.Log(m_PixelFormat + " image is not available yet ");
  67.         }
  68.  
  69.         string s = m_PixelFormat + " image: \n";
  70.         s += "  size: " + image.Width + "x" + image.Height + "\n";
  71.         s += "  bufferSize: " + image.BufferWidth + "x" + image.BufferHeight + "\n";
  72.         s += "  stride: " + image.Stride;
  73.         Debug.Log(s);
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement