arrays - how to manipulate an image very fast in accordance to an own math function in python -
i'm trying create 360 degree camera google street cameras (this whole code if interested)
i have individual kind of perspective equation map pixel [xold,yold] [xnew,ynew] in accordance alpha , beta angles inputs.
to simplify equation , question, assume i'm trying rotate image. question how rotate image using rotation equation on each pixel fast on pygame or anyother intractive shell:
- xnew = xold * cos(alpha) - yold * sin(alpha)
- ynew = xold * sin(alpha) + yold * cos(alpha)
assume pygame.transform.rotate() not available
read following words pygame.org: http://www.pygame.org/docs/ref/surface.html
"there support pixel access surfaces. pixel access on hardware surfaces slow , not recommended. pixels can accessed using get_at() , set_at() functions. these methods fine simple access, considerably slow when doing of pixel work them. if plan on doing lot of pixel level work, recommended use pygame.pixelarray object direct pixel access of surfaces, gives array view of surface. involved mathematical manipulations try pygame.surfarray module accessing surface pixel data using array interfaces module (it’s quite quick, requires numpy.)"
pygame.surface.set_at((x,y),color) easiest way it, performance (which asked), must use pygame.pixelarray or pygame.surfarray.
i can't coding because i'm short on time, these websites point in right direction:
http://www.pygame.org/docs/ref/pixelarray.html#pygame.pixelarray http://www.pygame.org/docs/ref/surfarray.html#module-pygame.surfarray
good luck coding!
Comments
Post a Comment