From 3c0166404dd871786cfdb18ce22bc543efc2b37a Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Sun, 2 May 2021 21:44:12 -0700 Subject: [PATCH] Supercollider --- audio.ck | 16 +++++++++++++--- radio.py | 19 +++++++++++++------ radio.sc | 4 ++++ 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 radio.sc diff --git a/audio.ck b/audio.ck index d4d0d6d..c2d02f0 100644 --- a/audio.ck +++ b/audio.ck @@ -6,12 +6,22 @@ SinOsc o3 => m; 500 => o1.freq; 800 => o2.freq; 900 => o3.freq; + OscRecv orec; -orec.event("webcam/update, i") @=> OscEvent update; +5005 => orec.port; orec.listen(); +orec.event("block/update") @=> OscEvent update; + while (true) { update => now; - update.getInt() => int i; - <<< i >>>; + <<< "got data" >>>; + //update.getInt() => int i; + //update.getInt() => int h; + //update.getInt() => int s; + //update.getInt() => int v; + //<<< i >>>; + //<<< h >>>; + //<<< s >>>; + //<<< v >>>; } diff --git a/radio.py b/radio.py index d15a882..d627e5b 100644 --- a/radio.py +++ b/radio.py @@ -1,7 +1,8 @@ -import cv2 -import numpy as np import math import itertools as it +import cv2 +from pythonosc import udp_client +import numpy as np DENSITY = 4 RED = [0, 0, 255] @@ -13,7 +14,7 @@ def draw_rectangle(frame, sp, ep): return cv2.rectangle(frame, sp, ep, RED, 1) -def analyze_block(frame, index, sp, ep): +def analyze_block(frame, osc, index, sp, ep): """ Analyze a block """ block = frame[sp[1]:ep[1], sp[0]:ep[0], 0:3] average_color = np.average(block, (0, 1)) @@ -24,6 +25,11 @@ def analyze_block(frame, index, sp, ep): average_color = np.uint8([[average_color]]) h, s, v = cv2.cvtColor(average_color, cv2.COLOR_BGR2HSV)[0][0] + # Configure the oscillator + # osc.send_message("block/update", [int(x) for x in (index, h, s, v)]) + osc.send_message("/goodbye", 1) + + # Draw the image for thickness, color in ((3, (0, 0, 0)), (1, (255, 255, 255))): frame = cv2.putText(frame, text=f"{h:03d} {s:03d} {v:03d}", @@ -35,7 +41,7 @@ def analyze_block(frame, index, sp, ep): return frame -def analyze(frame): +def analyze(frame, osc): """ Analyze the full frame """ height, width, d = frame.shape n = DENSITY @@ -46,16 +52,17 @@ def analyze(frame): sp = (int(x * dx), int(y * dy)) ep = (int(x * dx + dx), int(y * dy + dy)) frame = draw_rectangle(frame, sp, ep) - frame = analyze_block(frame, index, sp, ep) + frame = analyze_block(frame, osc, index, sp, ep) return frame if __name__ == '__main__': camera = cv2.VideoCapture(0) + osc = udp_client.SimpleUDPClient("0.0.0.0", 5005) while True: ret, frame = camera.read() - frame = analyze(frame) + frame = analyze(frame, osc) cv2.imshow('Input', frame) c = cv2.waitKey(1) diff --git a/radio.sc b/radio.sc new file mode 100644 index 0000000..576d362 --- /dev/null +++ b/radio.sc @@ -0,0 +1,4 @@ +thisProcess.openUDPPort(5005); +n = NetAddr.new("0.0.0.0", 5005) +o = OSCFunc({ arg msg, time, addr, recvPort; [msg, time, addr, recvPort].postln; }, '/block', n); +OSCFunc.trace(true); \ No newline at end of file