python msgs to stderr

master
Michael Murtaugh 8 years ago
parent 07e0671401
commit c42cfe6aef

@ -1,7 +1,8 @@
#!/usr/bin/env python
from __future__ import print_function
import numpy as np
import cv2, math
import cv2, math, sys
# import video
from picamera.array import PiRGBArray
from picamera import PiCamera
@ -10,7 +11,8 @@ import OSC
# from pythonosc import udp_client
import time
# MESSAGES NEED TO GO TO STDERR
print ("1.HELLO FROM PYTHON stderr", file=sys.stderr)
# def draw_flow(img, flow, step=4): # size grid
# h, w = img.shape[:2]
# y, x = np.mgrid[step/2:h:step, step/2:w:step].reshape(2,-1)
@ -45,7 +47,7 @@ def send_flow0(img, flow, step=4): # size grid
dy = y2 - y1
m = int(math.sqrt( (dx*dx) + (dy*dy) ))
if m>2:
print ("dot", (normx, normy))
print ("dot", (normx, normy), file=sys.stderr)
msg = OSC.OSCMessage()
msg.setAddress("/dot")
#msg.append(dx)
@ -53,7 +55,11 @@ def send_flow0(img, flow, step=4): # size grid
#msg.append(m)
msg.append(normx)
msg.append(normy)
client.send(msg)
try:
client.send(msg)
except OSC.OSCClientError:
print ("Unable to send OSC", file=sys.stderr)
# client.send_message("/franc", m)
@ -72,12 +78,13 @@ def send_flow0(img, flow, step=4): # size grid
# cv2.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]])
if __name__ == '__main__':
#data="hello"
# client = udp_client.SimpleUDPClient("127.0.0.1", 9001)
# connect camera
# cam = video.create_capture("0:size=160x120") #canvas size in pixels
print ("Starting camera", file=sys.stderr)
cam = PiCamera()
framesize = (160, 128)
cam.resolution = framesize
@ -86,10 +93,17 @@ if __name__ == '__main__':
# allow the camera to warmup
time.sleep(0.25)
print ("Starting main camera loop", file=sys.stderr)
# connect to pd
# Init OSC
client = OSC.OSCClient()
client.connect(('127.0.0.1', 9001)) # first argument is the IP of the host, second argument is the port to use
while True:
try:
client = OSC.OSCClient()
client.connect(('127.0.0.1', 9001)) # first argument is the IP of the host, second argument is the port to use
break
except OSC.OSCClientError:
print ("Unable to connect via OSC to pd, trying again in 5", file=sys.stderr)
time.sleep(5)
prevgray = None
for frame in cam.capture_continuous(rawCapture, format="bgr", use_video_port=True):

Loading…
Cancel
Save