Exemplo n.º 1
0
def for_adjust():
    f2 = MarkersPosition()
    marker1 = Marker(1, position_3D=(400, 2, 400))
    marker2 = Marker(2, position_3D=(800, 5, 700))
    marker3 = Marker(3, position_3D=(1200, 2, 400))
    marker4 = Marker(4, position_3D=(1600, 5, 700))
    marker5 = Marker(5, position_3D=(0, 5, 0))
    marker6 = Marker(5, position_3D=(3000, 3, 0))

    markers = [marker1, marker2, marker3, marker4, marker5, marker6]
    f2.markers_pos = markers
Exemplo n.º 2
0
def init_assignment(formation_setted):
    global marker_1
    global marker_2
    global marker_3
    global marker_4
    marker_1=Marker(1,position_3D=(formation_setted[0][0],formation_setted[0][1],0))
    marker_2=Marker(2,position_3D=(formation_setted[1][0],formation_setted[1][1],0))
    marker_3=Marker(3,position_3D=(formation_setted[2][0],formation_setted[2][1],0))
    marker_4=Marker(4,position_3D=(formation_setted[3][0],formation_setted[3][1],0))
    markers=[marker_1,marker_2,marker_3,marker_4]
    hung_index=assignment_change(formation_setted)
    ms_pos=MarkersPosition()
    ms_pos.markers_pos=markers
    ms_pos.hungarian_index=hung_index
Exemplo n.º 3
0
 def _tcp_link(self, sock, addr):
     print('Accept new connection from %s:%s...' % addr)
     while True:
         data = sock.recv(1024)
         time.sleep(0.1)
         if data == 'exit':
             break
         markers_pos = MarkersPosition()
         reply_data = markers_pos.markers_pos_string + markers_pos.hungarian_index_string
         #            print("reply:",reply_data)
         sock.send(reply_data.encode('utf_8'))
     sock.close()
     print('Connection from %s:%s closed.' % addr)
Exemplo n.º 4
0
def test():
    f2 = MarkersPosition()
    marker1 = Marker(1, position_3D=(400, 2, 400))
    marker2 = Marker(2, position_3D=(800, 5, 700))
    marker3 = Marker(3, position_3D=(1200, 2, 400))
    marker4 = Marker(4, position_3D=(1600, 5, 700))
    marker5 = Marker(5, position_3D=(0, 5, 0))
    marker6 = Marker(5, position_3D=(3000, 3, 0))
    #    marker7=Marker(5,position_3D=(2,5,7))
    #    marker8=Marker(5,position_3D=(1,3,6))

    markers = [marker1, marker2, marker3, marker4, marker5, marker6]
    f2.markers_pos = markers
    #    f2.hungarian_index=[1,2,3,0]

    print("starting")
    test_case = UDP_Server()  #('192.168.1.103',5000)
    test_case.start_server()
    print("ending")
    while True:
        #        print("hello")
        a = 1 + 2
        continue
Exemplo n.º 5
0
def main():
    cap = cv2.VideoCapture('./test_img/draw_video/video_orig_CA.avi')
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)

    cv2.namedWindow("image", cv2.WINDOW_NORMAL)
    video_file_path = "./test_img/"
    file_name = "video_test.avi"
    file_name_orig = "video_orig.avi"

    # Define the codec and create VideoWriter object
    #    fourcc =cv2.VideoWriter_fourcc('M','J','P','G')
    fourcc = cv2.VideoWriter_fourcc(*"XVID")
    out_video = cv2.VideoWriter(video_file_path + file_name, fourcc, 5.0,
                                (1920, 1080))
    out_video_orig = cv2.VideoWriter(video_file_path + file_name_orig, fourcc,
                                     5.0, (1920, 1080))
    #    for_adjust();
    model = None
    if Load_Autoencoder:
        model = joblib.load("./marker_detection/en_neigh_model.m")
    else:
        model = joblib.load("./marker_detection/neigh_model.m")

    log_file_path = "./log.txt"
    log_file = open(log_file_path, "w")

    formation = formation_I
    init_assignment(formation)
    addr = ('192.168.43.95', 5000)
    server = UDP_Server(addr)
    server.start_server()
    i = 0
    while (1):
        ret, frame = cap.read()
        i += 1
        print('i:', i)
        #        if i==21:
        #            continue
        #            cv2.waitKey(0)
        #        cv2.imshow("hello",frame)
        #        cv2.waitKey(0)
        before_markers = detect_markers(frame, model, 118, Load_Autoencoder)
        markers = generate_marker_5_pos(before_markers)

        global marker_1
        global marker_2
        global marker_3
        global marker_4
        global marker_5
        cur_marker_5 = []
        for marker in markers:
            if marker.id == 1:
                marker_1 = marker
            elif marker.id == 2:
                marker_2 = marker
            elif marker.id == 3:
                marker_3 = marker
            elif marker.id == 4:
                marker_4 = marker
            elif marker.id == 5:
                cur_marker_5.append(marker)
        if cur_marker_5 == 2:
            marker_5 = cur_marker_5

        # ********这一句只能在任意拓扑编队中使用**********
        hung_index = assignment_change(formation)

        ms_pos = MarkersPosition()
        ms_pos.markers_pos = markers
        ms_pos.hungarian_index = hung_index
        #        print("*******************markers_position************************")
        print(ms_pos.markers_pos_string)
        #        print(ms_pos.hungarian_index_string)
        #        for marker in markers:
        #            print(marker)
        #        print("***********************************************************")
        log_str = str(round(time.time(),
                            2)) + " " + ms_pos.markers_pos_string + "\n"
        log_file.write(log_str)
        out_video_orig.write(frame)
        markers = [marker_1, marker_2, marker_3, marker_4]  #保持图片中时刻检测到边框
        for marker in markers:
            try:
                marker.highlite_marker(frame)
            except:
                continue
        for marker in marker_5:
            try:
                marker.highlite_marker(frame)
            except:
                continue


#        if i<=272:
#            draw_T(frame,0)
#        else:
#            draw_T(frame,1)
#        draw_Line(frame)
#        frame=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        cv2.imshow("image", frame)
        out_video.write(frame)

        key = cv2.waitKey(10)
        if key == 27:
            break

    server.stop_server()
    log_file.close()
    out_video.release()
    out_video_orig.release()
    cap.release()
    cv2.destroyAllWindows()