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 kyewong · Jun 01, 2015 at 05:50 PM · texture2dvideoopencv

fast way for converting from opencv mat to texture2d

Hi guys,

I'm trying to read a large-size video (3840*2160) from opencv and then convert it to texture2d in unity frame by

frame, in order to show it as background of a 3d scene. The way I'm using is as follows:

in cpp: mat opencvimg; ... byte* imgdata=new byte[widh*height*3]; memcpy(imgdata,opencvimg.data,widh*height*3);

in c#: Texture2d texture0 texture0.LoadRawTextureData(imgdata); texture0.Apply(); GUITexture backgroundtexture; backgroundtexture.texture=texture0;

When the size of the video is of size 1920*1080, it went smoothly. However, I found that texture0.Apply() is quite quite slow that the video cannot be played normally.

Could anyone please give me some suggestions on how to do in real time please? Thank you!

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 kyewong · Jun 03, 2015 at 06:58 AM

let me end this topic myself I've found that the fastest way is to fill the texture2d data in native opengl using glBindTexture & glTexImage2D, instead of using LoadRawTextureDat in c#. For more details, pls refer to http://docs.unity3d.com/Manual/NativePluginInterface.html

Comment
Add comment · Show 4 · 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 flankechen · Dec 01, 2015 at 11:01 AM 0
Share

Hi, I might suffering from the same problem. and newbie to Unity, sigh. In your LoadRawTexture() method solution. did you new byte data in cpp and passed them back to unity script? I might try the simple one first(I have a opencv mat 1280*1024).

Thanks.

avatar image kyewong flankechen · Dec 01, 2015 at 03:09 PM 0
Share

Hi, you don't need to pass the data from cpp to unity script, In contrast, you need to pass the id/pointer of the texture from unity script to cpp, and bind the texture data to the id/pointer inside the cpp. Such an example can be found at: http://docs.unity3d.com/uploads/Examples/RenderingPluginExample52.zip

avatar image flankechen kyewong · Dec 02, 2015 at 02:44 AM 0
Share

thanks a lot, I am checking this sample

avatar image Abdis · Jan 22, 2018 at 02:54 PM 0
Share

@kyewong Hi, could you reupload the sample? the link was broken

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

import video from camera 3 Answers

Using of Texture2D.LoadImage 0 Answers

Smooth Synchronized HD Video Playback 0 Answers

android display h264 byte[] stream 0 Answers

Image Stitching without external libraries 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