コード例 #1
0
ファイル: rtcaudio.py プロジェクト: dkumor/rtcbot
    RTCConnection,
    Microphone,
    Speaker,
    CVDisplay,
    CVCamera,
    SubscriptionClosed,
)
import logging
from contextlib import suppress
import signal

logging.basicConfig(level=logging.DEBUG)

m = Microphone()
s = Speaker()
d = CVDisplay()
cam = CVCamera()

# cam.subscribe(d)

c1 = RTCConnection()
c2 = RTCConnection()

c1.video.putSubscription(cam)
c1.audio.putSubscription(m)

c2.video.subscribe(d)
c2.audio.subscribe(s)


async def testMe():
コード例 #2
0
# desktop.py

import asyncio
import aiohttp
import cv2
import json
from rtcbot import RTCConnection, Gamepad, CVDisplay

disp = CVDisplay()
#g = Gamepad()
conn = RTCConnection()


@conn.video.subscribe
def onFrame(frame):
    # Show a 4x larger image so that it is easy to see
    resized = cv2.resize(frame, (frame.shape[1] * 4, frame.shape[0] * 4))
    disp.put_nowait(resized)


async def connect():
    localDescription = await conn.getLocalDescription()
    async with aiohttp.ClientSession() as session:
        async with session.post("http://192.168.0.3:8080/connect",
                                data=json.dumps(localDescription)) as resp:
            response = await resp.json()
            await conn.setRemoteDescription(response)
    # Start sending gamepad controls
    #g.subscribe(conn)

コード例 #3
0
import cv2
import json
import time
import serial
import imutils
import asyncio
import datetime
from utils.conf import Conf
from threading import Thread
from imutils.io import TempFile
from imutils.video import VideoStream
from Logix_dir.MotionWriter import KeyClipWriter, Uploader
from rtcbot import Websocket, RTCConnection, CVCamera, CVDisplay

cam = CVCamera()
display = CVDisplay()

trans = 0
PS = False  # pin state resp from Arduino
cams = False  # flag var for webrtc video started

kcw = KeyClipWriter(bufSize=32)

conf = Conf("config/config.json")
up = Uploader(conf)

path = ''

try:
    arduino = serial.Serial('/dev/ttyUSB0', 9600, timeout=.1)
    time.sleep(1)
コード例 #4
0
import asyncio
from rtcbot import CVCamera, CVDisplay

camera = CVCamera()
display = CVDisplay()

display.putSubscription(camera)

try:
    asyncio.get_event_loop().run_forever()
finally:
    camera.close()
    display.close()
コード例 #5
0
from rtcbot import Microphone, Speaker, CVCamera, CVDisplay
import asyncio
import functools
import os
import signal
from contextlib import suppress

import logging

logging.basicConfig(level=logging.DEBUG)

s = Speaker()
m = Microphone()
c = CVCamera()
d = CVDisplay()
m.subscribe(s)
c.subscribe(d)
loop = asyncio.get_event_loop()
"""
def shutdown(signame):
    print("got signal %s: exit" % signame)
    loop = asyncio.get_event_loop()
    loop.stop()



for sig in (signal.SIGINT, signal.SIGTERM):
    loop.add_signal_handler(sig, shutdown, sig)

print("Event loop running forever, press Ctrl+C to interrupt.")
コード例 #6
0
ファイル: bwvideo.py プロジェクト: techwitz/rtcbot
import asyncio
from rtcbot import CVCamera, CVDisplay
import cv2

camera = CVCamera()
display = CVDisplay()


@camera.subscribe
def onFrame(frame):
    bwframe = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    display.put_nowait(bwframe)


try:
    asyncio.get_event_loop().run_forever()
finally:
    camera.close()
    display.close()
コード例 #7
0
import asyncio
from rtcbot import Websocket, RTCConnection, CVCamera, CVDisplay, Speaker, Microphone

flag = 0
camera1 = CVCamera(cameranumber=0)
camera2 = CVCamera(cameranumber=2)
mic = Microphone()
display = CVDisplay()
speaker = Speaker()

# For this example, we use just one global connection
conn = RTCConnection()
conn.video.putSubscription(camera1)
conn.audio.putSubscription(mic)
display.putSubscription(conn.video.subscribe())
speaker.putSubscription(conn.audio.subscribe())


async def receiver():
    global flag
    while True:
        if flag:
            frameSubscription = camera2.subscribe()
        else:
            frameSubscription = camera1.subscribe()
        frame = await frameSubscription.get()
        conn.video.put_nowait(frame)


@conn.subscribe
def onMessage(msg):  # Called when each message is sent
コード例 #8
0
ファイル: desktop.py プロジェクト: dkumor/rtcbot
# desktop.py

import asyncio
import aiohttp
import cv2
import json
from rtcbot import RTCConnection, Gamepad, CVDisplay

disp = CVDisplay()
g = Gamepad()
conn = RTCConnection()


@conn.video.subscribe
def onFrame(frame):
    # Show a 4x larger image so that it is easy to see
    resized = cv2.resize(frame, (frame.shape[1] * 4, frame.shape[0] * 4))
    disp.put_nowait(resized)


async def connect():
    localDescription = await conn.getLocalDescription()
    async with aiohttp.ClientSession() as session:
        async with session.post(
            "http://localhost:8080/connect", data=json.dumps(localDescription)
        ) as resp:
            response = await resp.json()
            await conn.setRemoteDescription(response)

    # Start sending gamepad controls
    g.subscribe(conn)
コード例 #9
0
ファイル: browser_audiovideo.py プロジェクト: dkumor/rtcbot
from aiohttp import web

routes = web.RouteTableDef()

from rtcbot import RTCConnection, getRTCBotJS, CVDisplay, Speaker

display = CVDisplay()
speaker = Speaker()

# For this example, we use just one global connection
conn = RTCConnection()
display.putSubscription(conn.video.subscribe())
speaker.putSubscription(conn.audio.subscribe())


# Serve the RTCBot javascript library at /rtcbot.js
@routes.get("/rtcbot.js")
async def rtcbotjs(request):
    return web.Response(content_type="application/javascript", text=getRTCBotJS())


# This sets up the connection
@routes.post("/connect")
async def connect(request):
    clientOffer = await request.json()
    serverResponse = await conn.getLocalDescription(clientOffer)
    return web.json_response(serverResponse)


@routes.get("/")
async def index(request):
コード例 #10
0
ファイル: avshow.py プロジェクト: techwitz/rtcbot
from rtcbot import Microphone, Speaker, CVCamera, CVDisplay
import asyncio
import logging

logging.basicConfig(level=logging.DEBUG)

m = Microphone()
s = Speaker()
c = CVCamera()
d = CVDisplay()

s.putSubscription(m)
d.putSubscription(c)


@c.onReady
def ready():
    print("LOL READY")


@d.onError
def err(e):
    print("ERR", e)


asyncio.get_event_loop().run_forever()