void LateUpdate() { if (capturing || sendDataOverPipe) { //var randomizer = GameObject.Find("/Randomizer").GetComponent<RandomizerScript>(); randomizer.Randomize(new System.Random().Next(), 1.0f); float interval = (1.0f / rate); elapsed += Time.deltaTime; if (elapsed > interval) { RenderTexture.active = renderTarget; target.Render(); texture.ReadPixels(new Rect(0, 0, width, height), 0, 0); RenderTexture.active = null; //double lat = 0.0; //double lon = 0.0; //GPSAnchorScript.GetLatLong(car.gameObject, out lat, out lon); // Write the captured frame to a file if (capturing) { byte[] bytes = texture.EncodeToPNG();// .EncodeToJPG(80); System.IO.File.WriteAllBytes(Path.Combine(baseDir, String.Format("frame_{0}_thr_{1}_ste_{2}_mil_{3}_odo_{4}_.png", captureCount.ToString().PadLeft(5, '0'), (int)car.throttle, (int)car.wheelAngle, (int)(Time.time * 1000), (int)car.odometer)), bytes); captureCount++; } // Send the metadata and image to tensorflow if (sendDataOverPipe) { float[] floats = new float[] { width, height, car.wheelAngle, car.throttle, (float)0, //lat, (float)0, //lon, }; Color32[] pixels = texture.GetPixels32(); int pixelCount = width * height; // Build and send the message byte[] message = new byte[floats.Length * 4 + pixelCount * 3]; Buffer.BlockCopy(floats, 0, message, 0, floats.Length * 4); for (int i = 0, j = floats.Length * 4; i < pixelCount; i++, j += 3) { Color32 pixel = pixels[i]; message[j] = pixel.r; message[j + 1] = pixel.g; message[j + 2] = pixel.b; } pipe.Send(message); } elapsed = interval - elapsed; } randomizer.Randomize(0, 0.0f); } }