Exemple #1
0
    def setup_server(i, conf):
        # Set up server
        sock, clis = networking.server.create_socket_and_client_list(
            port=conf.controlport)
        handler = networking.create_gst_handler(pipeline, None, 'valve' + i,
                                                'udpsink' + i)

        acceptThread = threading.Thread(target=networking.server.AcceptClients,
                                        args=[sock, clis, handler])
        acceptThread.daemon = True  # Makes the thread quit with the current thread
        acceptThread.start()
        return sock
Exemple #2
0
import networking.messages as m
from processing.tapecontours import get_corners_from_image
# Gst = gs.Gst

if __name__ == '__main__':
    conf = config.configfor('Vision')
    cleft = cv2.VideoCapture(0)
    cright = cv2.VideoCapture(1)

    logging.config.dictConfig(conf.logging)
    logger = logging.getLogger(__name__)

    # Set up server
    sock, clis = networking.server.create_socket_and_client_list(
        port=conf.controlport)
    handler = networking.create_gst_handler(None, None, None, None)

    acceptThread = threading.Thread(target=networking.server.AcceptClients,
                                    args=[sock, clis, handler])
    acceptThread.daemon = True  # Makes the thread quit with the current thread
    acceptThread.start()

    while True:
        _, ileft = cleft.read()
        _, iright = cright.read()

        ipleft = np.rot90(ileft, 3)
        ipright = np.rot90(iright, 3)

        corners_left = np.concatenate(get_corners_from_image(ipleft, 1))
        corners_right = np.concatenate(get_corners_from_image(ipright, 2))
Exemple #3
0
        Gst.CLOCK_TIME_NONE))  # Wait for pipeline to play

    caps = gs.get_sink_caps(pipeline.get_by_name(gs.SINK_NAME))
    cap_string = gs.make_command_line_parsable(caps)

    cap = cv2.VideoCapture(gs.SHMSrc(cap_string))

    # Now that the capture filters have been (hopefully) successfully
    # captured, GStreamer doesn't need to be debugged anymore and the thread
    # can be stopped.
    debuggingThread.stop()

    # Set up server
    sock, clis = networking.server.create_socket_and_client_list(
        port=conf.controlport)
    handler = networking.create_gst_handler(pipeline, gs.SRC_NAME, 'valve',
                                            gs.UDP_NAME)

    acceptThread = threading.Thread(target=networking.server.AcceptClients,
                                    args=[sock, clis, handler])
    acceptThread.daemon = True  # Makes the thread quit with the current thread
    acceptThread.start()

    while True:
        _, img = cap.read()
        cv2.imshow('original', img)
        corners = get_corners_from_image(img, show_image=True)

        # Send the coordinates to the roborio
        corns = [[(int(a[0]), int(a[1])) for a in b] for b in corners]
        message = m.create_message(m.TYPE_RESULTS, {m.FIELD_CORNERS: corns})
        networking.server.broadcast(sock, clis, message)
    pipeline = gs.pipeline(
        gs.RaspiCam(awb=True, expmode=1) + gs.Valve('valve') +
        gs.H264Stream(port=5002)  # Default to port 5002
    )
    pipeline.set_state(Gst.State.PLAYING)

    # Start debugging the gstreamer pipeline
    debuggingThread = gs.MessagePrinter(pipeline)
    debuggingThread.start()

    # TODO: Find a better method to wait for playback to start
    print(pipeline.get_state(Gst.CLOCK_TIME_NONE))  # Wait for pipeline to play

    # Now that the pipeline has been (hopefully) successfully started,
    # GStreamer doesn't need to be debugged anymore and the thread can be
    # stopped.
    debuggingThread.stop()

    # Set up server
    sock, clis = networking.server.create_socket_and_client_list()
    handler = networking.create_gst_handler(pipeline, None, 'valve',
                                            gs.SINK_NAME)

    acceptThread = threading.Thread(target=networking.server.AcceptClients,
                                    args=[sock, clis, handler])
    acceptThread.daemon = True  # Makes the thread quit with the current thread
    acceptThread.start()

    input('Streaming... Press enter to quit.')
    sock.close()