Python cv2.arrowedLine() Examples

The following are 20 code examples of cv2.arrowedLine(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cv2 , or try the search function .
Example #1
Source File: observation_processor.py    From football with Apache License 2.0 6 votes vote down vote up
def write_arrow(self, arrow_type, scale_factor=1):
    assert (arrow_type in self._arrow_types)
    thickness = 1
    arrow_offsets = {
        'top': (12, 0, 12, -16),
        'top_right': (16, -4, 4, -16),
        'right': (0, -10, 20, -10),
        'bottom_right': (4, -16, 16, -4),
        'bottom': (10, -16, 10, 0),
        'bottom_left': (12, -12, 0, 0),
        'left': (20, -10, 0, -10),
        'top_left': (16, -4, 4, -16)
    }
    (s_x, s_y, e_x,
     e_y) = tuple(int(v * scale_factor) for v in arrow_offsets[arrow_type])
    start_point = (self._pos_x + s_x, self._pos_y + s_y)
    end_point = (self._pos_x + e_x, self._pos_y + e_y)
    image = cv2.arrowedLine(self._frame, start_point, end_point, self._color,
                            thickness) 
Example #2
Source File: DIWDataset.py    From YouTube3D with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw(img, target, fname):
	img_temp = img.copy()
	
	color_close = (255, 0, 0)	# close is blue
	color_far = (0, 255, 0)		# far is green
	for i in range(target.shape[1]):
		x1 = int(target[1, i]); y1 = int(target[0, i]);
		x2 = int(target[3, i]); y2 = int(target[2, i]);
		
		cv2.circle(img_temp,(x1, y1),2,color_far,-1)
		cv2.circle(img_temp,(x2, y2),2,color_close,-1)
		cv2.arrowedLine(img_temp, (x2, y2), (x1, y1), (0, 255, 255), 1)
	
	cv2.imwrite(fname, img_temp)
	print "Done writing to %s" % fname 
Example #3
Source File: gaze.py    From GazeML with MIT License 5 votes vote down vote up
def draw_gaze(image_in, eye_pos, pitchyaw, length=40.0, thickness=2, color=(0, 0, 255)):
    """Draw gaze angle on given image with a given eye positions."""
    image_out = image_in
    if len(image_out.shape) == 2 or image_out.shape[2] == 1:
        image_out = cv.cvtColor(image_out, cv.COLOR_GRAY2BGR)
    dx = -length * np.sin(pitchyaw[1])
    dy = -length * np.sin(pitchyaw[0])
    cv.arrowedLine(image_out, tuple(np.round(eye_pos).astype(np.int32)),
                   tuple(np.round([eye_pos[0] + dx, eye_pos[1] + dy]).astype(int)), color,
                   thickness, cv.LINE_AA, tipLength=0.2)
    return image_out 
Example #4
Source File: opencv.py    From pymotutils with GNU General Public License v3.0 5 votes vote down vote up
def arrow(self, start, end):
        """Draw arrow from start to end.

        Parameters
        ----------
        start : array_like
            Vector of length 2 which contains the arrow starting position.
        end : array_like
            Vector of length 2 which contains the arrow end position.

        """
        start = tuple(int(x) for x in start)
        end = tuple(int(x) for x in end)
        cv2.arrowedLine(self.image, start, end, self.color, self.thickness) 
Example #5
Source File: TableRecognition.py    From OTR with GNU General Public License v3.0 5 votes vote down vote up
def visualize_node_arrows(self, img, node_id, size=3, color=(255,0,255)):
        l, r, t, b = self.adjacency[node_id]
        srcX, srcY = self.node_coordinates[node_id]
        for direction, r in enumerate((l,r,t,b)):
            if r == -1: continue
            targetX, targetY = self.node_coordinates[r]
            # Use constant arrow head size. As arrowedLine() takes a fraction of the length, we need to reverse that
            length = np.hypot(targetX - srcX, targetY - srcY)
            arrowHeadSizeWant = 15  #px
            arrowHeadSize = arrowHeadSizeWant / length
            print("Drawing <{3}> arrow from #{0} to #{1}  of length {2}".format(
                    r, node_id, length, {0: "left", 1: "right", 2:"top", 3:"bottom"}[direction]))
            cv2.arrowedLine(img, (int(targetX), int(targetY)), (int(srcX), int(srcY)),
                            color=color, thickness=3, tipLength=arrowHeadSize, line_type=cv2.LINE_AA) 
Example #6
Source File: visualize_real_data.py    From Multiverse with Apache License 2.0 5 votes vote down vote up
def plot_trajs(img, trajs, color, show_person_id=False):
  """Plot traj on img with the person_id text."""
  # color is bgr tuple
  for person_id_, traj in trajs:
    traj = [(int(p1), int(p2)) for p1, p2 in traj]
    points = zip(traj[:-1], traj[1:])
    for p1, p2 in points:
      img = cv2.arrowedLine(img, tuple(p1), tuple(p2), color=color, thickness=2,
                            line_type=cv2.LINE_AA, tipLength=0.3)
    # show the person_id
    if show_person_id:
      img = cv2.putText(img, "#%s" % person_id_, tuple(traj[0]),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255),
                        lineType=cv2.LINE_AA)
  return img 
Example #7
Source File: utils.py    From deepxplore with MIT License 5 votes vote down vote up
def draw_arrow(img, angle1, angle2, angle3):
    pt1 = (img.shape[1] / 2, img.shape[0])
    pt2_angle1 = (int(img.shape[1] / 2 - img.shape[0] / 3 * math.sin(angle1)),
                  int(img.shape[0] - img.shape[0] / 3 * math.cos(angle1)))
    pt2_angle2 = (int(img.shape[1] / 2 - img.shape[0] / 3 * math.sin(angle2)),
                  int(img.shape[0] - img.shape[0] / 3 * math.cos(angle2)))
    pt2_angle3 = (int(img.shape[1] / 2 - img.shape[0] / 3 * math.sin(angle3)),
                  int(img.shape[0] - img.shape[0] / 3 * math.cos(angle3)))
    img = cv2.arrowedLine(img, pt1, pt2_angle1, (0, 0, 255), 1)
    img = cv2.arrowedLine(img, pt1, pt2_angle2, (0, 255, 0), 1)
    img = cv2.arrowedLine(img, pt1, pt2_angle3, (255, 0, 0), 1)
    return img 
Example #8
Source File: visualize.py    From part-affinity with MIT License 5 votes vote down vote up
def visualize_paf(img, pafs,name='pafs'):
    img = img.copy()
    for i in range(pafs.shape[0]):
        paf_x = pafs[i,0,:,:]
        paf_y = pafs[i,1,:,:]
        len_paf = np.sqrt(paf_x**2 + paf_y**2)
        for x in range(0,img.shape[0],8):
            for y in range(0, img.shape[1], 8):
                if len_paf[x,y]>0.25:
                    img = cv2.arrowedLine(img, (y,x), (int(y + 6*paf_x[x,y]), int(x + 6*paf_y[x,y])), colors[i], 1)
    cv2.imshow(name, img)
    cv2.waitKey() 
Example #9
Source File: opt_flow.py    From Walk-Assistant with GNU General Public License v3.0 5 votes vote down vote up
def draw_arrow(img, x, y, multiply=25):
        h, w, c = img.shape
        arrow = cv2.arrowedLine(img, (int(w / 2), int(h / 2)), (int(w / 2 + x * multiply), int(h / 2 + y * multiply)),
                                color=(0, 255, 255), thickness=15)
        return arrow 
Example #10
Source File: DIWDataset.py    From YouTube3D with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw(self, img, target, fname):
		img_temp = img.copy()
		
		color_close = (255, 0, 0)	# close is blue
		color_far = (0, 255, 0)		# far is green
		for i in range(target.shape[1]):
			x1 = int(target[1, i]); y1 = int(target[0, i]);
			x2 = int(target[3, i]); y2 = int(target[2, i]);
			
			cv2.circle(img_temp,(x1, y1),2,color_far,-1)
			cv2.circle(img_temp,(x2, y2),2,color_close,-1)
			cv2.arrowedLine(img_temp, (x2, y2), (x1, y1), (0, 255, 255), 1)
		
		cv2.imwrite(fname, img_temp)
		print "Done writing to %s" % fname 
Example #11
Source File: tracker.py    From telloCV with Apache License 2.0 5 votes vote down vote up
def draw_arrows(self, frame):
        """Show the direction vector output in the cv2 window"""
        #cv2.putText(frame,"Color:", (0, 35), cv2.FONT_HERSHEY_SIMPLEX, 1, 255, thickness=2)
        cv2.arrowedLine(frame, (self.midx, self.midy),
                        (self.midx + self.xoffset, self.midy - self.yoffset),
                        (0, 0, 255), 5)
        return frame 
Example #12
Source File: YoutubeDataset.py    From YouTube3D with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw(self, img, target, fname):
		img_temp = img.copy()
		
		color_close = (255, 0, 0)	# close is blue
		color_far = (0, 255, 0)		# far is green
		for i in range(target.shape[1]):
			x1 = int(target[1, i]); y1 = int(target[0, i]);
			x2 = int(target[3, i]); y2 = int(target[2, i]);
			
			cv2.circle(img_temp,(x1, y1),2,color_far,-1)
			cv2.circle(img_temp,(x2, y2),2,color_close,-1)
			cv2.arrowedLine(img_temp, (x2, y2), (x1, y1), (0, 255, 255), 1)
		
		cv2.imwrite(fname, img_temp)
		print "Done writing to %s" % fname 
Example #13
Source File: YoutubeDataset.py    From YouTube3D with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw(img, target, fname):
	img_temp = img.copy()
	
	color_close = (255, 0, 0)	# close is blue
	color_far = (0, 255, 0)		# far is green
	for i in range(target.shape[1]):
		x1 = int(target[1, i]); y1 = int(target[0, i]);
		x2 = int(target[3, i]); y2 = int(target[2, i]);
		
		cv2.circle(img_temp,(x1, y1),2,color_far,-1)
		cv2.circle(img_temp,(x2, y2),2,color_close,-1)
		cv2.arrowedLine(img_temp, (x2, y2), (x1, y1), (0, 255, 255), 1)
	
	cv2.imwrite(fname, img_temp)
	print "Done writing to %s" % fname 
Example #14
Source File: ReDWebDataset.py    From YouTube3D with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw(img, target, fname):
	img_temp = img.copy()
	
	color_close = (255, 0, 0)	# close is blue
	color_far = (0, 255, 0)		# far is green
	for i in range(target.shape[1]):
		x1 = int(target[1, i]); y1 = int(target[0, i]);
		x2 = int(target[3, i]); y2 = int(target[2, i]);
		
		cv2.circle(img_temp,(x1, y1),2,color_far,-1)
		cv2.circle(img_temp,(x2, y2),2,color_close,-1)
		cv2.arrowedLine(img_temp, (x2, y2), (x1, y1), (0, 255, 255), 1)
	
	cv2.imwrite(fname, img_temp)
	print "Done writing to %s" % fname 
Example #15
Source File: generate_boxreconst_samples.py    From adversarial-object-removal with MIT License 5 votes vote down vote up
def draw_arrows(img, pt1 , pt2):
    imgSz = img.shape[0]
    pt1 = ((pt1.data.cpu().numpy()+1.)/2.) * imgSz
    pt2 = ((pt2.data.cpu().numpy()[0,::]+1.)/2.) * imgSz
    for i in xrange(0,pt1.shape[1],2):
        for j in xrange(0,pt1.shape[2],2):
            if np.abs(pt1[0,i,j]-pt2[0,i,j]) > 2. or  np.abs(pt1[1,i,j]-pt2[1,i,j]) > 2. :
                img = cv2.arrowedLine(img.astype(np.uint8), tuple(pt1[:,i,j]), tuple(pt2[:,i,j]), color=(0,0,255), line_type=cv2.LINE_AA, thickness=1, tipLength = 0.4)
    return img 
Example #16
Source File: label.py    From autowebcompat with Mozilla Public License 2.0 5 votes vote down vote up
def create_change_shape(drawing_area, start_x, start_y, end_x, end_y):
    cv2.arrowedLine(drawing_area, (end_x - 12, end_y - 12), (end_x - 2, end_y - 2), COLOR_CHANGE_SHAPE, 2, tipLength=0.3)
    cv2.arrowedLine(drawing_area, (end_x - 2, end_y - 2), (end_x - 12, end_y - 12), COLOR_CHANGE_SHAPE, 2, tipLength=0.3) 
Example #17
Source File: label.py    From autowebcompat with Mozilla Public License 2.0 5 votes vote down vote up
def create_plus(drawing_area, start_x, start_y, end_x, end_y):
    center_x = (start_x + end_x) // 2
    center_y = (start_y + end_y) // 2
    cv2.arrowedLine(drawing_area, (center_x, center_y - 10), (center_x, center_y + 10), COLOR_PLUS, 2, tipLength=0.2)
    cv2.arrowedLine(drawing_area, (center_x - 10, center_y), (center_x + 10, center_y), COLOR_PLUS, 2, tipLength=0.2)
    cv2.arrowedLine(drawing_area, (center_x, center_y + 10), (center_x, center_y - 10), COLOR_PLUS, 2, tipLength=0.2)
    cv2.arrowedLine(drawing_area, (center_x + 10, center_y), (center_x - 10, center_y), COLOR_PLUS, 2, tipLength=0.2) 
Example #18
Source File: visualize.py    From ExtremeNet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def vis_ex(img, extreme_points, col, border_thick=2):
    """Visualizes a single binary mask."""

    img = img.astype(np.uint8)
    COL = (col).astype(np.uint8).tolist()
    # print('col', COL)
    ex = np.array(extreme_points).reshape(4, 2).astype(np.int32)
    
    L = 10
    T = 0.7
    cv2.arrowedLine(img, (ex[0][0], ex[0][1] + L), (ex[0][0], ex[0][1]), COL, border_thick, tipLength=T)
    cv2.arrowedLine(img, (ex[1][0] + L, ex[1][1]), (ex[1][0], ex[1][1]), COL, border_thick, tipLength=T)
    cv2.arrowedLine(img, (ex[2][0], ex[2][1] - L), (ex[2][0], ex[2][1]), COL, border_thick, tipLength=T)
    cv2.arrowedLine(img, (ex[3][0] - L, ex[3][1]), (ex[3][0], ex[3][1]), COL, border_thick, tipLength=T)
    
    '''
    R = 6
    cv2.circle(img, (ex[0][0], ex[0][1]), R, COL, -1)
    cv2.circle(img, (ex[1][0], ex[1][1]), R, COL, -1)
    cv2.circle(img, (ex[2][0], ex[2][1]), R, COL, -1)
    cv2.circle(img, (ex[3][0], ex[3][1]), R, COL, -1)

    cv2.circle(img, (ex[0][0], ex[0][1]), R, _WHITE, 2)
    cv2.circle(img, (ex[1][0], ex[1][1]), R, _WHITE, 2)
    cv2.circle(img, (ex[2][0], ex[2][1]), R, _WHITE, 2)
    cv2.circle(img, (ex[3][0], ex[3][1]), R, _WHITE, 2)
    '''
    return img.astype(np.uint8) 
Example #19
Source File: simplevis.py    From second.pytorch with MIT License 4 votes vote down vote up
def draw_box_in_bev(img,
                    coors_range,
                    boxes,
                    color,
                    thickness=1,
                    labels=None,
                    label_color=None):
    """
    Args:
        boxes: center format.
    """
    coors_range = np.array(coors_range)
    bev_corners = box_np_ops.center_to_corner_box2d(
        boxes[:, [0, 1]], boxes[:, [3, 4]], boxes[:, 6])
    bev_corners -= coors_range[:2]
    bev_corners *= np.array(
        img.shape[:2])[::-1] / (coors_range[3:5] - coors_range[:2])
    standup = box_np_ops.corner_to_standup_nd(bev_corners)
    text_center = standup[:, 2:]
    text_center[:, 1] -= (standup[:, 3] - standup[:, 1]) / 2

    bev_lines = np.concatenate(
        [bev_corners[:, [0, 2, 3]], bev_corners[:, [1, 3, 0]]], axis=2)
    bev_lines = bev_lines.reshape(-1, 4)
    colors = np.tile(np.array(color).reshape(1, 3), [bev_lines.shape[0], 1])
    colors = colors.astype(np.int32)
    img = cv2_draw_lines(img, bev_lines, colors, thickness)
    if boxes.shape[1] == 9:
        # draw velocity arrows
        for box in boxes:
            velo = box[-2:]
            # velo = np.array([-np.sin(box[6]), -np.cos(box[6])])
            velo_unified = velo
            if np.isnan(velo_unified[0]):
                continue
            velo_unified = velo_unified * np.array(
                img.shape[:2])[::-1] / (coors_range[3:5] - coors_range[:2])
            center = box[:2] - coors_range[:2]
            center = center * np.array(
                img.shape[:2])[::-1] / (coors_range[3:5] - coors_range[:2])
            center = tuple(map(lambda x: int(x), center))
            center2 = tuple(map(lambda x: int(x), center + velo_unified))
            cv2.arrowedLine(img, center, center2, color, thickness, tipLength=0.3)
    if labels is not None:
        if label_color is None:
            label_color = colors
        else:
            label_color = np.tile(
                np.array(label_color).reshape(1, 3), [bev_lines.shape[0], 1])
            label_color = label_color.astype(np.int32)

        img = cv2_draw_text(img, text_center, labels, label_color,
                            thickness)
    return img 
Example #20
Source File: mylib.py    From anomaly-event-detection with MIT License 4 votes vote down vote up
def dispOpticalFlow (Image, Flow, Divisor, name ):
    """
    
    Display image with a visualisation of a flow over the top. 
    A divisor controls the density of the quiver plot.
    
    Arguments:
        Image:      Image on which to display flow lines
        Flow :      Flow vectors x and y
        Divisor:    Spacing between the arrow nodes
        name:       Name of the window
    """
    PictureShape = np.shape (Image)
    # determine number of quiver points there will be
    Imax = int (PictureShape[0] / Divisor)
    Jmax = int (PictureShape[1] / Divisor)
    # create a blank mask,   on which lines will be drawn.
    mask = np.zeros_like (Image)
    panel = np.zeros_like (Image)

    for i in range (1, Imax):
        for j in range (1, Jmax):
            X1 = (i) * Divisor
            Y1 = (j) * Divisor

            X2 = int (X1 + Flow[X1, Y1, 1])
            Y2 = int (Y1 + Flow[X1, Y1, 0])
            X2 = np.clip (X2, 0, PictureShape[0])
            Y2 = np.clip (Y2, 0, PictureShape[1])
            # add all the lines to the mask

            mask = cv2.arrowedLine (mask, (Y1, X1), (Y2, X2), [255, 255, 255], 1)
            # To show only arrows in the image
            # cv2.namedWindow("Panel", 0)
            # panel = panel+mask
            # cv2.imshow("Panel", panel)
    # superpose lines onto image

    img = cv2.add (Image, mask)
    # print image
    cv2.startWindowThread ()
    cv2.namedWindow (name, 0)
    cv2.imshow (name, img)

    return []