Sunday, 3 February 2019

python+openCV : only size-1 arrays can be converted to Python scalars

This is my code to rotate the img with cv2.getRotationMatrix2D() function.

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)

I am getting the following error:

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



from python+openCV : only size-1 arrays can be converted to Python scalars

No comments:

Post a Comment