如何根据python中自己的数学函数非常快速地操作图像 [英] how to manipulate an image very fast in accordance to an own math function in python

查看:159
本文介绍了如何根据python中自己的数学函数非常快速地操作图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个360度相机,就像谷歌街头相机
(这是我的整个代码,如果你感兴趣的话)

I'm trying to create a 360 degree camera just like google street cameras (This is my whole code if you are interested)

我有一种单独的透视方程,将像素[xold,yold]映射到[xnew,ynew ]根据Alpha和Beta角度作为输入。

I have a individual kind of perspective equation that map pixel [xold,yold] to [xnew,ynew] in accordance to Alpha and Beta angles as inputs.

为了简化这个等式和我的问题,我假设我只是试图旋转图像。
现在我的问题是如何通过在pygame或任何其他活动shell上非常快速地使用每个像素上的旋转方程来旋转图像:

To simplify that equation and my question, i assume i'm just trying to rotate an image. Now my question is how to rotate an image by using rotation equation on each pixel very fast on pygame or anyother intractive shell:


  1. xnew = xold * cos(alpha) - yold * sin(alpha)

  2. ynew = xold * sin(alpha)+ yold * cos(alpha)

假设pygame.transform.rotate()不可用

Assume pygame.transform.rotate() is not available

推荐答案

阅读pygame.org中的以下文字:
http:// www。 pygame.org/docs/ref/surface.html

Read the following words from pygame.org: http://www.pygame.org/docs/ref/surface.html

支持Surfaces的像素访问。硬件表面上的像素访问速度很慢,而不是建议。可以使用get_at()和set_at()函数访问像素。这些方法适用于简单访问,但在使用像素工作时会相当慢。如果你打算做很多像素级工作,建议使用pygame.PixelArray对象直接pix el访问曲面,它提供了一个像表面视图的数组。对于涉及的数学操作,请尝试使用pygame.surfarray模块使用数组接口模块访问表面像素数据(它非常快,但需要NumPy。)

"There is support for pixel access for the Surfaces. Pixel access on hardware surfaces is slow and not recommended. Pixels can be accessed using the get_at() and set_at() functions. These methods are fine for simple access, but will be considerably slow when doing of pixel work with them. If you plan on doing a lot of pixel level work, it is recommended to use a pygame.PixelArray object for direct pixel access of surfaces, which gives an array like view of the surface. For involved mathematical manipulations try the pygame.surfarray module for accessing surface pixel data using array interfaces module (It’s quite quick, but requires NumPy.)"

pygame.Surface.set_at ((x,y),Color)绝对是最简单的方法,但是对于性能(这就是你要求的),你必须使用pygame.PixelArray或pygame.surfarray。

pygame.Surface.set_at((x,y),Color) is definitely the easiest way to do it, but for performance (which is what you asked), you must use pygame.PixelArray or pygame.surfarray.

我无法为你编码,因为我的时间很短,但这些网站会指出你正确的方向:

I can't do the coding for you because I'm short on time, but these websites will point you in the right direction:

http://www.pygame.org/docs/ref/pixelarray.html# pygame.PixelArray
http:/ /www.pygame.org/docs/ref/surfarray.html#module-pygame.surfarray

祝你的编码好运!

这篇关于如何根据python中自己的数学函数非常快速地操作图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆