11import cv2
2- import os
32import numpy as np
43
54
@@ -41,30 +40,25 @@ def mouse_callback(event, x, y, flags, param):
4140 clicked_pts .clear ()
4241
4342 cv2 .destroyAllWindows ()
44-
4543 return np .array (clicked_pts , dtype = np .float32 )
4644
4745
48-
4946def distPoint2LineAB (p , a , b ):
5047 pa = p - a
5148 pb = p - b
5249 ba = b - a
53-
5450 dist = np .abs (np .cross (pa , pb )) / np .linalg .norm (ba )
5551 return dist
5652
5753
5854def calculateCandidateScore (pose , cornerPoints ):
5955 position = pose [0 :2 ]
60-
6156 score = np .min ([
6257 distPoint2LineAB (position , cornerPoints [0 ], cornerPoints [1 ]),
6358 distPoint2LineAB (position , cornerPoints [1 ], cornerPoints [2 ]),
6459 distPoint2LineAB (position , cornerPoints [2 ], cornerPoints [3 ]),
6560 distPoint2LineAB (position , cornerPoints [3 ], cornerPoints [0 ]),
6661 ])
67-
6862 return score
6963
7064
@@ -88,7 +82,6 @@ def cvtPose2CarBox(carPose):
8882
8983def find_all_candidate_parking_spots (cornerPts , angleStepDegree = 10 , positionStrideMeter = 0.5 ):
9084 cornerPts = np .array (cornerPts , dtype = np .float32 )
91-
9285 min_x = np .min (cornerPts [:, 0 ]) + 0.5
9386 max_x = np .max (cornerPts [:, 0 ]) - 0.5
9487 min_y = np .min (cornerPts [:, 1 ]) + 0.5
@@ -111,7 +104,6 @@ def find_all_candidate_parking_spots(cornerPts, angleStepDegree=10, positionStri
111104
112105 if judgeRectInPolygon (car_box_shifted , cornerPts ):
113106 candidates .append ((cx , cy , angleDegree ))
114-
115107 return candidates
116108
117109
@@ -137,7 +129,6 @@ def drawCarPose(img, center, angleDegree, color=(0, 0, 255), scale=100):
137129 rect = (center , (GEM_E4_LENGTH , GEM_E4_WIDTH ), float (angleDegree ))
138130 box = cv2 .boxPoints (rect )
139131 box_scaled = np .int32 (box * scale )
140-
141132 cv2 .polylines (img , [box_scaled ], isClosed = True , color = color , thickness = 2 )
142133
143134
0 commit comments