Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AlbiScando · Oct 17, 2017 at 11:34 AM · textureimagesram

acquiring images from simulation?

Hi, i have a problem with acquiring images from my simulation. I think the problem is in the script i use to manage this, as it works fine and is fluid until i enable a SaveVideo button. Below i write the script i use for this task:

using UnityEngine; using System.Collections.Generic; public class CamerasManager : MonoBehaviour { public bool enableVideoSave; public string folder = "AcquisitionVideo"; public int frameRate = 25; public List cameras = new List();

// initialisation void Start() {

   if(enableVideoSave) {

      Time.captureFramerate = frameRate;
      if(cameras.Count > 0) {

         // create one main folder which will contain a sub folder for each camera 
         folder = folder + System.DateTime.Now.ToString("_yyyy-MM-dd_HH-mm-ss");
         if(System.IO.Directory.Exists(folder)) {
            System.IO.Directory.Delete(folder, true);
         }
         System.IO.Directory.CreateDirectory(folder);

         // create sub folder for each camera
         for(int i = 0; i < cameras.Count; ++i) {
            if(cameras[i].Camera) {
               cameras[i].Folder = string.Format("{0}/{1}_{2}x{3}_{4}fps",
                                                  folder,
                                                  cameras[i].Name,
                                                  cameras[i].Camera.rect.width,
                                                  cameras[i].Camera.rect.height,
                                                  frameRate);
               System.IO.Directory.CreateDirectory(cameras[i].Folder);
            }
         }
      }
   }

}

//function called after Update() void LateUpdate() {

   if(enableVideoSave) {
      // for each camera
      for(int i = 0; i < cameras.Count; ++i) {
         if(cameras[i].Camera) {
            RenderTexture rt = new RenderTexture((int) cameras[i].Camera.rect.width, (int) 
            cameras[i].Camera.rect.height, 24);
            cameras[i].Camera.targetTexture = rt;

            rt.antiAliasing = 8;

            Texture2D screenShot = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
            cameras[i].Camera.Render();
            RenderTexture.active = rt;
            screenShot.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
            cameras[i].Camera.targetTexture = null;
            RenderTexture.active = null; 
            Destroy(rt);
            
            byte[] bytes = screenShot.EncodeToPNG();

            string filename = string.Format("{0}/frame_{1:D04}.png", cameras[i].Folder, Time.frameCount);
            System.IO.File.WriteAllBytes(filename, bytes); 
         }
      }
   }

} }

[System.Serializable]

public class CameraType {

    public string Name;
    public Camera Camera;
   public string Folder;
   public CameraType(string _Name) {
   Name = _Name;

} }

I also attach a screen with the errors. alt text Thanks in advance

screenshot.png (498.9 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlbiScando · Oct 17, 2017 at 11:37 AM 0
Share

as you can see from image the problem clearly is that at a certain point it generates black shadows ins$$anonymous$$d of real people. This problem doesn't appear when i run the simulation without acquiring images from cameras

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Oct 17, 2017 at 12:15 PM

You don't destroy your "screenShot" textures you create in that loop. So you create a new texture every iteration and finally run out of memory.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlbiScando · Oct 17, 2017 at 01:52 PM 0
Share

Really thank, but then i have another problem. Adding the command "Destroy(screenShot)" it creates people correctly, but almost immediately (from frame 97 out of 900), this warning appear "failed to create RenderTexture( 1920x1080 fmt 27 aa 8), error 0x800700e", and all the following captured images are completely grey. I really don't get why the program works perfectly and then it suddenly stops working as it should.alt text

screenshot-5.png (138.8 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

93 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Creating a 2D game using planes with textures 1 Answer

Issue with UnityWebRequest 1 Answer

Should we enable Generate Mipmap for Normal Map? 1 Answer

Why a texture always consume twice RAM when running? 1 Answer

Create a texture dynamically 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges