Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class CameraImageAccess : MonoBehaviour, ITrackerEventHandler
- {
- public QCARBehaviour qcarBehaviour;
- private Image.PIXEL_FORMAT m_PixelFormat = Image.PIXEL_FORMAT.RGB888;
- private bool m_RegisteredFormat = false;
- private bool m_LogInfo = true;
- private bool takePictureNextTrackablesUpdated = false;
- public void OnInitialized()
- {
- Debug.Log(" OnInitialized CameraImageAccess " + Time.realtimeSinceStartup);
- }
- void Start()
- {
- if (qcarBehaviour)
- {
- qcarBehaviour.RegisterTrackerEventHandler(this);
- }
- }
- public void SavePictureNextUpdate()
- {
- takePictureNextTrackablesUpdated = true;
- }
- public void OnTrackablesUpdated()
- {
- if (takePictureNextTrackablesUpdated == true)
- {
- GetFrame();
- takePictureNextTrackablesUpdated = false;
- }
- }
- private void GetFrame()
- {
- if (!m_RegisteredFormat)
- {
- bool formatOK = CameraDevice.Instance.SetFrameFormat(m_PixelFormat, true);
- if (formatOK)
- {
- m_RegisteredFormat = true;
- }
- else
- {
- Debug.Log("Format NOT OK, failed to set " + m_PixelFormat);
- return;
- }
- }
- CameraDevice cam = CameraDevice.Instance;
- Image image = cam.GetCameraImage(m_PixelFormat);
- StartCoroutine(ImageSaver(image));
- }
- IEnumerator ImageSaver(Image image)
- {
- while (image == null)
- {
- yield return new WaitForSeconds(0.03f);
- Debug.Log(m_PixelFormat + " image is not available yet ");
- }
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement