def draw (self, frame, **kwargs) : 
        """
        draw left and right max line
        @input:
            - frame
        @param: 
            - color
        @output:
            - frame
        """


        frame = frame.copy ()

        lines = []
        # first line min
        if self.min[1] is not None : 
            lines.append (Line.from_two_points (self.min[1], self.vp1))

        # then line max
        if self.max[1] is not None : 
            lines.append (Line.from_two_points (self.max[1], self.vp1))

        for l in lines : 
            frame = l.draw (frame, **kwargs)
        return frame
def get_corner_points (blob, vp1, vp2, pos_vp1, pos_vp2) : 
    cps = []
    for b in blobs : 
        # first get from left to right
        c1_right, c1_left = get_extreme_tan_point (vp1, b)
        c2_right, c2_left = get_extreme_tan_point (vp2, b)
        c3_right, c3_left = get_extreme_tan_point (None, b)

        # get ground line vp1
        # if position of vp1 is top-left (0), then 
        # the ground line is vp1 and c1_left
        if vp1_pos == 0 :
            gl_vp1 = Line.from_two_points (vp1, c1_left)

        # otherwise the groundline is vp1 and c1_right
        else :
            gl_vp1 = Line.from_two_points (vp1, c1_right) 

        # get ground line vp2
        # same with above, if the position of vp2  is top-right (1)
        # then the ground line is line between vp2 and c2_right
        if vp2_pos == 1 : 
            gl_vp2 = Line.from_two_points (vp2, c2_right)

        # otherwise it between vp2 and c2_left
        else :
            gl_vp2 = Line.from_two_points (vp2, c2_left)

        # get ground line vp3
        # it depend on the vp1, if vp1 position is top left, 
        # then construct line with c3_left
        if vp1_pos == 0 : 
            gl_vp3 = Line (None, c3_left[0])

        # otherwise with c3_right
        else : 
            gl_vp3 = Line (None, c3_right[0])

        """
        # get helper line
        line = [
                Line.from_two_points (vp1, c1_left),
                Line.from_two_points (vp2, c2_right),
                Line (None, c3_left[0])
            ]
        """

        # get corner point 
        cp = [
                gl_vp1.get_intersection (gl_vp2),
                gl_vp2.get_intersection (gl_vp3)
            ]

        cps.append (cp)
    return cps
Exemplo n.º 3
0
def get_corner_ground (vp1, vp2, points) : 
    # convention of points : 
    #   [left, top, right, bottom]

    lines = [
            Line.from_two_points (vp1, points[0]), # left line
            Line.from_two_points (vp2, points[1]), # top line,
            Line.from_two_points (vp1, points[2]), # right line
            Line.from_two_points (vp2, points[3]) # bottom line
        ]

    corner = (
            lines[0].get_intersection (lines[1]), # top left corner
            lines[1].get_intersection (lines[2]), # top right corner
            lines[2].get_intersection (lines[3]), # bottom right corner
            lines[3].get_intersection (lines[0]) # bottom left corner
        )
    
    return corner
Exemplo n.º 4
0
    def inverse_bin_Line(self, b, point):
        """
        Convert back from bin index into a Line, drawn from a point
        @input:
            - b, [Int, Int], bin index
            - point, [Float, Float], (x,y) value coordinate, a reference point to
                create a Line
        @param:
            -
        @output:
            - line, a Line object
        """

        r, theta = self.inverse_bin(b)
        x = r * math.cos(theta)
        y = r * math.sin(theta)
        l = Line.from_two_points((x, y), point)

        return l
Exemplo n.º 5
0
    # apply mask
    fg = cv2.bitwise_and(fg, mask)
    # get blobs
    blobs = get_contours(fg)

    # only consider that has object on it
    if blobs:

        for vp in (vp1, vp2):
            # select first blobs
            this_blobs = blobs[0]
            # get its tan point
            tan_left, tan_right = get_extreme_tan_point_contours(vp, blobs)

            # construct line from tangent point to vp2
            l_left_vp = Line.from_two_points(tan_left, vp)
            l_right_vp = Line.from_two_points(tan_right, vp)

            # draw lane
            frame = l_left_vp.draw(frame)
            frame = l_right_vp.draw(frame)

    # put text of iterator
    loc = (20, img.shape[0] - 20)
    cv2.putText(frame, 'Frame - {}'.format(ctr_frame), loc,
                cv2.FONT_HERSHEY_PLAIN, 3, (0, 128, 128), 4)

    cv2.imshow('default', frame)

    if (cv2.waitKey(1) & 0xFF == ord('q')):
        break
Exemplo n.º 6
0
vp_path = '../data/gt/2016-ITS-BrnoCompSpeed/results/{}/system_dubska_bmvc14.json'.format(
    session_id)
with open(vp_path, 'r') as f_buff:
    """
    vp has 2 keys
    - cars, list of cars detected, its frame and posX and posY
    - camera_calibration, the calibration parameter result (pp, vp1, and vp2)
    """
    vp = json.load(f_buff)
vp1 = vp['camera_calibration']['vp1']
vp2 = vp['camera_calibration']['vp2']

fi = FrameIterator('../data/sync/{}'.format(session_id))
ctr_frame = 1
while True:
    img = next(fi)

    div_line = Line.from_two_points(vp2, (10, img.shape[0] / 2))

    frame = div_line.draw(img)

    loc = (20, img.shape[0] - 20)
    cv2.putText(frame, 'Frame - {}'.format(ctr_frame), loc,
                cv2.FONT_HERSHEY_PLAIN, 3, (0, 128, 128), 4)

    cv2.imshow('default', frame)

    if (cv2.waitKey(1) & 0xFF == ord('q')):
        break
    ctr_frame += 1
Exemplo n.º 7
0
        for view in VIEW : 
            # first, draw ground truth
            points = GT['session{}'.format (ses_id)][view]
            corner = np.float32 (get_corner_ground (vp[view]['vp1'], vp[view]['vp2'], points))

            M_inv = cv2.getPerspectiveTransform (corner_wrap, corner)

            blobs = get_contours (fgs[view])

            # convert foreground to color so can be enhanched
            fgs[view] = imgs_color[view] # 
            # fgs[view] = cv2.cvtColor (fgs[view], cv2.COLOR_GRAY2BGR)

            for b_idx, b in enumerate (bbox[view]) : 

                la = Line.from_two_points (b[0], b[2])
                lb = Line.from_two_points (b[1], b[3])

                middle_point = la.get_intersection (lb)
                middle_point = tuple ([int (_) for _ in middle_point])
                color = (255, b_idx * 255, 255)
                thickness = 2

                # fgs[view] = draw_polylines (fgs[view], b, color, thickness )

                # b = np.matrix (b)
                bottom_polylines = b

                # get blobs that contain this 
                is_found = False
                for bl in blobs : 
        # max angle from vp2 for this frame only
        max_angle_vp2 = None
        max_point_vp2 = None
        min_angle_vp2 = None
        min_point_vp2 = None

        for b in blobs : 
            # first get from left to right
            c1_right, c1_left = get_extreme_tan_point (vp1, b)
            c2_right, c2_left = get_extreme_tan_point (vp2, b)
            c3_right, c3_left = get_extreme_tan_point (None, b)

            # get helper line
            line = [
                    Line.from_two_points (vp1, c1_left),
                    Line.from_two_points (vp2, c2_right),
                    Line (None, c3_left[0])
                ]

            # draw line
            for l_idx, l in enumerate (line) : 
                color = [0, 0, 0]
                color[l_idx] += 255
                frame = l.draw (frame, color=color)

            # get corner point 
            cp = [
                    line[0].get_intersection (line[1]),
                    line[1].get_intersection (line[2])
                ]
                # if the first line is found, then for the next, using the
                # furthest line
                if TBL.is_found0 : 
                    if min_angle_vp2 is None or min_angle_vp2 < ang : 
                        min_angle_vp2 = ang
                        min_point_vp2 = c
                else : 
                    if min_angle_vp2 is None or min_angle_vp2 > ang : 
                        min_angle_vp2 = ang
                        min_point_vp2 = c

            # convert max top-bottom from point to polar line
            if min_point_vp2 is not None : 
                # first find its line parameter
                # just take the furthest (bottom)
                l = Line.from_two_points (vp2, min_point_vp2)
                line_extreme_vp2.append (l)

                # draw top-bottom 
                frame = l.draw (frame)
                point_extreme_vp2.append (min_point_vp2)

            else : 
                line_extreme_vp2.append (None)
                point_extreme_vp2.append (None)


            # combine each view
            if view_frame is None :
                view_frame = frame
            else :
Exemplo n.º 10
0
        vps[view] = {
            'vp1': vp['camera_calibration']['vp1'],
            'vp2': vp['camera_calibration']['vp2']
        }

img = {}
for i in range(300):
    view_frame = None
    for view in session[_id]:
        # draw mask
        img_color = next(fi[view])
        img[view] = cv2.addWeighted(img_color, 0.7, masks[view], 0.3, 0)

        # draw line
        lines = [
            Line.from_two_points(common_plane_coor['session0'][view][0],
                                 vps[view]['vp2']),  # top
            Line.from_two_points(common_plane_coor['session0'][view][-1],
                                 vps[view]['vp2']),  # bottom
            Line.from_two_points(common_plane_coor['session0'][view][1],
                                 vps[view]['vp1']),  # right 
            Line.from_two_points(common_plane_coor['session0'][view][2],
                                 vps[view]['vp1']),  # left 
        ]

        for l in lines:
            img[view] = l.draw(img[view])

        # combine view
        if view_frame is None:
            view_frame = img[view]
        else:
Exemplo n.º 11
0
        # frame = draw_bounding_box_contours (frame, blobs)
        # frame = fg

        # only consider that has object on it
        if blobs:

            for b in blobs:

                # first get from left to right
                c1_right, c1_left = get_extreme_tan_point(vp1, b)
                c2_right, c2_left = get_extreme_tan_point(vp2, b)
                c3_right, c3_left = get_extreme_tan_point(None, b)

                # get line
                line = [
                    Line.from_two_points(vp1, c1_left),
                    Line.from_two_points(vp2, c2_right),
                    Line(None, c3_left[0])
                ]

                for l_idx, l in enumerate(line):
                    color = [0, 0, 0]
                    color[l_idx] += 255
                    frame = l.draw(frame, color=color)

                # draw corner point
                cp = [
                    line[0].get_intersection(line[1]),
                    line[1].get_intersection(line[2])
                ]