用JES和python创建鱼眼效果,代码生成空白imag

2024-09-30 12:29:29 发布

您现在位置:Python中文网/ 问答频道 /正文

这段代码运行时没有错误,并返回一个空白图像,打印颜色和坐标的显示数字,这是有意义的,但由于某些原因,似乎什么都没有写。 希望有人能看到我看不到的东西:

import math
def fisheye():
  file = pickAFile()
  pic = makePicture(file)  
  h = getHeight(pic)
  w = getWidth(pic)
  maxradius = sqrt(w**2 + h**2)/2
  fisheye = makeEmptyPicture(int(w+maxradius), int(h+maxradius),white)
  for x in range(0,w):
    for y in range(0,h):
      nyS = ( (2*x)/h ) - 1
      nxS = ( (2*y)/w ) - 1
      r = sqrt( nxS**2 + nyS**2 )
      if( r >= 0.0 and r <= 1.0 ):
        nr = (r + (1.0-r)) / 2.0
        if( nr <= 1.0 ):
          t = math.atan2(nyS,nxS)
          nx = nr*cos(t)
          ny = nr*sin(t)
          x2 = (((nx+1)*w)/2.0)
          y2 = (((ny+1)*h)/2.0)
          color = getColor(getPixel(pic, x, y))
          print max(color)
          setColor( getPixel(pic, int(x2),int(y2)) , color)
  explore(fisheye)

Tags: inforifrangemathsqrtnrfile
1条回答
网友
1楼 · 发布于 2024-09-30 12:29:29

问题似乎是您对setColor()的调用。在这个语句中,您还有一个对getPixel()的调用,它引用的是pic,而不是{}。在

请将此声明改为:

setColor( getPixel(fisheye, int(x2),int(y2)) , colour)

相关问题 更多 >

    热门问题