Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 我在这个Python代码中遇到了错误,如何调试它?_Python 3.x_Image Processing_Twirl - Fatal编程技术网

Python 3.x 我在这个Python代码中遇到了错误,如何调试它?

Python 3.x 我在这个Python代码中遇到了错误,如何调试它?,python-3.x,image-processing,twirl,Python 3.x,Image Processing,Twirl,我试着用Python对图像进行旋转变换。但是没有得到预期的输出。互联网上的所有解决方案都是C语言 我期待一个旋转图像,但得到的输出与输入相同。您可以用这种方法解决它 # -*- coding: utf-8 -*- """ Created on Tue Mar 26 16:46:20 2019 @author: Hafiz """ import cv2 import numpy as np import math imgIn=cv2.imread('lena.jpg',0) imgOut=n

我试着用Python对图像进行旋转变换。但是没有得到预期的输出。互联网上的所有解决方案都是C语言


我期待一个旋转图像,但得到的输出与输入相同。

您可以用这种方法解决它

# -*- coding: utf-8 -*-
"""
Created on Tue Mar 26 16:46:20 2019

@author: Hafiz
"""

import cv2
import numpy as np
import math

imgIn=cv2.imread('lena.jpg',0)
imgOut=np.zeros(imgIn.shape,dtype='uint8')

alpha=float(input('Enter alpha: '))
alpha=np.deg2rad(alpha)
rmax=int(input('Enter rmax: '))

centerX=int(imgIn.shape[1]/2)
centerY=int(imgIn.shape[0]/2)

for i in  range(imgOut.shape[0]):
    for j in range(imgOut.shape[1]):
        dX=j-centerX
        dY=i-centerY
        r=math.sqrt(dX*dX+dY*dY)
        if(r<=rmax):
            beta=math.atan2(dY,dX)+alpha*((rmax-r)/rmax)
            x=round(centerX+r*math.cos(beta))
            y=round(centerY+r*math.sin(beta))
        else:
            x=j
            y=i
        if(x>=imgIn.shape[1] or y>=imgIn.shape[0] or x<0 or y<0):
            imgOut.itemset((i,j),0)
        else:
            imgOut.itemset((i,j),imgIn.item(y,x))
cv2.imshow('in',imgIn)       
cv2.imshow('out',imgOut)
cv2.waitKey(0)
cv2.destroyAllWindows()
#-*-编码:utf-8-*-
"""
创建于2019年3月26日星期二16:46:20
@作者:哈菲兹
"""
进口cv2
将numpy作为np导入
输入数学
imgIn=cv2.imread('lena.jpg',0)
imgOut=np.zero(imgIn.shape,dtype='uint8')
alpha=float(输入('Enter alpha:'))
α=np.deg2rad(α)
rmax=int(输入('enterrmax:'))
centerX=int(imgIn.shape[1]/2)
centerY=int(imgIn.shape[0]/2)
对于范围内的i(imgOut.shape[0]):
对于范围内的j(imgOut.形状[1]):
dX=j-centerX
dY=i-centerY
r=math.sqrt(dX*dX+dY*dY)

如果(r=imgIn.shape[1]或y>=imgIn.shape[0]或XA是新手,您不应该编写此代码。这不是一个小问题。您的标题说您遇到了错误,但问题的主体说您的输入与输出相同。这些对您的问题的解释不匹配-哪一个是正确的?
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 26 16:46:20 2019

@author: Hafiz
"""

import cv2
import numpy as np
import math

imgIn=cv2.imread('lena.jpg',0)
imgOut=np.zeros(imgIn.shape,dtype='uint8')

alpha=float(input('Enter alpha: '))
alpha=np.deg2rad(alpha)
rmax=int(input('Enter rmax: '))

centerX=int(imgIn.shape[1]/2)
centerY=int(imgIn.shape[0]/2)

for i in  range(imgOut.shape[0]):
    for j in range(imgOut.shape[1]):
        dX=j-centerX
        dY=i-centerY
        r=math.sqrt(dX*dX+dY*dY)
        if(r<=rmax):
            beta=math.atan2(dY,dX)+alpha*((rmax-r)/rmax)
            x=round(centerX+r*math.cos(beta))
            y=round(centerY+r*math.sin(beta))
        else:
            x=j
            y=i
        if(x>=imgIn.shape[1] or y>=imgIn.shape[0] or x<0 or y<0):
            imgOut.itemset((i,j),0)
        else:
            imgOut.itemset((i,j),imgIn.item(y,x))
cv2.imshow('in',imgIn)       
cv2.imshow('out',imgOut)
cv2.waitKey(0)
cv2.destroyAllWindows()