Faster cv rendering with polylines
This commit is contained in:
		
							parent
							
								
									49c5e66f1d
								
							
						
					
					
						commit
						4bc1e56dad
					
				
					 1 changed files with 16 additions and 20 deletions
				
			
		| 
						 | 
				
			
			@ -200,7 +200,7 @@ def transition_path_points(path: np.array, t: float):
 | 
			
		|||
    # distance = cum_lenghts[-1] * t
 | 
			
		||||
    # ts = np.concatenate((np.array([0.]), cum_lenghts / cum_lenghts[-1]))
 | 
			
		||||
    # print(cum_lenghts[-1])
 | 
			
		||||
    DRAW_SPEED = 30 # fixed speed (independent of lenght) TODO)) make variable
 | 
			
		||||
    DRAW_SPEED = 35 # fixed speed (independent of lenght) TODO)) make variable
 | 
			
		||||
    ts = np.concatenate((np.array([0.]), cum_lenghts / DRAW_SPEED))
 | 
			
		||||
    new_path = [path[0]]
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -235,6 +235,7 @@ def draw_track_predictions(img: cv2.Mat, track: Track, color_index: int, camera:
 | 
			
		|||
    # if convert_points:
 | 
			
		||||
    #     current_point = convert_points([current_point])[0]
 | 
			
		||||
    
 | 
			
		||||
    lines = []
 | 
			
		||||
    for pred_i, pred in enumerate(track.predictions):
 | 
			
		||||
        pred_coords = pred #cv2.perspectiveTransform(np.array([pred]), inv_H)[0].tolist()
 | 
			
		||||
        # line_points = pred_coords
 | 
			
		||||
| 
						 | 
				
			
			@ -249,23 +250,15 @@ def draw_track_predictions(img: cv2.Mat, track: Track, color_index: int, camera:
 | 
			
		|||
        color = bgr_colors[color_index % len(bgr_colors)]
 | 
			
		||||
        color = tuple([int(c*opacity) for c in color])
 | 
			
		||||
 | 
			
		||||
        line_points = line_points.reshape((-1,1,2))
 | 
			
		||||
        lines.append(line_points)
 | 
			
		||||
 | 
			
		||||
        for start, end in zip(line_points[:-1], line_points[1:]):
 | 
			
		||||
        # for ci in range(0, len(pred_coords)):
 | 
			
		||||
            # if ci == 0:
 | 
			
		||||
            #     # TODO)) prev point
 | 
			
		||||
            #     # continue
 | 
			
		||||
            #     start = [int(p) for p in current_point]
 | 
			
		||||
            #     # start = [int(p) for p in coords[-1]]
 | 
			
		||||
            #     # start = [0,0]?
 | 
			
		||||
            #     # print(start)
 | 
			
		||||
            # else:
 | 
			
		||||
            #     start = [int(p) for p in pred_coords[ci-1]]
 | 
			
		||||
            # end = [int(p) for p in pred_coords[ci]]
 | 
			
		||||
            # print(np.rint(start),np.rint(end).tolist())
 | 
			
		||||
            cv2.line(img, start, end, color, 2, lineType=cv2.LINE_AA)
 | 
			
		||||
            pass
 | 
			
		||||
            # cv2.circle(img, end, 2, color, 1, lineType=cv2.LINE_AA)
 | 
			
		||||
    # draw in a single pass
 | 
			
		||||
    cv2.polylines(img, lines, False, color, 2, cv2.LINE_AA)
 | 
			
		||||
        # for start, end in zip(line_points[:-1], line_points[1:]):
 | 
			
		||||
        #     cv2.line(img, start, end, color, 2, lineType=cv2.LINE_AA)
 | 
			
		||||
        #     pass
 | 
			
		||||
        #     # cv2.circle(img, end, 2, color, 1, lineType=cv2.LINE_AA)
 | 
			
		||||
 | 
			
		||||
def draw_trackjectron_history(img: cv2.Mat, track: Track, color_index: int, convert_points: Optional[Callable]):
 | 
			
		||||
    if not track.predictor_history:
 | 
			
		||||
| 
						 | 
				
			
			@ -302,11 +295,14 @@ def draw_track_projected(img: cv2.Mat, track: Track, color_index: int, camera: C
 | 
			
		|||
    point_color = bgr_colors[color_index % len(bgr_colors)]
 | 
			
		||||
    cv2.circle(img, to_point(history[0]), 3, point_color, 2)
 | 
			
		||||
 | 
			
		||||
    points = np.rint(history.reshape((-1,1,2))).astype(np.int32)
 | 
			
		||||
    cv2.polylines(img, [points], False, point_color, 1)
 | 
			
		||||
    
 | 
			
		||||
    for j in range(len(history)-1):
 | 
			
		||||
        a = history[j]
 | 
			
		||||
        # a = history[j]
 | 
			
		||||
        b = history[j+1]
 | 
			
		||||
 | 
			
		||||
        cv2.line(img, to_point(a), to_point(b), point_color, 1)
 | 
			
		||||
        # cv2.line(img, to_point(a), to_point(b), point_color, 1)
 | 
			
		||||
        cv2.circle(img, to_point(b), 3, point_color, 2)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue