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 chuggy25 · Oct 22, 2019 at 09:16 PM · camerargbrgba

Efficient Way to Get Pure RGB Data toCSV

Hey everyone, I'm currently trying to pull RGB data from my camera on update using the following code:

 // assumes you have your RenderTexture renderTexture
         Texture2D tex2d = new Texture2D(cam.width, cam.height, TextureFormat.RGB24, false);
 
         RenderTexture.active = cam;
         tex2d.ReadPixels(new Rect(0, 0, cam.width, cam.height), 0, 0);
         tex2d.Apply();

         //super janky solution to gathering the data, write it to a text file!
         using (StreamWriter writer = new StreamWriter(@"C:\Users\Oliver\Camera\Assets\data.csv", true))
         {
 
             //maybe exit this to select r, g, and b from each pixel and add the values to a list, then to string, then to array and write to line
             //join each distance in array seperated by commas into a line and append it to a file.
             writer.WriteLine(String.Join(",", new List<Color>(tex2d.GetPixels()).ConvertAll(i => i.ToString()).ToArray())); //OR  writer.Write(i + ",");
         }
         

The end result is writing to the CSV in the following format ColA, ColB, ColC, ColD "RGBA(0 "| " 0 "| " 0 " | " 1) " ... <----- only one pixel value taking up 4 cells

However, I want the end product to be an array of ONLY RGB values in each cell, so... ColA, ColB, ColC, ColD "[0,0,0]"| " [0,185,12] "| " [122,89,0] " | " [0,0,0] " ... <---- 4pixel values taking up 4 cells

Is there an efficient way to do this (i.e. clean the data before writing to the CSV? ) The only way I can think of to do this is to make 2 nested for-loops and comb through each pixel and put it in this format then concat. to an array of arrays and write to the CSV.

Would this slow the collection of pixels values so that it takes longer than the 'update' function? Am I better of doing post-processing on the data to clean it up the way I want?

Thanks in advance for any help suggestions!

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

177 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

Related Questions

rgb value detail 0 Answers

PNG import problem 2019.1.0f2 0 Answers

How to make camera position relative to a specific target. 1 Answer

Convert RGB to RYB color scheme? 0 Answers

Make unity camera appear all screen width 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