|
|
@ -1,7 +1,8 @@
|
|
|
|
#!/usr/bin/env python
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
import numpy as np
|
|
|
|
import numpy as np
|
|
|
|
import cv2, math
|
|
|
|
import cv2, math, sys
|
|
|
|
# import video
|
|
|
|
# import video
|
|
|
|
from picamera.array import PiRGBArray
|
|
|
|
from picamera.array import PiRGBArray
|
|
|
|
from picamera import PiCamera
|
|
|
|
from picamera import PiCamera
|
|
|
@ -10,7 +11,8 @@ import OSC
|
|
|
|
# from pythonosc import udp_client
|
|
|
|
# from pythonosc import udp_client
|
|
|
|
import time
|
|
|
|
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
|
|
|
|
# def draw_flow(img, flow, step=4): # size grid
|
|
|
|
# h, w = img.shape[:2]
|
|
|
|
# h, w = img.shape[:2]
|
|
|
|
# y, x = np.mgrid[step/2:h:step, step/2:w:step].reshape(2,-1)
|
|
|
|
# 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
|
|
|
|
dy = y2 - y1
|
|
|
|
m = int(math.sqrt( (dx*dx) + (dy*dy) ))
|
|
|
|
m = int(math.sqrt( (dx*dx) + (dy*dy) ))
|
|
|
|
if m>2:
|
|
|
|
if m>2:
|
|
|
|
print ("dot", (normx, normy))
|
|
|
|
print ("dot", (normx, normy), file=sys.stderr)
|
|
|
|
msg = OSC.OSCMessage()
|
|
|
|
msg = OSC.OSCMessage()
|
|
|
|
msg.setAddress("/dot")
|
|
|
|
msg.setAddress("/dot")
|
|
|
|
#msg.append(dx)
|
|
|
|
#msg.append(dx)
|
|
|
@ -53,7 +55,11 @@ def send_flow0(img, flow, step=4): # size grid
|
|
|
|
#msg.append(m)
|
|
|
|
#msg.append(m)
|
|
|
|
msg.append(normx)
|
|
|
|
msg.append(normx)
|
|
|
|
msg.append(normy)
|
|
|
|
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)
|
|
|
|
# client.send_message("/franc", m)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -78,6 +84,7 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
|
|
# connect camera
|
|
|
|
# connect camera
|
|
|
|
# cam = video.create_capture("0:size=160x120") #canvas size in pixels
|
|
|
|
# cam = video.create_capture("0:size=160x120") #canvas size in pixels
|
|
|
|
|
|
|
|
print ("Starting camera", file=sys.stderr)
|
|
|
|
cam = PiCamera()
|
|
|
|
cam = PiCamera()
|
|
|
|
framesize = (160, 128)
|
|
|
|
framesize = (160, 128)
|
|
|
|
cam.resolution = framesize
|
|
|
|
cam.resolution = framesize
|
|
|
@ -86,10 +93,17 @@ if __name__ == '__main__':
|
|
|
|
# allow the camera to warmup
|
|
|
|
# allow the camera to warmup
|
|
|
|
time.sleep(0.25)
|
|
|
|
time.sleep(0.25)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print ("Starting main camera loop", file=sys.stderr)
|
|
|
|
# connect to pd
|
|
|
|
# connect to pd
|
|
|
|
# Init OSC
|
|
|
|
# Init OSC
|
|
|
|
client = OSC.OSCClient()
|
|
|
|
while True:
|
|
|
|
client.connect(('127.0.0.1', 9001)) # first argument is the IP of the host, second argument is the port to use
|
|
|
|
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
|
|
|
|
prevgray = None
|
|
|
|
for frame in cam.capture_continuous(rawCapture, format="bgr", use_video_port=True):
|
|
|
|
for frame in cam.capture_continuous(rawCapture, format="bgr", use_video_port=True):
|
|
|
|