Skip to content

Commit

Permalink
Added smoother steering
Browse files Browse the repository at this point in the history
  • Loading branch information
Sully Chen authored and Sully Chen committed Oct 2, 2016
1 parent 65e4a3b commit d3bb3ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
img = cv2.imread('steering_wheel_image.jpg',0)
rows,cols = img.shape

smoothed_angle = 0

cap = cv2.VideoCapture(0)
while(cv2.waitKey(10) != ord('q')):
ret, frame = cap.read()
Expand All @@ -19,7 +21,10 @@
call("clear")
print("Predicted steering angle: " + str(degrees) + " degrees")
cv2.imshow('frame', frame)
M = cv2.getRotationMatrix2D((cols/2,rows/2),-degrees,1)
#make smooth angle transitions by turning the steering wheel based on the difference of the current angle
#and the predicted angle
smoothed_angle += 0.2 * pow(abs((degrees - smoothed_angle)), 2.0 / 3.0) * (degrees - smoothed_angle) / abs(degrees - smoothed_angle)
M = cv2.getRotationMatrix2D((cols/2,rows/2),-smoothed_angle,1)
dst = cv2.warpAffine(img,M,(cols,rows))
cv2.imshow("steering wheel", dst)

Expand Down
9 changes: 7 additions & 2 deletions run_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
img = cv2.imread('steering_wheel_image.jpg',0)
rows,cols = img.shape

i = 0
smoothed_angle = 0

i = 10000
while(cv2.waitKey(10) != ord('q')):
image = scipy.misc.imresize(scipy.misc.imread("driving_dataset/" + str(i) + ".jpg")[-150:], [66, 200]) / 255.0
degrees = model.y.eval(feed_dict={model.x: [image], model.keep_prob: 1.0})[0][0] * 180.0 / scipy.pi
call("clear")
print("Predicted steering angle: " + str(degrees) + " degrees")
cv2.imshow("frame", image)
M = cv2.getRotationMatrix2D((cols/2,rows/2),-degrees,1)
#make smooth angle transitions by turning the steering wheel based on the difference of the current angle
#and the predicted angle
smoothed_angle += 0.2 * pow(abs((degrees - smoothed_angle)), 2.0 / 3.0) * (degrees - smoothed_angle) / abs(degrees - smoothed_angle)
M = cv2.getRotationMatrix2D((cols/2,rows/2),-smoothed_angle,1)
dst = cv2.warpAffine(img,M,(cols,rows))
cv2.imshow("steering wheel", dst)
i += 1
Expand Down

0 comments on commit d3bb3ee

Please sign in to comment.