@@ -414,10 +414,15 @@ def show_lidar_bev_with_boxes(
414414 lines = None ,
415415 line_colors = None ,
416416 bev_size = [500 , 500 ],
417- colormethod = "depth" ,
418- rescale = True ,
419- show = True ,
420- return_image = False ,
417+ fov = None ,
418+ fov_color : str = "#069Af3" ,
419+ fov_filled : bool = True ,
420+ fov_filled_alpha : float = 0.1 ,
421+ colormethod : str = "depth" ,
422+ background_color : str = "black" ,
423+ rescale : bool = True ,
424+ show : bool = True ,
425+ return_image : bool = False ,
421426):
422427 """
423428 Show lidar and the detection results (optional) in BEV
@@ -503,7 +508,12 @@ def show_lidar_bev_with_boxes(
503508 max_width = max (max_width , max (bev_corners [:, 1 ]) + 2 )
504509
505510 # define the size of the image and scaling factor
506- img1 = 0 * np .ones ([bev_size [0 ], bev_size [1 ], 3 ], dtype = np .uint8 )
511+ if background_color == "black" :
512+ img1 = 0 * np .ones ([bev_size [0 ], bev_size [1 ], 3 ], dtype = np .uint8 )
513+ elif background_color == "white" :
514+ img1 = 255 * np .ones ([bev_size [0 ], bev_size [1 ], 3 ], dtype = np .uint8 )
515+ else :
516+ raise NotImplementedError (background_color )
507517 if extent is None :
508518 width_scale = (max_width - min_width ) / bev_size [0 ]
509519 range_scale = (max_range - min_range ) / bev_size [1 ]
@@ -515,6 +525,30 @@ def show_lidar_bev_with_boxes(
515525 sc_arr = np .array ([range_scale , width_scale ])
516526 pc_bev = (pc2 [:, [0 , 1 ]] - min_arr ) / sc_arr
517527
528+ # add the field of view by blending
529+ if fov is not None :
530+ # add fov boundary without alpha
531+ boundary_bev = ((fov .boundary [:, [0 , 1 ]] - min_arr ) / sc_arr ).astype (int )
532+ boundary_bev = boundary_bev .reshape ((- 1 , 1 , 2 ))
533+ thickness = 3
534+ cv2 .polylines (
535+ img = img1 ,
536+ pts = [boundary_bev ],
537+ color = parse_color_string (fov_color ),
538+ thickness = thickness ,
539+ isClosed = True ,
540+ )
541+ # add fov filled with alpha
542+ if fov_filled :
543+ img2 = img1 .copy ()
544+ cv2 .fillPoly (
545+ img = img2 ,
546+ pts = [boundary_bev ],
547+ color = parse_color_string (fov_color ),
548+ )
549+ w = fov_filled_alpha
550+ img1 = cv2 .addWeighted (img1 , 1 - w , img2 , w , 0 )
551+
518552 # get colors for lidar pcs
519553 if colormethod == "depth" :
520554 depths = np .linalg .norm (pc2 [:, [0 , 1 ]], axis = 1 )
@@ -524,6 +558,10 @@ def show_lidar_bev_with_boxes(
524558 elif "channel" in colormethod :
525559 channel = int (colormethod .split ("-" )[1 ])
526560 pt_colors = get_lidar_color (pc2 [:, channel ], mode = "channel" )
561+ elif colormethod == "black" :
562+ pt_colors = 0 * np .ones ((len (pc2 ), 3 ), dtype = float )
563+ elif colormethod == "white" :
564+ pt_colors = 255 * np .ones ((len (pc2 ), 3 ), dtype = float )
527565 else :
528566 raise NotImplementedError
529567
0 commit comments