def draw(comp, base, fine, W=3000, H=2000): arr = np.zeros((H,W,3), np.uint8) segs = reduce(lambda x,y: x+y, [X.getArrangement().getSequencePreview().segs for X in comp.rhythms]) out_t = 0 duration = max([X.start+X.duration for X in segs]) for seg in segs: cv2.line(arr, (int(W*(out_t/duration)), 0), (int(W*(seg.start/duration)), H), (255,255,255)) out_t += seg.duration base = cv2.resize(numm.image2np(base), (W,H)) fine = cv2.resize(numm.image2np(fine), (W,H)) divisors = np.linspace(0, 1, H).reshape((-1,1,1)) comp = ((base*(1-divisors)) + (fine*divisors)).astype(np.uint8) numm.np2image(comp, 'COMP.PNG') comp[arr==0] = 0 return comp
def draw(comp, base, fine, W=3000, H=2000): arr = np.zeros((H, W, 3), np.uint8) segs = reduce( lambda x, y: x + y, [X.getArrangement().getSequencePreview().segs for X in comp.rhythms]) out_t = 0 duration = max([X.start + X.duration for X in segs]) for seg in segs: cv2.line(arr, (int(W * (out_t / duration)), 0), (int(W * (seg.start / duration)), H), (255, 255, 255)) out_t += seg.duration base = cv2.resize(numm.image2np(base), (W, H)) fine = cv2.resize(numm.image2np(fine), (W, H)) divisors = np.linspace(0, 1, H).reshape((-1, 1, 1)) comp = ((base * (1 - divisors)) + (fine * divisors)).astype(np.uint8) numm.np2image(comp, 'COMP.PNG') comp[arr == 0] = 0 return comp
import compose def draw(comp, cover, W=1200, H=600): arr = np.zeros((H,W,3), np.uint8) covarr = cv2.resize(cover, (W,H)) segs = reduce(lambda x,y: x+y, [X.getArrangement().getSequencePreview().segs for X in comp.rhythms]) count = 0 duration = max([X.start+X.duration for X in segs]) total = W*H temparr = [] temparr2 = [] for i in range(len(covarr)): temparr.extend(covarr[i][:][:]) for seg in segs: a = int(total*(seg.start/duration)) b = int(total*((seg.start+seg.duration)/duration)) temparr2.extend(temparr[a:b]) for j in range(H): for i in range(W): if count < len(temparr2)-1: arr[j][i] = temparr2[count] count+=1 else: break return arr if __name__=='__main__': import sys comp = compose.Composition.fromfile(sys.argv[1]) cover = numm.image2np(sys.argv[2]) numm.np2image(draw(comp, cover), sys.argv[3])
covarr = cv2.resize(cover, (W, H)) segs = reduce( lambda x, y: x + y, [X.getArrangement().getSequencePreview().segs for X in comp.rhythms]) count = 0 duration = max([X.start + X.duration for X in segs]) total = W * H temparr = [] temparr2 = [] for i in range(len(covarr)): temparr.extend(covarr[i][:][:]) for seg in segs: a = int(total * (seg.start / duration)) b = int(total * ((seg.start + seg.duration) / duration)) temparr2.extend(temparr[a:b]) for j in range(H): for i in range(W): if count < len(temparr2) - 1: arr[j][i] = temparr2[count] count += 1 else: break return arr if __name__ == '__main__': import sys comp = compose.Composition.fromfile(sys.argv[1]) cover = numm.image2np(sys.argv[2]) numm.np2image(draw(comp, cover), sys.argv[3])
import numm import cv2 import numpy as np import pickle PATH = "a.png" # PATH = 'b.png' net = numm.image2np(PATH) MOUSEX = 0 MOUSEY = 0 PX = 0 PY = 0 OFFX = 0 OFFY = 0 CIRCLES = [] EDGES = [] def find_circles(img, cutoff=125, blur=10, min_area=2, max_area=50): blur = cv2.blur(img, (blur, blur)) blur = blur.mean(axis=2) threshold = (blur < cutoff).astype(np.uint8) contours, hierarchy = cv2.findContours(threshold, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) circles = [cv2.minEnclosingCircle(X) for X in contours] circles = filter(lambda (xy, r): r * 2 * np.pi >= min_area and r * 2 * np.pi <= max_area, circles)