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 /
avatar image
0
Question by dzz · May 14, 2014 at 12:24 PM · texture2drendertextureunityiphone

Get pixels from material displaying camera feed - LiveTexture Plugin

Hello,

I'm using the LiveTexture plugin for iOS in order to retrieve the camera feed of my device. The code for displaying my camera feed on a plane is the following - it works:

     private Texture2D texture;
     private GUIText textLog;
 
     // Use this for initialization
     void Start () {
         texture = LiveTextureBinding.startCameraCapture(false, LTCapturePreset.Size1280x720);
         renderer.sharedMaterial.mainTexture = texture;
         LiveTextureBinding.setExposureMode(LTExposureMode.Locked);
 
         textLog = GameObject.Find("LogText").GetComponent<GUIText>();
     }


I would like to get the pixels of that video feed, I do the following however it doesn't seem to work as the output value doesn't change. What is wrong?

     void Update (){
 
         Color[] pixels = texture.GetPixels();
 
 
         float averageLum = 0.0f;
         foreach(Color pixel in pixels){
             averageLum += (pixel.r * 0.299f) + (pixel.g * 0.587f) + (pixel.b * 0.114f);
         }
         averageLum /= pixels.Length;
 
         textLog.text = "avg. luminosity: " + averageLum;
     }

I also tried to replace texture.GetPixels by the following but it still doesn't work!

 pixels = (renderer.sharedMaterial.mainTexture as Texture2D).GetPixels();


EDIT: Note that if I replace all that LiveTexture thing on my Start with a WebCamTexture and then retrieve the pixels in Update with code below, it is working fine.

 pixels = (renderer.material.mainTexture as WebCamTexture).GetPixels();
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · May 14, 2014 at 01:04 PM

Well, i don't know that "LiveTexture plugin" but it might be possible that the Texture the plugin generates isn't readable. You can only call GetPixels on textures which are readable. Have you tried using GetPixels and then using SetPixels on a new Texture to see if the data got transferred? I think the Texture2D you got back is just a wrapper for a native texture which probably can't be read since it doesn't exist in program memory.

Comment
Add comment · Show 3 · 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 dzz · May 23, 2014 at 12:08 PM 0
Share

Yes that was the problem. Solved it by creating a temp texture containing this unreadable texture (with ReadPixels). In case someone has the same problem...

avatar image pixel_fiend · Jun 19, 2014 at 10:45 PM 0
Share

any chance you can post some example code?

avatar image claytonreeves · Mar 07, 2015 at 08:20 PM 0
Share

I am having this same issue, but can't find an example anywhere to solve this. How do you create a texture from another one with the ReadPixels set?

avatar image
0

Answer by pixel_fiend · Jun 20, 2014 at 04:54 PM

This Blit function worked better than ReadPixels. I'm pretty sure it's just an abstraction of ReadPixels, fullscreen quad, etc.

Anyway, this is how I took a snapshot of the webcam and copied it to another texture.

 // temporary render texture to draw the webcam to
 RenderTexture _rt = new RenderTexture(Screen.width, Screen.height, 24);
 Texture2D webcamTexture = LiveTextureBinding.startCameraCapture (true, LTCapturePreset.Size640x480);
 RenderTexture snapshot = Graphics.Blit(webcamTexture, _rt);
   
Comment
Add comment · 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

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

22 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

Related Questions

Live screen share Unity3D 2 Answers

How can I save the Bild from a Camera, which not main camera is. 1 Answer

Get RenderTexture 1 Answer

Pass a RenderTexture to a plugin with zero copies 2 Answers

Rendering Unity output on OpenTK Windows? 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