Spaces:
Running
Running
Update simulation_modules.py
Browse files- simulation_modules.py +14 -15
simulation_modules.py
CHANGED
@@ -39,7 +39,7 @@ def find_peak_box_and_classify(data):
|
|
39 |
for j in range(1, W + 1):
|
40 |
confidence = det_data[i, j, 0]
|
41 |
# تم رفع حد الثقة قليلاً لتقليل الاكتشافات الخاطئة
|
42 |
-
if confidence > 0.
|
43 |
# البحث عن القمة المحلية
|
44 |
if (confidence >= det_data[i,j-1,0] and confidence >= det_data[i,j+1,0] and
|
45 |
confidence >= det_data[i-1,j,0] and confidence >= det_data[i+1,j,0]):
|
@@ -531,8 +531,8 @@ def render_bev(
|
|
531 |
predicted_waypoints: np.ndarray,
|
532 |
ego_pos_global: np.ndarray,
|
533 |
ego_theta_global: float,
|
534 |
-
pixels_per_meter: int =
|
535 |
-
grid_size_meters: tuple = (
|
536 |
future_time_steps: tuple = (1.0, 2.0) # أزمنة التنبؤ المستقبلية
|
537 |
) -> Dict[str, np.ndarray]:
|
538 |
"""
|
@@ -591,28 +591,27 @@ def render_bev(
|
|
591 |
cv2.drawContours(bev_maps[key], [box_points_future.astype(np.int32)], 0, (255, 0, 128), 2) # بنفسجي
|
592 |
|
593 |
# --- 2. رسم مركبة الأنا (يجب رسمها على كل الخرائط) ---
|
594 |
-
ego_center_pixel = (width_px / 2, height_px -
|
595 |
-
ego_size_px = (1.8 * pixels_per_meter,
|
596 |
ego_box = cv2.boxPoints((ego_center_pixel, ego_size_px, -90))
|
597 |
for key in bev_maps:
|
598 |
cv2.drawContours(bev_maps[key], [ego_box.astype(np.int32)], 0, (0, 255, 255), -1) # أصفر
|
599 |
|
600 |
# --- 3. رسم نقاط المسار المتوقعة (فقط على خريطة الحاضر t0) ---
|
601 |
if predicted_waypoints.size > 0:
|
602 |
-
waypoints_pixels = world_to_pixel(predicted_waypoints, (width_px, height_px), grid_size_meters)
|
603 |
cv2.polylines(bev_maps['t0'], [waypoints_pixels.astype(np.int32)], isClosed=False, color=(0, 255, 0), thickness=3)
|
604 |
|
605 |
return bev_maps
|
606 |
-
|
607 |
# =========================================================
|
608 |
-
# (دالة world_to_pixel تبقى كما هي من الرد السابق)
|
609 |
-
def world_to_pixel(world_points, grid_size_pixels, grid_size_meters):
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
|
617 |
# ==========================================================
|
618 |
# الدالة الثانية: generate_bev_image (النسخة النهائية)
|
|
|
39 |
for j in range(1, W + 1):
|
40 |
confidence = det_data[i, j, 0]
|
41 |
# تم رفع حد الثقة قليلاً لتقليل الاكتشافات الخاطئة
|
42 |
+
if confidence > 0.15:
|
43 |
# البحث عن القمة المحلية
|
44 |
if (confidence >= det_data[i,j-1,0] and confidence >= det_data[i,j+1,0] and
|
45 |
confidence >= det_data[i-1,j,0] and confidence >= det_data[i+1,j,0]):
|
|
|
531 |
predicted_waypoints: np.ndarray,
|
532 |
ego_pos_global: np.ndarray,
|
533 |
ego_theta_global: float,
|
534 |
+
pixels_per_meter: int = 20,
|
535 |
+
grid_size_meters: tuple = (20, 20),
|
536 |
future_time_steps: tuple = (1.0, 2.0) # أزمنة التنبؤ المستقبلية
|
537 |
) -> Dict[str, np.ndarray]:
|
538 |
"""
|
|
|
591 |
cv2.drawContours(bev_maps[key], [box_points_future.astype(np.int32)], 0, (255, 0, 128), 2) # بنفسجي
|
592 |
|
593 |
# --- 2. رسم مركبة الأنا (يجب رسمها على كل الخرائط) ---
|
594 |
+
ego_center_pixel = ((width_px / 2 ) + 20 , height_px - 10)
|
595 |
+
ego_size_px = (1.8 * pixels_per_meter, 2.0 * pixels_per_meter)
|
596 |
ego_box = cv2.boxPoints((ego_center_pixel, ego_size_px, -90))
|
597 |
for key in bev_maps:
|
598 |
cv2.drawContours(bev_maps[key], [ego_box.astype(np.int32)], 0, (0, 255, 255), -1) # أصفر
|
599 |
|
600 |
# --- 3. رسم نقاط المسار المتوقعة (فقط على خريطة الحاضر t0) ---
|
601 |
if predicted_waypoints.size > 0:
|
602 |
+
waypoints_pixels = world_to_pixel(predicted_waypoints, (width_px+20, height_px), grid_size_meters)
|
603 |
cv2.polylines(bev_maps['t0'], [waypoints_pixels.astype(np.int32)], isClosed=False, color=(0, 255, 0), thickness=3)
|
604 |
|
605 |
return bev_maps
|
|
|
606 |
# =========================================================
|
607 |
+
# # (دالة world_to_pixel تبقى كما هي من الرد السابق)
|
608 |
+
# def world_to_pixel(world_points, grid_size_pixels, grid_size_meters):
|
609 |
+
# pixel_per_meter_x = grid_size_pixels[0] / grid_size_meters[0]
|
610 |
+
# pixel_per_meter_y = grid_size_pixels[1] / grid_size_meters[1]
|
611 |
+
|
612 |
+
# pixel_x = (world_points[:, 1] * pixel_per_meter_x) + (grid_size_pixels[0] / 2)
|
613 |
+
# pixel_y = (grid_size_pixels[1]) - (world_points[:, 0] * pixel_per_meter_y)
|
614 |
+
# return np.vstack((pixel_x, pixel_y)).T
|
615 |
|
616 |
# ==========================================================
|
617 |
# الدالة الثانية: generate_bev_image (النسخة النهائية)
|