Ejemplo n.º 1
0
def piCameraSendFrameHelper(stream, frame):
    ''' do the actual frame processing '''
    global piCameraLastFrameIndex

    try:
        # record index of new frame
        piCameraLastFrameIndex = frame.index

        # get the frame data and display it
        stream.seek(frame.position)
        image = stream.read(frame.frame_size)

        timestamp = time.time()
        message = rdf.newPublishMessage('picam', outTopic, vdefs.DATATYPE,
                                        timestamp)
        message[vdefs.WIDTH] = cameraWidth
        message[vdefs.HEIGHT] = cameraHeight
        message[vdefs.RATE] = cameraRate
        message[vdefs.FORMAT] = 'mjpeg'
        if ManifoldPython.isServiceActive(
                sourcePort) and ManifoldPython.isClearToSend(sourcePort):
            ManifoldPython.sendMulticastData(sourcePort, json.dumps(message),
                                             image, timestamp)
    except:
        print("Send frame error ", sys.exc_info()[0], sys.exc_info()[1])
Ejemplo n.º 2
0
def sendMessage():
    global waitForComplete
    
    ret = False    
    
    if (ManifoldPython.isServiceActive(clientPort)):
        ret = ManifoldPython.sendE2EData(clientPort, json.dumps(textMessage), '', time.time())
            
    if ret:
        print('Sent: ' + testText)
        waitForComplete = True
Ejemplo n.º 3
0
def callback(samples, frame_count, time_info, status):

    timestamp = time.time()
    message = rdf.newPublishMessage('audio', audioTopic, adefs.DATATYPE,
                                    timestamp)
    message[adefs.CHANNELS] = audioChannels
    message[adefs.RATE] = audioRate
    message[adefs.SAMPTYPE] = 'int16'
    message[adefs.FORMAT] = 'pcm'
    if ManifoldPython.isServiceActive(
            sourcePort) and ManifoldPython.isClearToSend(sourcePort):
        ManifoldPython.sendMulticastData(sourcePort, json.dumps(message),
                                         samples, timestamp)

    return (None, pyaudio.paContinue)
Ejemplo n.º 4
0
def readSensors():
    global lastSensorReadTime

    if ((time.time() - lastSensorReadTime) < sampleInterval):
        return
    # call background loops
    if accel.sensorValid:
        accel.background()
    if light.sensorValid:
        light.background()
    if temperature.sensorValid:
        temperature.background()
    if pressure.sensorValid:
        pressure.background()
    if humidity.sensorValid:
        humidity.background()

    # time send send the sensor readings
    lastSensorReadTime = time.time()

    message = rdf.newPublishMessage('sensors', outTopic, sdefs.DATATYPE,
                                    lastSensorReadTime)

    if accel.dataValid:
        accelData = accel.readAccel()
        message[sdefs.ACCEL_DATA] = accelData

    if light.dataValid:
        lightData = light.readLight()
        message[sdefs.LIGHT_DATA] = lightData

    if temperature.dataValid:
        temperatureData = temperature.readTemperature()
        message[sdefs.TEMPERATURE_DATA] = temperatureData

    if pressure.dataValid:
        pressureData = pressure.readPressure()
        message[sdefs.PRESSURE_DATA] = pressureData

    if humidity.dataValid:
        humidityData = humidity.readHumidity()
        message[sdefs.HUMIDITY_DATA] = humidityData

    if ManifoldPython.isServiceActive(
            sourcePort) and ManifoldPython.isClearToSend(sourcePort):
        ManifoldPython.sendMulticastData(sourcePort, json.dumps(message), '',
                                         lastSensorReadTime)
Ejemplo n.º 5
0
    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',
                                              timestamp)

            if ManifoldPython.isServiceActive(
                    ttyInPort) and ManifoldPython.isClearToSend(ttyInPort):
                ManifoldPython.sendMulticastData(ttyInPort,
                                                 json.dumps(inMessage),
                                                 readBytes, timestamp)

        time.sleep(0.001)
except:
    print("Main loop error", sys.exc_info()[0], sys.exc_info()[1])

# Exiting so clean everything up.

ManifoldPython.removeService(ttyInPort)
ManifoldPython.removeService(ttyOutPort)
serialPort.close()
ManifoldPython.stop()
Ejemplo n.º 6
0
                    #                    retVal, subJpeg = cv2.imencode('.jpeg', subImage)
                    #                    binSubImage = base64.b64encode(subJpeg)
                    #                    modetarrayentry[mdefs.JPEG] = binSubImage
                    modetarray.append(modetarrayentry)

                    # draw the box in the original image

                    cv2.rectangle(inImage, (x, y), (x + w, y + h), (0, 255, 0),
                                  2)

                metadata[mdefs.TYPE] = modetarray
                jsonToProcess[rtndefs.METADATA] = metadata

                retVal, outJpeg = cv2.imencode('.jpeg', inImage)
                jsonToProcess[rtndefs.TOPIC] = outTopic
                if ManifoldPython.isServiceActive(
                        outPort) and ManifoldPython.isClearToSend(outPort):
                    ManifoldPython.sendMulticastData(outPort,
                                                     json.dumps(jsonToProcess),
                                                     outJpeg, imageTS)

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

            processing = False
        time.sleep(0.01)
except:
    print("Main loop error", sys.exc_info()[0], sys.exc_info()[1])
    pass

ManifoldPython.removeService(inPort)
ManifoldPython.removeService(outPort)
Ejemplo n.º 7
0
            if (jpeg):
                ManifoldPython.displayJpegImage(frame, "")
            else:
                ManifoldPython.displayImage(frame, width, height, "")

            timestamp = time.time()
            message = rdf.newPublishMessage('uvccam', outTopic, vdefs.DATATYPE,
                                            timestamp)
            message[vdefs.WIDTH] = width
            message[vdefs.HEIGHT] = height
            message[vdefs.RATE] = rate
            if jpeg:
                message[vdefs.FORMAT] = 'mjpeg'
            else:
                message[vdefs.FORMAT] = 'raw'
            if ManifoldPython.isServiceActive(
                    sourcePort) and ManifoldPython.isClearToSend(sourcePort):
                ManifoldPython.sendMulticastData(sourcePort,
                                                 json.dumps(message), frame,
                                                 timestamp)

    except:
        print("Main loop error ", sys.exc_info()[0], sys.exc_info()[1])
        break

# Exiting so clean everything up.

ManifoldPython.vidCapClose(cameraIndex)
ManifoldPython.removeService(sourcePort)
ManifoldPython.stop()
Ejemplo n.º 8
0
print("Type characters to send:")

try:
    while True:
        time.sleep(0.001)
        processReceivedText()

        c = ManifoldPython.getConsoleInput()
        if c is None:
            continue

        timestamp = time.time()
        inMessage = rdf.newPublishMessage('ttytest', ttyOutTopic,
                                          'ttydatatype', timestamp)

        if ManifoldPython.isServiceActive(ttyOutPort):
            ManifoldPython.sendE2EData(ttyOutPort, json.dumps(inMessage),
                                       str(chr(c)), timestamp)

except:
    print("Main loop error", sys.exc_info()[0], sys.exc_info()[1])

# Exiting so clean everything up.

ManifoldPython.removeService(ttyInPort)
ManifoldPython.removeService(ttyOutPort)
ManifoldPython.stop()

print("Exiting")
Ejemplo n.º 9
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()