Exemplo n.º 1
0
    IEnumerator SendImages()
    {
        while (true)
        {
            Texture2D rgb   = RTImageColor(_cameras[0]);
            Texture2D depth = RTImageDepth(_cameras[1]);
            //Color c;
            //for (int i = 0; i < rgb.width; i++) {
            //    for (int j = 0; j < rgb.height; j++) {
            //        c = rgb.GetPixel(i, j);
            //        c.a = depth.GetPixel(i, j).a;
            //        rgb.SetPixel(i, j, c);
            //    }
            //}​

            Color[] pxs      = rgb.GetPixels();
            Color[] pxsDepth = depth.GetPixels();

            for (int i = 0; i < pxs.Length; i++)
            {
                pxs[i].a = pxsDepth[i].a;
            }

            rgb.SetPixels(pxs);

            HeaderMsg _head = new HeaderMsg(0, new TimeMsg(_ros.GetepochStart().Second, 0), "map");

            //RGB
            CompressedImageMsg compressedImg = new CompressedImageMsg(_head, "png", rgb.EncodeToPNG());
            _ros.Publish(RobotCamera_pub.GetMessageTopic(), compressedImg);

            //Depth
            //compressedImg = new CompressedImageMsg(_head, "png", RTImageDepth(_cameras[1]).EncodeToPNG());
            //_ros.Publish(CameraDepth_pub.GetMessageTopic(), compressedImg);
            yield return(new WaitForSeconds(_frecuency));
        }
    }
    /*private void Update()
     * {
     *  StartCoroutine(SendImage());
     * }*/

    private void FixedUpdate()
    {
        HeaderMsg header = new HeaderMsg(0, new TimeMsg(_robot.GetepochStart().Second, 0), "base_link");

        _cam.Render();
        RenderTexture.active = _cam.targetTexture;
        //msg = new ImageMsg(header, _cam.targetTexture);
        //string msg_string = msg.ToString();

        /*if(k == 0)
         * {
         *  int i = 190000;
         *  byte[] _data = new byte[i];
         *
         *  for (int j = 0; j < i; j++)
         *  {
         *      _data[j] = (byte)0;
         *  }
         *  System.IO.File.WriteAllBytes(Application.dataPath + "/msg", _data);
         *  Debug.Log("Imagen capturada");
         *  k = 1;
         * }*/
        //_robot.Publish(RobotCamera_pub.GetMessageTopic(), msg);
    }