Example #1
0
    void sendToVuforia()
    {
        //Debug.Log("capturing image for vuforia");
        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

        sw.Reset();
        sw.Start();
        Texture2D colorTexture = (Texture2D)imageCube.GetComponent <Renderer>().material.mainTexture;

        sw.Stop();
        //Debug.Log("time to acquire texture pointer: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        RenderTexture colorRT = new RenderTexture(colorTexture.width, colorTexture.height, 24, RenderTextureFormat.ARGB32);

        sw.Stop();
        //Debug.Log("time to declare render texture: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        Graphics.Blit(colorTexture, colorRT); //move it from colortexture gpu to rendertexture
        sw.Stop();
        //Debug.Log("time to blit texture to render texture: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        RenderTexture.active = colorRT;
        sw.Stop();
        //Debug.Log("time to make render texture active: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));


        //debugFreezeRendertexture = colorRT;
        sw.Reset();
        sw.Start();
        Texture2D colorFreeze = new Texture2D(colorTexture.width, colorTexture.height, TextureFormat.ARGB32, false);

        sw.Stop();
        //Debug.Log("time to declare a freeze texture: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        colorFreeze.ReadPixels(new UnityEngine.Rect(0, 0, colorTexture.width, colorTexture.height), 0, 0);
        sw.Stop();
        //Debug.Log("time to read pixels from rendertexture: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        byte[] c         = colorFreeze.GetRawTextureData();
        string outstring = "";

        for (int i = 0; i < 50; i++)
        {
            outstring += c[i] + "-";
        }
        //Debug.Log("first 50: " + outstring);

        sw.Reset();
        sw.Start();
        colorFreeze.Apply();
        sw.Stop();
        //Debug.Log("time to do apply: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));



        sw.Reset();
        sw.Start();
        byte[] b = colorFreeze.GetRawTextureData();
        sw.Stop();
        //Debug.Log("time to return raw texture data: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));
        //Array.Reverse(b);

        string outstring2 = "";

        for (int i = 0; i < 50; i++)
        {
            outstring2 += b[i] + "-";
        }
        //Debug.Log("first 50: " + outstring2);

        /*
         * //flip up down:
         * byte[] b_flip = new byte[b.Length];
         * for (int i = 0; i < colorFreeze.height; i++)
         * {
         *  for (int j = 0; j < 4 * colorFreeze.width; j++)
         *  {
         *      b_flip[i * (colorFreeze.width * 4) + j] = b[((colorFreeze.height - 1) - i) * (colorFreeze.width * 4) + j];
         *  }
         * }
         * //b = b_flip;
         */

        sw.Reset();
        sw.Start();
        string image_data = System.Convert.ToBase64String(b);

        sw.Stop();
        //Debug.Log("time to convert to base 64: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));


        sw.Reset();
        sw.Start();
        JSONNode vuforiaRequest = new SimpleJSON.JSONObject();

        vuforiaRequest.Add("imageData", image_data);
        vuforiaRequest.Add("imageWidth", colorFreeze.width);
        vuforiaRequest.Add("imageHeight", colorFreeze.height);

        vuforiaRequest.Add("A_offset", 0);
        vuforiaRequest.Add("R_offset", 1);
        vuforiaRequest.Add("G_offset", 2);
        vuforiaRequest.Add("B_offset", 3);
        string data = vuforiaRequest.ToString();

        sw.Stop();
        //Debug.Log("time to make vuforia string: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        GameObject.Find("pusher").GetComponent <Pusher>().sendToVuforia(data);
        sw.Stop();
        //Debug.Log("time to send vuforia string: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));

        sw.Reset();
        sw.Start();
        DestroyImmediate(colorRT);
        DestroyImmediate(colorFreeze);
        sw.Stop();
        //Debug.Log("time to destroy resources: " + ((float)sw.ElapsedTicks / (float)System.TimeSpan.TicksPerMillisecond).ToString("F6"));
    }
Example #2
0
 public override void Add(string aKey, JSONNode aItem)
 {
     var tmp = new JSONObject();
     tmp.Add(aKey, aItem);
     Set(tmp);
 }
Example #3
0
    public void saveVuforiaObjectsToFile()
    {
        //update position of this object's struct in the dictionary:
        updateStructsBasedOnGameObjects();

        JSONArray ja = new JSONArray();

        foreach (KeyValuePair <string, realityEditorObjectStruct> pair in realityEditorObjectDict)
        {
            //Debug.Log("save operating on: " + pair.Key + " " + pair.Value.ip);
            //Debug.Log("content of struct");
            Debug.Log(pair.Value.id + " " + pair.Value.ip + " " + pair.Value.temporaryChecksum + " " + pair.Value.versionNumber + " " + pair.Value.zone + " " + pair.Value.xmlAddress + " " + pair.Value.datAddress);

            //Debug.Log("temporary checksum value: " + pair.Value.temporaryChecksum + " nulloperator: " + (pair.Value.temporaryChecksum ?? "null") + " ==\"\"?" + (pair.Value.temporaryChecksum == ""));

            JSONNode jo = new SimpleJSON.JSONObject();
            jo.Add("id", pair.Value.id ?? "");
            jo.Add("ip", pair.Value.ip ?? "");
            jo.Add("temporaryChecksum", pair.Value.temporaryChecksum ?? "");
            jo.Add("versionNumber", pair.Value.versionNumber ?? "");
            jo.Add("zone", pair.Value.zone ?? "");
            jo.Add("xmlAddress", pair.Value.xmlAddress ?? "");
            jo.Add("dataAddress", pair.Value.datAddress ?? "");
            jo.Add("Tx", pair.Value.position.x);
            jo.Add("Ty", pair.Value.position.y);
            jo.Add("Tz", pair.Value.position.z);
            jo.Add("Qx", pair.Value.rotation.x);
            jo.Add("Qy", pair.Value.rotation.y);
            jo.Add("Qz", pair.Value.rotation.z);
            jo.Add("Qw", pair.Value.rotation.w);

            /*
             * jo.Add("id", pair.Value.id);
             * jo.Add("ip", pair.Value.ip);
             * jo.Add("temporaryChecksum", pair.Value.temporaryChecksum);
             * jo.Add("versionNumber", pair.Value.versionNumber);
             * jo.Add("zone", pair.Value.zone);
             * jo.Add("xmlAddress", pair.Value.xmlAddress);
             * jo.Add("dataAddress", pair.Value.datAddress);
             * jo.Add("Tx", pair.Value.position.x);
             * jo.Add("Ty", pair.Value.position.y);
             * jo.Add("Tz", pair.Value.position.z);
             * jo.Add("Qx", pair.Value.rotation.x);
             * jo.Add("Qy", pair.Value.rotation.y);
             * jo.Add("Qz", pair.Value.rotation.z);
             * jo.Add("Qw", pair.Value.rotation.w);
             */
            //JSONNode cameraCalibrationResult = new JSONObject();
            //cameraCalibrationResult.Add("camera_enumeration", 1);
            //cameraCalibrationResult.Add("serial_number", "cool");


            //jo["id"] = pair.Value.id;

            /*
             * jo["ip"] = pair.Value.ip;
             * jo["temporaryChecksum"] = pair.Value.temporaryChecksum;
             * jo["versionNumber"] = pair.Value.versionNumber;
             * jo["zone"] = pair.Value.zone;
             * jo["xmlAddress"] = pair.Value.xmlAddress;
             * jo["datAddress"] = pair.Value.datAddress;
             *
             *
             *
             *
             *
             *
             * jo["Tx"] = pair.Value.position.x;
             * jo["Ty"] = pair.Value.position.y;
             * jo["Tz"] = pair.Value.position.z;
             * jo["Qx"] = pair.Value.rotation.x;
             * jo["Qy"] = pair.Value.rotation.y;
             * jo["Qz"] = pair.Value.rotation.z;
             * jo["QW"] = pair.Value.rotation.w;
             */
            //Debug.Log("camera calibration result: " + cameraCalibrationResult.ToString());
            //Debug.Log("adding jo: " + jo.ToString());

            ja.Add(jo);
        }
        //Debug.Log("json array: " + ja.ToString());
        System.IO.File.WriteAllText("vuforiaSaved.txt", ja.ToString());
    }