示例#1
0
文件: picam.py 项目: chatbox77/rtndf
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])
示例#2
0
文件: audio.py 项目: chatbox77/rtndf
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)
示例#3
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)
示例#4
0
    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()
示例#5
0
                    #                    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)
示例#6
0
文件: uvccam.py 项目: chatbox77/rtndf
            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()
示例#7
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()            
示例#8
0
imu.setCompassEnable(True)

if (not pressure.pressureInit()):
    print("Pressure sensor Init Failed")
else:
    print("Pressure sensor Init Succeeded")

if (not humidity.humidityInit()):
    print("Humidity sensor Init Failed")
else:
    print("Humidity sensor Init Succeeded")

poll_interval = imu.IMUGetPollInterval()
print("Recommended Poll Interval: %dmS\n" % poll_interval)

while True:
    time.sleep(poll_interval*1.0/1000.0)
    if imu.IMURead():
        timestamp = time.time()
        message = rdf.newPublishMessage('imu', outTopic, idefs.DATATYPE, timestamp)
        data = imu.getIMUData()
        (data["pressureValid"], data["pressure"], data["pressureTemperatureValid"], data["pressureTemperature"]) = pressure.pressureRead()
        (data["humidityValid"], data["humidity"], data["humidityTemperatureValid"], data["humidityTemperature"]) = humidity.humidityRead()
        message[idefs.DATA] = data
        if ManifoldPython.isServiceActive(outPort) and ManifoldPython.isClearToSend(outPort):
            ManifoldPython.sendMulticastData(outPort, json.dumps(message), '', timestamp)


ManifoldPython.removeService(outPort)
ManifoldPython.stop()