- Home /
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 ?
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?
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?
You should edit your question, not post an answer, cuz now it looks like you have one answer.
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().
@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.
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.
Your answer
Follow this Question
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