Ejemplo n.º 1
0
def test():

    our_defence_flag = False
    enemy_defence_flag = False

    cap = cv2.VideoCapture('/Users/itaegyeong/Desktop/GOPR0011.mov')

    if cap.isOpened():
        while True:
            ret, frame = cap.read()
            if ret is True:


                # Get trans Matrix, trans image weight and height
                trans_matrix, trans_w, trans_h = gtv.get_trans_matrix([23,164],[432,358], [205,34]
                                                                      ,[532,142])

                # Get object's points
                find_frame, our_team_point, enemy_team_point, other_point = gop.main(frame)

                # Get trans object's points
                dst, trans_our_team_point, trans_enemy_team_point, trans_other_point = \
                    gtv.trans_object_point(find_frame, our_team_point, enemy_team_point,
                                           other_point, trans_matrix, trans_w, trans_h)

                key = cv2.waitKey(1) & 0xFF

                if key == ord('d'):
                    if our_defence_flag is False:
                        our_defence_flag = True
                    else:
                        our_defence_flag = False

                if key == ord('f'):
                    if enemy_defence_flag is False:
                        enemy_defence_flag = True
                    else:
                        enemy_defence_flag = False

                if our_defence_flag is True and enemy_defence_flag is False:
                    result_frame = dp.canvas_show(trans_our_team_point, trans_enemy_team_point, trans_other_point,
                                                  trans_w,trans_h, 1)
                if enemy_defence_flag is True and our_defence_flag is False:
                    result_frame = dp.canvas_show(trans_our_team_point, trans_enemy_team_point, trans_other_point,
                                                  trans_w,trans_h, -1)
                if enemy_defence_flag is True and our_defence_flag is True:
                    result_frame = dp.canvas_show(trans_our_team_point, trans_enemy_team_point, trans_other_point,
                                                  trans_w,trans_h, 2)

                if our_defence_flag is False and enemy_defence_flag is False:
                    result_frame = dp.canvas_show(trans_our_team_point, trans_enemy_team_point, trans_other_point,
                                                  trans_w, trans_h, 0)

                cv2.imshow('result_frame', result_frame)
                cv2.imshow('bird eye view', dst)
                cv2.imshow('find object frame', find_frame)
                # cv2.imshow('stadium frame',stadium_frame)
                cv2.imshow('original_frame', frame)
Ejemplo n.º 2
0
def main():
    frame_success = False

    cap = cv2.VideoCapture('/Users/itaegyeong/Desktop/GOPR0011.mov')

    trans_matrix, trans_w, trans_h = None, None, None

    if cap.isOpened():
        while True:
            ret, frame = cap.read()
            if ret is True:

                # Get stadium frame and stadium's points [ [x1,y1], [x2,y2], [x3,y3], [x4,y4] ]
                if frame_success is False:
                    _, stadium_frame, img, stadium_point = gsp.get_stadium_line(frame)

                    if stadium_frame is None:
                        continue
                    else:
                        # Get trans Matrix, trans image weight and height
                        trans_matrix, trans_w, trans_h = gtv.get_trans_matrix(stadium_point[0], stadium_point[1],
                                                                              stadium_point[2],
                                                                              stadium_point[3])
                        frame_success = True


                # Get object's points
                find_frame, our_team_point, enemy_team_point, other_point = gop.main(frame)

                # Get trans object's points
                dst, trans_our_team_point, trans_enemy_team_point, trans_other_point = \
                    gtv.trans_object_point(find_frame, our_team_point, enemy_team_point,
                                           other_point, trans_matrix, trans_w, trans_h)

                result_frame = dp.canvas_show(trans_our_team_point, trans_enemy_team_point, trans_other_point, trans_w, trans_h)

                cv2.imshow('result_frame',result_frame)
                cv2.imshow('bird eye view', dst)
                cv2.imshow('find object frame',find_frame)
                #cv2.imshow('stadium frame',stadium_frame)
                cv2.imshow('original_frame',frame)

                cv2.waitKey(1)
Ejemplo n.º 3
0
            th1 = cv2.erode(th1, kernel, iterations=1)
            th1 = cv2.dilate(th1, kernel, iterations=4)
            th1 = cv2.erode(th1, kernel, iterations=2)
            cv2.imshow('diff', th1)

            t1 = time.time()

            find_frame, our_team_point, enemy_team_point, other_point = gop.main(
                frame)

            t2 = time.time()
            print(t2 - t1)
            # Get trans object's points
            dst, trans_our_team_point, trans_enemy_team_point, trans_other_point = \
                gtv.trans_object_point(find_frame, our_team_point, enemy_team_point,
                                       other_point, trans_matrix, trans_w, trans_h)

            key = cv2.waitKey(1) & 0xFF

            if key == ord('d'):
                if our_defence_flag is False:
                    our_defence_flag = True
                else:
                    our_defence_flag = False

            if key == ord('f'):
                if enemy_defence_flag is False:
                    enemy_defence_flag = True
                else:
                    enemy_defence_flag = False
Ejemplo n.º 4
0
                # Track object using Kalman Filter
                tracker.Update(other_team_point)

                for i in range(len(tracker.tracks)):
                    if (len(tracker.tracks[i].trace) > 1):
                        for j in range(len(tracker.tracks[i].trace) - 1):
                            x2 = tracker.tracks[i].trace[j + 1][0][0]
                            y2 = tracker.tracks[i].trace[j + 1][1][0]
                            KF_other_team.append([x2, y2])

            t2 = time.time()
            print(t2 - t1)
            # Get trans object's points
            dst, trans_our_team_point, trans_enemy_team_point, trans_other_point = \
                gtv.trans_object_point(find_frame, KF_our_team, KF_enemy_team,
                                       KF_other_team, trans_matrix, trans_w, trans_h)

            key = cv2.waitKey(1) & 0xFF

            if key == ord('d'):
                if our_defence_flag is False:
                    our_defence_flag = True
                else:
                    our_defence_flag = False

            if key == ord('f'):
                if enemy_defence_flag is False:
                    enemy_defence_flag = True
                else:
                    enemy_defence_flag = False