Beispiel #1
0
# 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()

        readBytes = serialPort.read(256)
        if len(readBytes) > 0:
            timestamp = time.time()
            inMessage = rdf.newPublishMessage('tty', ttyInTopic, 'tty',
Beispiel #2
0
    if opt == '-p':
        audioTopic = arg
    if opt == '-n':
        audioChannels = int(arg)
    if opt == '-r':
        audioRate = int(arg)

# start ManifoldPython running

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

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

# Activate the source stream
sourcePort = ManifoldPython.addMulticastSource(audioTopic)
if (sourcePort == -1):
    print("Failed to activate stream service")
    ManifoldPython.stop()
    sys.exit()

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

# start up the audio device

audioDevice = pyaudio.PyAudio()
audioBlockSize = audioRate / 20
audioStream = audioDevice.open(stream_callback=callback,
                               format=pyaudio.paInt16,
Beispiel #3
0
# This controls the minimum contour area that will be accepted
minContourArea = 300

# This controls the thresholding applied before contour detection
maskThreshold = 8

# 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()

try:
    #   Create the background subtractor
    fgbg = cv2.createBackgroundSubtractorMOG2(bgHistory, bgThreshold, False)

    while True:
        processReceivedMessage()
        if (processing):
            try:
                image = imageToProcess
Beispiel #4
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()