Ejemplo n.º 1
0
def audioThread():
    firstAudio = True
    audioStream = None
    audioDevice = pyaudio.PyAudio()

    # Activate the audio stream

    audioPort = ManifoldPython.addMulticastSink(audioTopic)
    if (audioPort == -1):
        print("Failed to activate audio stream")
        ManifoldPython.stop()
        sys.exit()

    while not audioThreadExit:
        ret, data, samples, timestamp = ManifoldPython.getMulticastData(
            audioPort)
        if not ret:
            time.sleep(0.001)
            continue

        try:
            jsonObj = json.loads(data)
            if firstAudio:
                firstAudio = False
                audioStream = audioDevice.open(format=pyaudio.paInt16,
                                               channels=int(
                                                   jsonObj[adefs.CHANNELS]),
                                               rate=int(jsonObj[adefs.RATE]),
                                               output=True)
            audioStream.write(samples)
        except:
            print("audio data error", sys.exc_info()[0], sys.exc_info()[1])

    try:
        audioStream.stop_stream()
        audioStream.close()
    except:
        pass

    audioDevice.terminate()
    ManifoldPython.removeService(audioPort)
Ejemplo n.º 2
0
# start ManifoldPython running

ManifoldPython.start("tty", sys.argv, False)

# this delay is necessary to allow Qt startup to complete
time.sleep(1.0)

# wake up the console
print("tty starting...")
sys.stdout.flush()

# Activate the service endpoint
ttyOutPort = ManifoldPython.addE2EService(ttyOutTopic)
if (ttyOutPort == -1):
    print("Failed to activate E2E service endpoint")
    ManifoldPython.stop()
    sys.exit()

# Activate the multicast endpoint
ttyInPort = ManifoldPython.addMulticastSource(ttyInTopic)
if (ttyInPort == -1):
    print("Failed to activate multicast source endpoint")
    ManifoldPython.stop()
    sys.exit()

serialPort = serial.Serial(ttyPort, ttyRate, timeout=0)

try:
    while True:
        processReceivedText()
Ejemplo n.º 3
0
def forwardThread():
    global processingForward, forwardMessage, forwardImage, forwardTS, forwardThreadExit, inPort

    # start ManifoldPython running

    ManifoldPython.start("facerec", sys.argv, False)

    # this delay is necessary to allow Qt startup to complete
    time.sleep(1.0)
    
    # Activate the input stream
    inPort = ManifoldPython.addMulticastSink(inTopic)
    if (inPort == -1):
        print("Failed to activate input stream")
        ManifoldPython.stop()
        sys.exit()

    # Activate the output stream
    outPort = ManifoldPython.addMulticastSource(outTopic)
    if (outPort == -1):
        print("Failed to activate output stream")
        ManifoldPython.stop()
        sys.exit()

    while not forwardThreadExit:
        time.sleep(0.01)
        processReceivedMessage()       
        if not processingForward:
            continue
        
        try:
            image = forwardImage
            inJpeg = np.frombuffer(image, dtype=np.uint8)
            cv2Image = cv2.imdecode(inJpeg, cv2.IMREAD_COLOR)

        except:
            print ("Forward jpeg error", sys.exc_info()[0],sys.exc_info()[1])

        try:
            dataLock.acquire()
            for detectedData in globalDetectedData:
                name = detectedData['name']
                namepos = detectedData['namepos']

                cv2.putText(cv2Image, name, namepos,
                    cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.75,
                    color=(152, 255, 204), thickness=2)

                landMarks = detectedData['landmarks']

                for landMark in landMarks:
                    cv2.circle(cv2Image, center=landMark, radius=3,
                       color=(102, 204, 255), thickness=-1)
        except:
            pass

        dataLock.release()

        # generate the output jpeg
        retVal, outJpeg = cv2.imencode('.jpeg', cv2Image)

        forwardMessage[rtndefs.TOPIC] = outTopic
        if ManifoldPython.isServiceActive(outPort) and ManifoldPython.isClearToSend(outPort):
            ManifoldPython.sendMulticastData(outPort, json.dumps(forwardMessage), outJpeg, forwardTS)
        processingForward = False

    ManifoldPython.removeService(inPort)
    ManifoldPython.removeService(outPort)
    ManifoldPython.stop()