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 natwales · Feb 20, 2013 at 09:14 PM · getpixelsgetpixel

Most efficient way to getPixels() of non rectangular region

I'm trying to extract tracking image from video texture and speed is important (ios app). What's the best way to get an array of pixels from the polygon A, B, C, D ?

Comment
Add comment · Show 6
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 natwales · Feb 20, 2013 at 10:51 PM 0
Share

alt text

Sorry, forgot to post my photo.. though doubt it is that helpful.

So, if I extract the box containing abcd, wouldn't I still need to iterate over the pixels using GetPixel() in order to extract the polygon? If that's the case, how is isolating the polygon in a box helping me?

question.jpg (285.5 kB)
avatar image DaveA · Feb 20, 2013 at 10:53 PM 0
Share

Curious why you don't use Vuforia? Which I assume you are though, by the picture, in which case, you have the picture (as a marker) so why not just use that?

avatar image DaveA · Feb 20, 2013 at 10:54 PM 0
Share

You should edit your question, not post an answer, cuz now it looks like you have one answer.

avatar image robertbu · Feb 21, 2013 at 01:54 AM 0
Share

If you extract the bounding box of your points, you have an array of local data that you can process without making function calls. You don't need to call GetPixel to read the data. It is a 1D array so there is a bit of calculation to figure out the rows and columns. I'm not solving how you identify the pixels to be read, just that you do the analysis and reading on a local copy of the data rather than making function calls.

You could use GetPixels() to get the block of data or GetPixels32(). GetPixels() returns an array of Unity Colors. That is r,g,b,&a are represented by floating point values. GetPixels32() returns the block of data as Color32 values (i.e. bytes for r,g,b & a). I've never run a test, but I'm assu$$anonymous$$g there is notable overhead in converting bytes to floats for GetPixels().

avatar image natwales · Feb 21, 2013 at 02:48 PM 0
Share

@DaveA, I am using vuforia. $$anonymous$$y goal isn't just to get the tracking image, but rather extract the tracking image from the camera view so I can compare the color shift from original image to the live image in order to tone map my virtual assets. If you know of a more direct way to accomplish this I am all ears.

@robertbu, I am currently getting pixels using GetPixels() on my camera texture. I'm then perfor$$anonymous$$g functions on that array of Color objects to find brightest pixels, etc. Obviously I can't just use getPixels() on a polygon shape, and therefore assume I need to create my own algorithm for iterating over the pixels of a polygon shape using GetPixel(). If I understand correctly your suggestion is to grab the bounding box of pixels outlining the polygon with getPixels() and then loop through that array somehow eli$$anonymous$$ating the ones that fall out of the bounds of the polygon?

Thanks both of you for your help.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Feb 20, 2013 at 09:28 PM

Unless memory is an issue, I'd do GetPixels32() on the rectangular bounds of your polygon and then process the polygon locally as opposed to making repeated GetPixels calls.

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

11 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

Related Questions

The non-trivial problem with image processing. 1 Answer

Problem getting the right result when combining two textures 0 Answers

Proper way to strew lots of dead in Napoleonic RTS? 3 Answers

Use SetPixels, but dont set unvisible Pixels 1 Answer

Using GetPixel to instantiate blocks of different pixel colors 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