Browse Source

project done

James Jeon 1 year ago
parent
commit
fb331a5278
1 changed files with 25 additions and 21 deletions
  1. 25
    21
      live_eval.py

+ 25
- 21
live_eval.py View File

@@ -6,6 +6,9 @@ import model
6 6
 import params
7 7
 import cv2
8 8
 import numpy as np
9
+import can
10
+
11
+bus = can.interface.Bus(channel='can0', bustype='socketcan_native')
9 12
 
10 13
 cap = cv2.VideoCapture(0)
11 14
 cap.set(3,300) # set height
@@ -28,21 +31,21 @@ def get_frame():
28 31
 	return img, frame
29 32
 
30 33
 def get_angle():
31
-    while(True):
32
-	# get one can data
33
-        can_data = str(bus.recv())
34
-	# check it is steering angle, if yes then stop the loop
35
-        if(can_data.find("ID: 0025") > 0):
36
-            break
37
-
38
-    # change the can data (HEX) to numerical data
34
+	while(True):
35
+		# get one can data
36
+		can_data = str(bus.recv())
37
+		# check it is steering angle, if yes then stop the loop
38
+		if(can_data.find("ID: 0025") > 0):
39
+			break
40
+	
41
+	# change the can data (HEX) to numerical data
39 42
 	tmp = can_data
40 43
 	hex_data = tmp[-23:-21] + tmp[-20:-18]
41 44
 	hex_decimal = tmp[-3:-1]
42 45
 	int_data = int(hex_data, 16)
43 46
 	int_decimal = int(hex_decimal, 16) / 256
44 47
 
45
-			# if the steering wheel angle in in right to the center
48
+	# if the steering wheel angle in in right to the center
46 49
 	if(int_data > 550):
47 50
 		int_data = int_data - 4096
48 51
 		int_decimal = 1 - int_decimal 
@@ -51,7 +54,7 @@ def get_angle():
51 54
 		# put the int and the decimal together
52 55
 		final_data = int_data + int_decimal
53 56
 
54
-    return final_data
57
+	return final_data
55 58
 
56 59
 def main():
57 60
 	# discard first 40 frames to give time for webcam to get the proper exposure
@@ -63,21 +66,22 @@ def main():
63 66
 	while True:
64 67
 		angle = get_angle()
65 68
 		img, frame = get_frame()
66
-
69
+		frame = cv2.flip(frame,0)
70
+		frame = cv2.flip(frame,1)
67 71
 		deg = model.y.eval(feed_dict={model.x: [img], model.keep_prob: 1.0})[0][0]
68
-		difference = ((final_data+16)-(deg+16))/(final_data+16)
69
-		if difference < 0:
70
-			difference = difference * -1
71
-		difference = difference * 100
72
+		#difference = ((final_data+16)-(deg+16))/(final_data+16)
73
+		#if difference < 0:
74
+		#	difference = difference * -1
75
+		#difference = difference * 100
72 76
 
73 77
 		predicted = "predicted : " + str(deg)
74
-		actual = "actual : " + str(final_data)
75
-		percent = "% difference : " + str(difference)
78
+		actual = "actual : " + str(angle)
79
+		#percent = "% difference : " + str(difference)
76 80
 
77
-		cv2.putText(image,predicted,(10,30), cv2.FONT_HERSHEY_COMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
78
-		cv2.putText(image,actual,(50,30), cv2.FONT_HERSHEY_COMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
79
-		cv2.putText(image,percent,(70,30), cv2.FONT_HERSHEY_COMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
80
-		
81
+		cv2.putText(frame,predicted,(10,30), cv2.FONT_HERSHEY_COMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
82
+		cv2.putText(frame,actual,(10,60), cv2.FONT_HERSHEY_COMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
83
+		#cv2.putText(frame,percent,(70,30), cv2.FONT_HERSHEY_COMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
84
+		print(deg,angle)		
81 85
 		cv2.imshow('frame', frame)
82 86
 
83 87
 		if cv2.waitKey(1) & 0xFF == ord('q'):

Loading…
Cancel
Save