Esempio n. 1
0
    /*
     * Get snaped image from camera
     */
    private Texture2D TakeTextureSnap()
    {
        Vuforia.Image captured = CameraDevice.Instance.GetCameraImage(mPixelFormat);

        if (captured == null || !captured.IsValid())
        {
            return(null);
        }

        byte[] pixels = captured.Pixels;

        if (pixels == null || pixels.Length <= 0)
        {
            return(null);
        }

        // Make temperate Texture2D to copy camera pixel data
        Texture2D tmp = new Texture2D(captured.Width, captured.Height, TextureFormat.RGB24, false);

        captured.CopyToTexture(tmp);

        /*
         * TODO: Change captureImageWidth to be proportional to Screen.width
         */
        return(TextureTools.CropWithRect(
                   tmp,
                   //new Rect(0, 0, Mathf.Min(tmp.width, Screen.width), Mathf.Min(tmp.height, Screen.height)),
                   //new Rect(0, 0, 610, 1280),
                   new Rect(0, 0, capturedImageWidth, capturedImageWidth),
                   TextureTools.RectOptions.Center,
                   0, 0));
    }
Esempio n. 2
0
    private void ScanQRCode()
    {
        if (mFormatRegistered)
        {
            if (mAccessCameraImage)
            {
                Vuforia.Image image = CameraDevice.Instance.GetCameraImage(mPixelFormat); //DC this is where problem is
                if (image != null && image.IsValid())
                {
                    string imageInfo = mPixelFormat + " image: \n";
                    imageInfo += " size: " + image.Width + " x " + image.Height + "\n";
                    imageInfo += " bufferSize: " + image.BufferWidth + " x " + image.BufferHeight + "\n";
                    imageInfo += " stride: " + image.Stride;
                    Debug.Log(imageInfo);
                    byte[] pixels = image.Pixels;

                    if (pixels != null && pixels.Length > 0)
                    {
                        Debug.Log("Image pixels: " + pixels[0] + "," + pixels[1] + "," + pixels[2] + ",...");
                        Texture2D tex = new Texture2D(image.BufferWidth, image.BufferHeight, TextureFormat.RGB24, false); // RGB24
                        tex.LoadRawTextureData(pixels);
                        tex.Apply();
                        m_Texture             = tex;
                        m_RawImageBig.texture = tex;
                        m_RawImageBig.material.mainTexture = tex;
                        //QRCodeChecker qr = QRCodeChecker.getSingleton();
                        //Debug.Log(qr.findQRCodeInImage(m_Texture));
                    }
                }
            }
        }
    }
 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);
 }
Esempio n. 4
0
    public void TakePhoto(bool display)
    {
        if (mFormatRegistered)
        {
            if (mAccessCameraImage)
            {
                Vuforia.Image image = CameraDevice.Instance.GetCameraImage(mPixelFormat);
                if (image != null && image.IsValid())
                {
                    /*
                     * string imageInfo = mPixelFormat + " image: \n";
                     * imageInfo += " size: " + image.Width + " x " + image.Height + "\n";
                     * imageInfo += " bufferSize: " + image.BufferWidth + " x " + image.BufferHeight + "\n";
                     * imageInfo += " stride: " + image.Stride;
                     * Debug.Log(imageInfo);*/
                    byte[] pixels = image.Pixels;

                    if (pixels != null && pixels.Length > 0)
                    {
                        if (display)
                        {
                            //Debug.Log("Image pixels: " + pixels[0] + "," + pixels[1] + "," + pixels[2] + ",...");
                            Texture2D tex = new Texture2D(image.BufferWidth, image.BufferHeight, TextureFormat.RGB24, false); // RGB24
                            tex.LoadRawTextureData(pixels);
                            tex.Apply();
                            m_Texture = tex;
                            //since I noticed this was set to null in the main scene, I decided to save my network code if someone derps.
                            if (m_RawImageBig)
                            {
                                m_RawImageBig.texture = tex;
                                m_RawImageBig.material.mainTexture = tex;
                            }
                            else
                            {
                                Debug.LogError("You didn't assign m_RawImageBig");
                            }
                            if (m_RawImageSmall)
                            {
                                m_RawImageSmall.texture = tex;
                                m_RawImageSmall.material.mainTexture = tex;
                            }
                            else
                            {
                                Debug.LogError("You didn't assign m_RawImageSmall");
                            }
                            //ServerConnect.S.sendPicture(m_Texture);
                        }
                    }
                }
            }
        }
    }
Esempio n. 5
0
 /// <summary>
 /// Vuforia 图片格式转为Color32
 /// </summary>
 /// <param name="a"></param>
 /// <returns></returns>
 Color32[] ImageToColor32(Vuforia.Image a)
 {
     if (!a.IsValid())
     {
         return(null);
     }
     Color32[] r = new Color32[a.BufferWidth * a.BufferHeight];
     for (int i = 0; i < r.Length; i++)
     {
         r[i].r = r[i].g = r[i].b = a.Pixels[i];
     }
     return(r);
 }
Esempio n. 6
0
    public void TakePhoto()
    {
        /*
         * RegisterFormat();
         * Vuforia.Image image = CameraDevice.Instance.GetCameraImage(mPixelFormat);
         *
         * if (image != null)
         * {
         *  Texture2D tex = new Texture2D(1280, 720, TextureFormat.RGB24, false);
         *  tex.LoadRawTextureData(image.Pixels);
         *  tex.Apply();
         *  //tex.LoadImage(image.Pixels);
         *  m_Texture = tex;
         * }
         */

        if (mFormatRegistered)
        {
            if (mAccessCameraImage)
            {
                Vuforia.Image image = CameraDevice.Instance.GetCameraImage(mPixelFormat);
                if (image != null && image.IsValid())
                {
                    string imageInfo = mPixelFormat + " image: \n";
                    imageInfo += " size: " + image.Width + " x " + image.Height + "\n";
                    imageInfo += " bufferSize: " + image.BufferWidth + " x " + image.BufferHeight + "\n";
                    imageInfo += " stride: " + image.Stride;
                    Debug.Log(imageInfo);
                    byte[] pixels = image.Pixels;

                    if (pixels != null && pixels.Length > 0)
                    {
                        Debug.Log("Image pixels: " + pixels[0] + "," + pixels[1] + "," + pixels[2] + ",...");
                        Texture2D tex = new Texture2D(image.BufferWidth, image.BufferHeight, TextureFormat.RGB24, false); // RGB24
                        tex.LoadRawTextureData(pixels);
                        tex.Apply();
                        m_Texture             = tex;
                        m_RawImageBig.texture = tex;
                        m_RawImageBig.material.mainTexture = tex;
                        QRCodeChecker qr = QRCodeChecker.getSingleton();
                        Debug.Log(qr.findQRCodeInImage(m_Texture));
                    }
                }
            }
        }
    }