![]() |
Image perspective effect in python
Hi,
I'm trying to do a Apple's Coverflow like display, and so i'm trying to make perspective on an image. I've successfully found how to do it, but it's really slow. For this i use pygame to display and load image and PIL to make perspective. It's take at least one minute to calc 5 covers. I think most of the time is taken by the conversion of a pygame image to an pil image : Code:
def perspectiv(self,z,w): |
Re: Image perspective effect in python
For what's its worth, here's how i would -try- to optimize (never used these python functions).
Just from looking at the documentation at : http://www.pygame.org/docs/ref/image.html and http://www.pythonware.com/library/pi...book/image.htm I would probably keep the original image strings in global array so i didnt need to frombuffer() before every frame. I would do this using the pygame.image.frombuffer() during intial setup only... subsequent accesses just write directly to the string buffer (i guess this is how it would work) Additionally I would probably -try- to do the same thing with the destination image strings... keeping in global array and just use a third/temp string for transformation. Not sure if regular assignment to the buffers would keep links to image using them though. So your render function might look like TmpImageString = OriginalImageStrings[x] TmpImage = pil_image.transform(...) #Try uncommented first... if just setting the buffer string doesnt work, revert to original way. #self.image = pygame.image.fromstring() DestinationImageStrings[x] = pil_image.tostring() Also not too sure about the 2d transformation function other than whats the performance difference using NEAREST or BILINEAR instead of BICUBIC? BICUBIC is the nicest/slowest and nearest is fastest. |
Re: Image perspective effect in python
Thanks.
Since my post i've make some tests, deleted the conversion with StringIO and optimized use of image, use smallest cover 125x125 instead of 250x250, use NEAREST instead of BICUBIC. But it's still too slow on the device to be usefull. In fact, the most slower thing is PIL transformation. |
Re: Image perspective effect in python
Can you maybe post the whole source so i can take a look at it ?
|
Re: Image perspective effect in python
1 Attachment(s)
yes of course ... but it 's just a test a this time of 5 covers movig on the screen. It s really sadly coded !
Here the source (Sorry can't upload a complete zip as this forum only accept 96Kb max files): Just get the cover i ve upload and duplicate it to "cover1.jpg" "cover2.jpg" "cover3.jpg" "cover4.jpg" "cover5.jpg" in a "covers" folder, located in the flow.py source code folder. Code:
#!/usr/bin/env python |
Re: Image perspective effect in python
Hmm i'm afraid the transformation ist just too slow. I don't think it is possible to optimize it *heavily* without openGl. You could of course precache the transformations but for a common music collection on a 8GB card i don't think thats reasonable..
|
Re: Image perspective effect in python
I don't think too.
I ve tested raytracing algo too ... but really too slow ;) Hum i'll think of a manual transformation by matrix on the image. |
Re: Image perspective effect in python
I'm pretty sure that's what the pil transform function does. And it is *a lot* of computation. We need openGL on the IT :)
|
Re: Image perspective effect in python
Me a novice to maemo dev but can't the DSP be used to do the transform?
|
Re: Image perspective effect in python
hey, don't use PIL to do anything if at all possible. It's freaking slow. If possible by any means, just use pygame / add your own transformer function.
Or, consider this: Take the image to pygame. Make a copy of it. Scale the copy inside pygame to 40x40. Move that to PIL. Make the transformation in PIL. Take the image from PIL. Transfer it to pygame. Scale it to 250x250 in pygame. Phew. Relax. Should have taken much less time that way. Also, consider doing less frames for the transformation and make it quicker. As it's quick, user might not notice the blurriness of the image because of the 40x40 base image. |
Re: Image perspective effect in python
Ahh, you might also consider evas. They should be good way to do the coverflow.
|
Re: Image perspective effect in python
Hi,
would you like to join my py-navigator project. car navigation made in python 2D/3D perspective intelligent POI database managment and more. Please contact me if you are interested. Mayby Python is slow as a script language but give a chance to have more developers to work on the project. Darius |
Re: Image perspective effect in python
Hi,
Quote:
Quote:
And if you have some questions don't hesitate, i ll help you (if i can :) ). |
| All times are GMT. The time now is 02:46. |
vBulletin® Version 3.8.8