这是我的代码来旋转用cv2.getRotationMatrix2D()函数的IMG。
smoothed_angle = 0
img = cv2.imread("/home/hp/self driving car/steering_wheel_image.png")
print(img.shape) #outputs (240, 240, 3)
rows = img.shape[0]
print(rows) #outputs 240
cols = img.shape[1]
print(cols) #outputs 240
M = cv2.getRotationMatrix2D((cols/2,rows/2),-smoothed_angle,1)
我收到以下错误:
TypeError Traceback (most recent call last)
<ipython-input-37-55419a87d5b5> in <module>()
34 #and the predicted angle
35 smoothed_angle += 0.2 * pow(abs((predicted_angle_degree - smoothed_angle)), 2.0 / 3.0) * (predicted_angle_degree - smoothed_angle) / abs(predicted_angle_degree - smoothed_angle)
---> 36 M = cv2.getRotationMatrix2D((cols/2,rows/2),-smoothed_angle,1)
37 dst = cv2.warpAffine(img,M,(cols,rows))
38 #cv2.imshow("steering wheel", dst)
TypeError: only size-1 arrays can be converted to Python scalars
此外,print(type(smoothed_angle))
给出了下面的输出:
<class 'numpy.ndarray'>
因为它是写的脚本例子没有返回一个错误。但是,在你的错误输出,还有一个35行,上面写着:
35 smoothed_angle += 0.2 * pow(abs((predicted_angle_degree - smoothed_angle)), 2.0 / 3.0) * (predicted_angle_degree - smoothed_angle) / abs(predicted_angle_degree - smoothed_angle)
这不是在本例中的脚本,但可能是问题(或其他步骤,该步骤没有在实施例)的源。如果开始smoothed_angle = 0
但predicted_angle_degree
是阵列而不是标量(例如predicted_angle_degree = np.array([0,0])
),它会导致所显示的错误。所以它看起来是错误是由于smoothed_angle
不是一个标量。
与类型信息更新:由于与smoothed_angle
类型显示,它不是一个标量或将印有<type 'int'>
或<type 'float'>
。如果smoothed_angle
也开始像在例如标量,那么它是由在本例中没有给出另一个功能改变,像在线路35这也意味着,该活动正用于更新smoothed_angle
另一个参数,如predicted_angle_degree
,也有类型ndarray
。