Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
  • Help Room /
avatar image
0
Question by Zanolon · Nov 19, 2020 at 12:47 PM · datascreenshotdata storage

Annotations and Screenshots not lining up

I'm using Unity to take annotated screenshots of images for a machine learning project. For whatever reason, sometimes the label of the image and annotation number don't line up. Sometimes it'll be off by one, as in, image 7 will correspond to annotations 6. Does anyone see why that might occur in my code?

```

public class randomizer : MonoBehaviour {

 public int model_num;
 public float timer;
 public float rand_anim_sleep_time;
 float[] camera_coords = new float[3];
 public string model_name;
 public bool model_up;
 public GameObject selected_model;
 public GameObject camera;
 public GameObject ball;
 public Rect bound_box;
 
 public int counter;
 
 // Start is called before the first frame update
 void Start()
 {
     camera = GameObject.Find("Main Camera");
     ball = GameObject.Find("st_ball_000");
     counter = 0;

    
 }

 public static Rect GUIRectWithObject(GameObject go)
 {
     Vector3 cen = go.GetComponent<Collider>().bounds.center;
     Vector3 ext = go.GetComponent<Collider>().bounds.extents;
     Vector2[] extentPoints = new Vector2[8]
     {
         HandleUtility.WorldToGUIPoint(new Vector3(cen.x-ext.x, cen.y-ext.y, cen.z-ext.z)),
         HandleUtility.WorldToGUIPoint(new Vector3(cen.x+ext.x, cen.y-ext.y, cen.z-ext.z)),
         HandleUtility.WorldToGUIPoint(new Vector3(cen.x-ext.x, cen.y-ext.y, cen.z+ext.z)),
         HandleUtility.WorldToGUIPoint(new Vector3(cen.x+ext.x, cen.y-ext.y, cen.z+ext.z)),
         HandleUtility.WorldToGUIPoint(new Vector3(cen.x-ext.x, cen.y+ext.y, cen.z-ext.z)),
         HandleUtility.WorldToGUIPoint(new Vector3(cen.x+ext.x, cen.y+ext.y, cen.z-ext.z)),
         HandleUtility.WorldToGUIPoint(new Vector3(cen.x-ext.x, cen.y+ext.y, cen.z+ext.z)),
         HandleUtility.WorldToGUIPoint(new Vector3(cen.x+ext.x, cen.y+ext.y, cen.z+ext.z))
     };
     Vector2 min = extentPoints[0];
     Vector2 max = extentPoints[0];
     foreach(Vector2 v in extentPoints)
     {
         min = Vector2.Min(min, v);
         max = Vector2.Max(max, v);
     }
     return new Rect(min.x, min.y, max.x-min.x, max.y-min.y);
 }

 // Update is called once per frame
 void Update()
 {
     // initializes new UnityEngine.Random model
     if (timer == 0)
     {
         rand_anim_sleep_time = UnityEngine.Random.value;

         model_num = UnityEngine.Random.Range(0, 10);
         model_name = "model_00" + model_num.ToString();
         selected_model = GameObject.Find(model_name);
         Vector3 selected_model_position = new Vector3((UnityEngine.Random.value*6) - 3, 0, (UnityEngine.Random.value*6) - 3);
         selected_model.transform.position = selected_model_position;
         selected_model.transform.rotation = Quaternion.Euler(0, (UnityEngine.Random.value*360) - 180, 0);
         
         Vector3 ball_transform_position = new Vector3( selected_model_position[0] + (UnityEngine.Random.value*2) - 1, .1f,  selected_model_position[2] + (UnityEngine.Random.value*2) - 1);
         ball.transform.position = ball_transform_position;
         

         camera_coords[0] = (UnityEngine.Random.value*10) - 5; // [-5, 5]
         camera_coords[1] = (UnityEngine.Random.value*2) + 1; // [1, 3]
         camera_coords[2] = (UnityEngine.Random.value*-9) - 1; // [-1, -10]
         camera.transform.position = new Vector3(camera_coords[0], camera_coords[1], camera_coords[2]);
         camera.transform.LookAt(ball.transform);
         camera.transform.rotation = Quaternion.Euler(UnityEngine.Random.value*40 - 20, UnityEngine.Random.value*40 - 20, UnityEngine.Random.value*40 - 20)
         
         bound_box = GUIRectWithObject(ball);

         selected_model.GetComponent<Animator>().Play("", -1, 0);      
     }

     timer += Time.deltaTime;
     // lets the animation play out before killing
     if (timer > rand_anim_sleep_time && timer < rand_anim_sleep_time + Time.deltaTime)
     {
         string folderPath = Directory.GetCurrentDirectory() + "/imgs/";
         var sr = File.AppendText(folderPath+"annotations.txt");
         ScreenCapture.CaptureScreenshot(System.IO.Path.Combine(folderPath, counter.ToString() + @".png"));
         sr.WriteLine(counter.ToString()+ ","+bound_box.ToString());
         sr.Close();
         
         
     }
     
     if (timer > rand_anim_sleep_time + .1)
     {
         counter++;
         Debug.Log(counter);
         selected_model.transform.position = new Vector3(-10, -10, -10);
         timer = 0;
     }

 }

} ```

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

209 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 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 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

Is there any tutorials on using MySQL and Unity? 0 Answers

how to initiate a file in the persistent data path using unity editor project tab ? 0 Answers

What is the best way to achieve local database for mobile? 0 Answers

Some help with Data Save/Load would be most appreciated 3 Answers

Save multiple inputs for one item and print out all items 0 Answers


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