GetPixels32() private method

private GetPixels32 ( ) : UnityEngine.Color32[]
return UnityEngine.Color32[]
Example #1
0
 static public int GetPixels32(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 1)
         {
             UnityEngine.WebCamTexture self = (UnityEngine.WebCamTexture)checkSelf(l);
             var ret = self.GetPixels32();
             pushValue(l, ret);
             return(1);
         }
         else if (argc == 2)
         {
             UnityEngine.WebCamTexture self = (UnityEngine.WebCamTexture)checkSelf(l);
             UnityEngine.Color32[]     a1;
             checkType(l, 2, out a1);
             var ret = self.GetPixels32(a1);
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static public int GetPixels32(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 1)
         {
             UnityEngine.WebCamTexture self = (UnityEngine.WebCamTexture)checkSelf(l);
             var ret = self.GetPixels32();
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (argc == 2)
         {
             UnityEngine.WebCamTexture self = (UnityEngine.WebCamTexture)checkSelf(l);
             UnityEngine.Color32[]     a1;
             checkArray(l, 2, out a1);
             var ret = self.GetPixels32(a1);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #3
0
        /// <summary>
        /// Create a native CGImage object from a WebCamTexture.
        /// </summary>
        /// <returns>The newly created native CGImage object or null if error.</returns>
        /// <param name="texture">Texture.</param>
        /// <param name="scale">Scale.</param>
        public static CGImage FromWebCamTexture(WebCamTexture texture, float scale = 1.0f)
        {
            if (texture == null)
                return null;

            var data = texture.GetPixels32();
            return CGImage.FromPixels32(data, texture.width, texture.height, scale);
        }
Example #4
0
 static public int GetPixels32(IntPtr l)
 {
     try {
         UnityEngine.WebCamTexture self = (UnityEngine.WebCamTexture)checkSelf(l);
         var ret = self.GetPixels32();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #5
0
 static public int GetPixels32__A_Color32(IntPtr l)
 {
     try {
         UnityEngine.WebCamTexture self = (UnityEngine.WebCamTexture)checkSelf(l);
         UnityEngine.Color32[]     a1;
         checkArray(l, 2, out a1);
         var ret = self.GetPixels32(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #6
0
 static public int GetPixels32(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 1)
         {
             UnityEngine.WebCamTexture self = (UnityEngine.WebCamTexture)checkSelf(l);
             var ret = self.GetPixels32();
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (argc == 2)
         {
             UnityEngine.WebCamTexture self = (UnityEngine.WebCamTexture)checkSelf(l);
             UnityEngine.Color32[]     a1;
             checkArray(l, 2, out a1);
             var ret = self.GetPixels32(a1);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function GetPixels32 to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
		/**
		 * WebTextureで更新します。
		 */
		public void updateByWebCamTexture(WebCamTexture i_wtx)
		{
			i_wtx.GetPixels32((Color32[])this._buf);
			//this._rgb_pixel_driver.switchRaster(this);//バッファを上書きするからいらない。
			return;
		}
Example #8
0
    void Update()
    {
        if (timer < 2.0f) {
            timer += Time.deltaTime;
            return;
        }

        wct = wcb.wct;
        c = wct.GetPixels32 ();
        width = wcb.width;
        height = wcb.height;
        GetComponent<Renderer>().material.mainTexture = wct;

        // ------------------------------------------------------------------------
        // 真値.
        // 状態更新.
        x = dotVec(dotVec(dotVec(A ,x), dotVec(B ,u)), dotVec(s_sigma, randn(2, 1)));

        // 観測.
        z = dotVec(dotVec(o_sigma, randn(2, 1)), x);

        // ------------------------------------------------------------------------
        // particle filter
        // サンプリング
        Kai = dotVec(dotVec(dotVec(A ,Kai) ,repmat21M(dotVec(B, u))) ,dotVec(s_sigma ,randn(2, M)));

        // 尤度を計算
        for(int i = 0; i < M; i++)
            w[i] = 1.0f/(Mathf.Sqrt(2.0f* Mathf.PI) * sigma)
                * Mathf.Exp(
                    -(
                    (Kai[1, i] - z[1, 1])*(Kai[1, i] - z[1, 1])
                              /(2.0f * sigma * sigma)
                    )
                    )
                /(Mathf.Sqrt(2.0f*Mathf.PI)*sigma)
                    * Mathf.Exp(
                    -(Kai[2,i]-z[2,1])*(Kai[2,i]-z[2,1])/(2.0f*sigma*sigma)
                    );

        // 重みを正規化
        float w_sum = 0;
        for(int i = 0; i < M; i++)
            w_sum += w[i];
        for(int i = 0; i < M; i++)
            w[i] /= w_sum;

        // Kai_barに入れておく
        for(int i = 0; i < M; i++)
            for(int j = 0; j < 2; j++)
                Kai_bar[j, i] = Kai[j, i];
        for(int i = 0; i < M; i++)
                Kai_bar[2, i] = w[i];

        // リサンプリング
        // 重みを入れる箱(無駄が多い)
        float[,] box = new float[M + 1, 1];
        for (int i = 0; i < M - 1; i++)
            box[i + 1, 0] = box[i, 0] + w[i];

        box[M, 0] = 1.0f;

        // くじ引き
        for (int i = 0; i < M; i++){
            float r = Random.Range(0.0f, 1.0f);
            int num = 0;

            // 乱数がどの箱かを調べる(遅い)
            for (int j = 0; j < M; j++){
                if((box[j, 0] < r) && (r < box[j + 1, 0])){
                    num = j;
                }
            }
            // 新たなKaiに代入
            Kai[0, i] = Kai_bar[0, num];
            Kai[1, i] = Kai_bar[1, num];
        }

        // ------------------------------------------------------------------------
        // 描画

        // パーティクル
        for (int i = 0; i < M; i++) {
            objParticles [i].transform.position = new Vector3(Kai[0,i], Kai[1, i], 0);
            // objParticles [i].renderer.material.color = c [Kai[1,i] * width + Kai[0, i]];
        }
    }