Ejemplo n.º 1
0
def createAudio(length, sampleRate, functionLength, singleWeight, numberWeight):
    function = randFunction(functionLength, singleWeight, numberWeight)

    clProgram = replace(clProgramTemplate, '<FUNCTION>', function)

    gpu.readFromString(clProgram)

    globalSize = (length*sampleRate,)

    output = np.zeros(globalSize, dtype=np.float32)


    gpu.setup([], output)

    output = gpu.run('AutoAudio', globalSize) % (32767 * 2) - 32767

    name = directory + '/' + \
             ' '.join([namemaker3.generate() for i in range(3)]) + '.wav'

    outputFile = wave.open(name, 'w')
    outputFile.setparams((1, 1, sampleRate, 0, 'NONE', 'not compressed'))

    outputFile.writeframes(output)

    outputFile.close()
Ejemplo n.º 2
0
def createImage(width, height, functionLength, singleWeight, numberWeight):

    rfunction = randFunction(functionLength, singleWeight, numberWeight)
    gfunction = randFunction(functionLength, singleWeight, numberWeight)
    bfunction = randFunction(functionLength, singleWeight, numberWeight)
    
    clProgram = replace(clProgramTemplate, '<WIDTH>', str(width))
    clProgram = replace(clProgram, '<RFUNCTION>', rfunction)
    clProgram = replace(clProgram, '<GFUNCTION>', gfunction)
    clProgram = replace(clProgram, '<BFUNCTION>', bfunction)

    gpu.readFromString(clProgram)

    globalSize = (width*height*3,)

    output = np.zeros(globalSize, dtype=np.float32) % 255

    gpu.setup([], output)

    output = gpu.run('AutoImage', globalSize)

    output.resize(height, width, 3, refcheck=False)

    img = Image.fromarray(output.astype(np.uint8), 'RGB')
    img.save(directory + '/' +
             ' '.join([namemaker3.generate() for i in range(3)]) + '.png')
Ejemplo n.º 3
0
def createVideo(width, height, videoLength, frameRate, functionLength,
                singleWeight, numberWeight):

    rfunction = randFunction(functionLength, singleWeight, numberWeight)
    gfunction = randFunction(functionLength, singleWeight, numberWeight)
    bfunction = randFunction(functionLength, singleWeight, numberWeight)
    
    clProgramTemplate2 = replace(clProgramTemplate, '<WIDTH>', str(width))
    clProgramTemplate2 = replace(clProgramTemplate2, '<RFUNCTION>', rfunction)
    clProgramTemplate2 = replace(clProgramTemplate2, '<GFUNCTION>', gfunction)
    clProgramTemplate2 = replace(clProgramTemplate2, '<BFUNCTION>', bfunction)
    
    try:
        fourcc = cv2.cv.CV_FOURCC(*'XVID')
    except:
        fourcc = cv2.VideoWriter_fourcc(*'XVID')
    name = ' '.join([namemaker3.generate() for i in range(3)]) + '.avi'
    out = cv2.VideoWriter(directory+'/'+name, fourcc, frameRate, (width,height))
    if not out.isOpened():
        try:
            fourcc = cv2.cv.CV_FOURCC(*'MJPG')
        except:
            fourcc = cv2.VideoWriter_fourcc(*'MJPG')
        out = cv2.VideoWriter(directory+'/'+name, fourcc, frameRate, (width,height))
    
    for t in range(int(videoLength*frameRate)):
        clProgram = replace(clProgramTemplate2, '<FRAMENUMBER>', str(t))
        gpu.readFromString(clProgram)

        globalSize = (width*height*3,)

        output = np.zeros(globalSize, dtype=np.float32)
        
        gpu.setup([], output)

        output = gpu.run('AutoFrame', globalSize) % 255

        output.resize(height, width, 3, refcheck=False)

        output = output.astype(np.uint8)

        out.write(output[:, :, ::-1])
        
    out.release()
Ejemplo n.º 4
0
try:
    w = cap.get(cv2.CV_CAP_PROP_FRAME_WIDTH)
    h = cap.get(cv2.CV_CAP_PROP_FRAME_HEIGHT)
except:
    w = cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
    h = cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)
rfunction = randFunction(80, 1, 1)
gfunction = randFunction(80, 1, 1)
bfunction = randFunction(80, 1, 1)

if rec:
    try:
        fourcc = cv2.cv.CV_FOURCC(*'XVID')
    except:
        fourcc = cv2.VideoWriter_fourcc(*'XVID')
    out = cv2.VideoWriter(' '.join([namemaker3.generate() for i in range(3)]) + '.avi', fourcc, 10, (int(w),int(h)))


while True:
    t += 0.1
    ret, fr = cap.read()
    b, g, r = cv2.split(fr)
    r = r.astype(float)
    g = g.astype(float)
    b = b.astype(float)
    frame = r
    r = eval(rfunction)
    frame = g
    g = eval(gfunction)
    frame = b
    b = eval(bfunction)