• 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
2
Question by eduacostam · Dec 28, 2011 at 09:45 PM · texturewebcamunity 3.5bitmap

Need to access memory address of Texture in Unity 3.5 Beta

I have a library written in C++ with binding for C# for gathering information from an image. Currently in C#.NET I'm using my library in this way:

 unsafe
 {
     Bitmap imageData = new Bitmap("image.jpg");
     BitmapData data = imageData.LockBits(
             new Rectangle(new Point(0, 0), imageData.Size),
             ImageLockMode.ReadWrite,
             PixelFormat.Format24bppRgb);
 
     // Get the address of first pixel in image
     byte* pointer = (byte*)data.Scan0;
 
     // My object singleton
     Live live = w2d.GetLive();
 
     // Call process and retrieve information
     Content content = live.Process(pointer,
             (uint)imageData.Width,
             (uint)imageData.Height,
             data.Stride,
             false,
             engine);
 }

Now what I want is to integrate this with Unity. Using a Unity script I've created a WebCamTexture object like this:

 WebCamDevice device = new WebCamDevice();
 // texture is a class attribute in order to be able to access it from Update()
 texture = new WebCamTexture(device.name, (int)width, (int)height, 30);
 
 renderer.material.mainTexture = texture;
 texture.Play();

This works great and I can see the webcam image in Unity when executing.

On the Update() method of this script I would like to retrieve the frame from memory (as I do with the Bitmap in .NET) and pass that info to my processing library. In essence what I need is a way to find the memory address of the frame and how it is encoded in memory (I hope it's like the Bitmap (uncompressed) and RGB24).

Thanks in advance,

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tonio · Feb 23, 2012 at 11:15 PM

Have you had any succes on this. I need exactly the same thing. I tried to use getPixels32(data) but the returned data seems strange to me.

If I save it to a png image, the resulting image looks strange. Color[] tmp = new Color[data.Length]; for (int i = 0; i < tmp.Length; i++) { tmp[i].r = data[i].r;//m_vidframe_byte[3 i]; tmp[i].g = data[i].g;//m_vidframe_byte[3 i + 1]; tmp[i].b = data[i].b;//m_vidframe_byte[3 * i + 2]; }

             // For testing purposes, also write to a file in the project folder
             count++;
            
             var tex = new Texture2D (640, 480, TextureFormat.RGB24, false);
             tex.SetPixels(tmp);
             tex.Apply();
        
             // Encode texture into PNG
             var bytes = tex.EncodeToPNG();
             Destroy (tex);
    
            
             File.WriteAllBytes(Application.dataPath + "/../SavedScreen" + count + ".png", bytes);
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to i split a bitmap into parts? And use each part for a texture? 2 Answers

WebcamTexture changing scenes - crash 5 Answers

How to create giant bitmaps such as for backgrounds? 0 Answers

QR-Code Decoding for iOS and Android 0 Answers

webcam texture format 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