public override bool SetFrameFormat(Image.PIXEL_FORMAT format, bool enabled) { if (enabled) { if (!this.mCameraImages.ContainsKey(format)) { if (QCARWrapper.Instance.QcarSetFrameFormat((int)format, 1) == 0) { Debug.LogError("Failed to set frame format"); return(false); } Image image = new ImageImpl { PixelFormat = format }; this.mCameraImages.Add(format, image); return(true); } } else if (this.mCameraImages.ContainsKey(format)) { if (QCARWrapper.Instance.QcarSetFrameFormat((int)format, 0) == 0) { Debug.LogError("Failed to set frame format"); return(false); } return(this.mCameraImages.Remove(format)); } return(true); }
/// <summary> /// Update is called once per frame /// </summary> void Update() { // Skip if QCAR has not been initialized yet if (mQCARInitialized) { if (!mRegisteredFormat) { //first time update or first resume after pause //see OnApplicationPaused() above mFormat = Image.PIXEL_FORMAT.RGB888;// Choose the Frame Format you want here CameraDevice.Instance.SetFrameFormat(mFormat, false); if (CameraDevice.Instance.SetFrameFormat(mFormat, true)) { mDebugMsg = mFormat.ToString() + " successfully set."; mRegisteredFormat = true; } else { mDebugMsg = "Failed to set RGB888."; mFormat = Image.PIXEL_FORMAT.UNKNOWN_FORMAT; } } Image img = CameraDevice.Instance.GetCameraImage(mFormat); if (img != null) { mImageInfo = img.Width + " x " + img.Height + " " + "Pixels:" + img.Pixels[0] + ", " + img.Pixels[1] + " ..."; } else { mImageInfo = "Can't get Image for " + mFormat.ToString(); } } }
// Enables or disables the request of the camera image in the desired pixel // format. Returns true on success, false otherwise. Note that this may // result in processing overhead. Image are accessed using GetCameraImage. // Note that there may be a delay of several frames until the camera image // becomes availables. public bool SetFrameFormat(Image.PIXEL_FORMAT format, bool enabled) { if (enabled) { if (!mCameraImages.ContainsKey(format)) { if (qcarSetFrameFormat((int)format, 1) == 0) { Debug.LogError("Failed to set frame format"); return(false); } Image newImage = new Image(); newImage.PixelFormat = format; mCameraImages.Add(format, newImage); return(true); } } else { if (mCameraImages.ContainsKey(format)) { if (qcarSetFrameFormat((int)format, 0) == 0) { Debug.LogError("Failed to set frame format"); return(false); } return(mCameraImages.Remove(format)); } } return(true); }
// Use this for initialization void Start() { #if UNITY_EDITOR mPixelFormat = Image.PIXEL_FORMAT.GRAYSCALE; // Need Grayscale for Editor #else mPixelFormat = Image.PIXEL_FORMAT.RGB888; // Use RGB888 for mobile #endif VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted); VuforiaARController.Instance.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated); }
void Start() { #if UNITY_EDITOR mPixelFormat = Image.PIXEL_FORMAT.RGBA8888; #else mPixelFormat = Image.PIXEL_FORMAT.RGB888; // Use RGB888 for mobile #endif // Register Vuforia life-cycle callbacks: VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted); VuforiaARController.Instance.RegisterOnPauseCallback(OnPause); }
public override Image GetCameraImage(Image.PIXEL_FORMAT format) { if (this.mCameraImages.ContainsKey(format)) { Image image = this.mCameraImages[format]; if (image.IsValid()) { return(image); } } return(null); }
private void ForceFrameFormat(Image.PIXEL_FORMAT format, bool enabled) { if (!enabled && this.mForcedCameraFormats.Contains(format)) { this.mForcedCameraFormats.Remove(format); } bool flag = this.SetFrameFormat(format, enabled); if ((enabled & flag) && !this.mForcedCameraFormats.Contains(format)) { this.mForcedCameraFormats.Add(format); } }
public VuforiaQRTokenScanner() { m_barcodeReader = new BarcodeReader(); #if UNITY_EDITOR m_pixelFormat = Image.PIXEL_FORMAT.GRAYSCALE; // Need Grayscale for Editor m_bitmapFormat = RGBLuminanceSource.BitmapFormat.Gray8; #else m_pixelFormat = Image.PIXEL_FORMAT.RGB888; // Use RGB888 for mobile m_bitmapFormat = RGBLuminanceSource.BitmapFormat.RGB24; #endif }
public ImageImpl() { this.mWidth = 0; this.mHeight = 0; this.mStride = 0; this.mBufferWidth = 0; this.mBufferHeight = 0; this.mPixelFormat = Image.PIXEL_FORMAT.UNKNOWN_FORMAT; this.mData = null; this.mUnmanagedData = IntPtr.Zero; this.mDataSet = false; this.mPixel32 = new Color32[0]; }
void Start() { rend = GetComponent <Renderer>(); #if UNITY_EDITOR mPixelFormat = Image.PIXEL_FORMAT.RGBA8888; #else mPixelFormat = Image.PIXEL_FORMAT.RGB888; // Use RGB888 for mobile #endif // Register Vuforia life-cycle callbacks: VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted); VuforiaARController.Instance.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated); VuforiaARController.Instance.RegisterOnPauseCallback(OnPause); }
// Returns a camera images for the requested format. Returns null if // this image is not available. You must call SetFrameFormat before // accessing the corresponding camera image. public Image GetCameraImage(Image.PIXEL_FORMAT format) { // Has the format been requested: if (mCameraImages.ContainsKey(format)) { // Check the image is valid: Image image = mCameraImages[format]; if (image.IsValid()) { return(image); } } // No valid image of this format: return(null); }
private TextureFormat ConvertPixelFormat(Image.PIXEL_FORMAT input) { Image.PIXEL_FORMAT pIXEL_FORMAT = this.mPixelFormat; if (pIXEL_FORMAT == Image.PIXEL_FORMAT.RGB565) { return(TextureFormat.RGB565); } if (pIXEL_FORMAT == Image.PIXEL_FORMAT.RGB888) { return(TextureFormat.RGB24); } if (pIXEL_FORMAT == Image.PIXEL_FORMAT.RGBA8888) { return(TextureFormat.RGBA32); } return(TextureFormat.Alpha8); }
private TextureFormat ConvertPixelFormat(Image.PIXEL_FORMAT input) { Image.PIXEL_FORMAT mPixelFormat = this.mPixelFormat; switch (mPixelFormat) { case Image.PIXEL_FORMAT.RGB565: return(TextureFormat.RGB565); case Image.PIXEL_FORMAT.RGB888: return(TextureFormat.RGB24); } if (mPixelFormat != Image.PIXEL_FORMAT.RGBA8888) { return(TextureFormat.Alpha8); } return(TextureFormat.RGBA32); }
/// <summary> /// Use this for initialize /// </summary> void Start() { // Set frame format, RGB888 equal to RGB24 if (Application.platform == RuntimePlatform.Android) { m_PixelFormat = Image.PIXEL_FORMAT.RGB888; } else { m_PixelFormat = Image.PIXEL_FORMAT.GRAYSCALE; } // Register to have access to trackable events QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour)); if (qcarBehaviour) { qcarBehaviour.RegisterTrackerEventHandler(this); } }
public override void CopyToTexture(Texture2D texture2D) { TextureFormat format = this.ConvertPixelFormat(this.mPixelFormat); if (((texture2D.width != this.mWidth) || (texture2D.height != this.mHeight)) || (format != texture2D.format)) { texture2D.Resize(this.mWidth, this.mHeight, format, false); } int num = 1; Image.PIXEL_FORMAT mPixelFormat = this.mPixelFormat; switch (mPixelFormat) { case Image.PIXEL_FORMAT.RGB565: case Image.PIXEL_FORMAT.RGB888: num = 3; break; default: if (mPixelFormat == Image.PIXEL_FORMAT.RGBA8888) { num = 4; } break; } Color[] pixels = texture2D.GetPixels(); int num2 = 0; for (int i = 0; i < pixels.Length; i++) { for (int j = 0; j < num; j++) { pixels[i][j] = ((float)this.mData[num2++]) / 255f; } for (int k = num; k < 4; k++) { pixels[i][k] = pixels[i][k - 1]; } } texture2D.SetPixels(pixels); }
void OnVuforiaStarted() { CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO); foreach (var format in mPixelFormatOpts) { if (CameraDevice.Instance.SetFrameFormat(format, true)) { Debug.Log("Successfully registered pixel format " + mPixelFormat.ToString()); mFormatRegistered = true; mPixelFormat = format; return; } } Debug.LogError( "Failed to register pixel format " + mPixelFormat.ToString() + "\n the format may be unsupported by your device;" + "\n consider using a different pixel format."); mFormatRegistered = false; }
public override void CopyToTexture(Texture2D texture2D) { TextureFormat textureFormat = this.ConvertPixelFormat(this.mPixelFormat); if (texture2D.width != this.mWidth || texture2D.height != this.mHeight || textureFormat != texture2D.format) { texture2D.Resize(this.mWidth, this.mHeight, textureFormat, false); } int num = 1; Image.PIXEL_FORMAT pIXEL_FORMAT = this.mPixelFormat; if (pIXEL_FORMAT != Image.PIXEL_FORMAT.RGB565 && pIXEL_FORMAT != Image.PIXEL_FORMAT.RGB888) { if (pIXEL_FORMAT == Image.PIXEL_FORMAT.RGBA8888) { num = 4; } } else { num = 3; } Color[] pixels = texture2D.GetPixels(); int num2 = 0; for (int i = 0; i < pixels.Length; i++) { for (int j = 0; j < num; j++) { pixels[i][j] = (float)this.mData[num2++] / 255f; } for (int k = num; k < 4; k++) { pixels[i][k] = pixels[i][k - 1]; } } texture2D.SetPixels(pixels); }
private IEnumerator InitializeCamera() { yield return(new WaitForSeconds(1.25f)); var isAutoFocus = CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO); Image.PIXEL_FORMAT mPixelFormat = Image.PIXEL_FORMAT.GRAYSCALE; // Need Grayscale for Editor if (CameraDevice.Instance.SetFrameFormat(mPixelFormat, true)) { Debug.Log("Successfully registered pixel format " + mPixelFormat.ToString()); } else { Debug.Log("didnt registered pixel format " + mPixelFormat.ToString()); } if (!isAutoFocus) { CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_NORMAL); } Debug.Log(String.Format("AutoFocus : {0}", isAutoFocus)); cameraInitialized = true; }
/// <summary> /// Returns a camera images for the requested format. Returns null if /// this image is not available. You must call SetFrameFormat before /// accessing the corresponding camera image. /// </summary> public abstract Image GetCameraImage(Image.PIXEL_FORMAT format);
public VuforiaCamera() { // RGBA8888 is the most common pixel format, but it may not work with your device. Test others. VuforiaARCamera = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGBA8888); currentPixelFormat = Image.PIXEL_FORMAT.RGBA8888; }
public VuforiaCamera(Image.PIXEL_FORMAT pixelFormat) { VuforiaARCamera = CameraDevice.Instance.GetCameraImage(pixelFormat); currentPixelFormat = pixelFormat; }
/// <summary> /// Enables or disables the request of the camera image in the desired pixel /// format. Returns true on success, false otherwise. Note that this may /// result in processing overhead. Image are accessed using GetCameraImage. /// Note that there may be a delay of several frames until the camera image /// becomes availables. /// </summary> public abstract bool SetFrameFormat(Image.PIXEL_FORMAT format, bool enabled);