Ejemplo n.º 1
0
def main():
    draw = drawer.DrawerNet()
    draw.penUp()
    draw.toPosition(0, 0)
    set_brightness(.05)
    blinked.switchColor('g', [0])
    try:
        kinect = kinecter.kinect()
        blinked.switchColor('o', [1])
        kinect.start()
        kinect.backGroundSubstractor(nFrames=100)
        kinect.stop()
        blinked.switchColor('p', [1])
        time.sleep(20)
        kinect.start()
        kinect.getDepthFrames(nFrames=40, delay=.01, maxDepth=2049)
        kinect.stop()
        blinked.switchColor('c', [1])
        kinect.backgroundSubstract(blur=True, level=15)
        dX, dY, angle, angleZ = kinect.derivateFrames()
    except Exception as e:
        print(traceback.format_exc())

    blinked.switchColor('g', [5, 6])
    draw = drawer.DrawerNet()
    draw.penUp()
    draw.squareCorner(0, 0, widthPaper, heightPaper)
    blinked.switchColor('g', [5, 6, 7])
    nLines = 400
    size = 0

    X2 = []
    nx0 = np.int(len(kinect.frames) / 2)
    scale, nx, dist, offsetX, offsetY = spacer(kinect.frames, nx0 - 1, nx0)
    print("scale : " + str(scale))
    print("n     : " + str(nx))
    print("offsetX  : " + str(offsetX))
    print("offsetY : " + str(offsetY))
    print("dist : " + str(dist))
    xu, yu = scaler(1, 1, scale=scale, offsetX=0, offsetY=0)
    offsetA = [[-np.pi / 3, 0, np.pi / 3],
               [-2 * np.pi / 3, np.pi, 2 * np.pi / 3]]
    blinked.switchColor('a', [0])
    blinked.switchColor('g', [1])

    offsetX0 = 5 - offsetY
    offsetY0 = 5 - offsetX

    d = np.linspace(.1, 4, nx)
    nL = np.linspace(250, 600, nx)

    sp = np.linspace(.2, 1.0, nx)
    crop = np.linspace(0, .6, nx)

    try:
        for j in range(0, nx):

            blinked.progressColor(j / nx, 'v', 'y', [4])

            kFrames = j + nx0
            #dist = random.uniform((j-nx*math.floor(j/nx)),1+(j-nx*math.floor(j/nx)))*5
            #

            offsetX = offsetX0
            offsetY = offsetY0 + j * dist

            #print("offset : "+str((offsetX,offsetY)))
            X2 = drawing(kFrames,kinect.frames,angle,angleZ,draw,nLines = 300,scale = scale,A0=0,\
                    offsetX = offsetX,offsetY=offsetY,figurePosition = X2,distanceLine = .2  ,speed = .2,cropFactor=crop[j])

    except Exception as e:
        print(traceback.format_exc())
        draw.toPosition(0, 0)
    draw.closeDrawer()
    switchColor(1)
Ejemplo n.º 2
0
def main():

    mouseThread = threading.Thread(target = mouseListener)
    mouseThread.daemon = True
    mouseThread.start()
    draw = drawer.DrawerNet()    
    draw.penUp()
    draw.toPosition(0,0)
    set_brightness(.05)
    blinked.switchColor('g',[0])


    while(not backgroundSub):
        time.sleep(.1)
    try:
        kinect = kinecter.kinect()
        blinked.switchColor('o',[1])
        kinect.start()
        kinect.backGroundSubstractor(nFrames=100)
        kinect.stop()
        blinked.switchColor('p',[1])
        while(not drawLoop):
            time.sleep(1)
        for k in range(0,6):
            time.sleep(.4)
            blinked.switchColor('r',[7])
            time.sleep(.2)
            blinked.switchColor('k',[7])

        for k in range(0,5):
            time.sleep(.3)
            blinked.switchColor('o',[7])
            time.sleep(.1)
            blinked.switchColor('k',[7])
        
        for k in range(0,5):
            deltaT = .3/((k+1))
            time.sleep(.9*deltaT)
            blinked.switchColor('g',[7])
            time.sleep(.1*deltaT)
            blinked.switchColor('k',[7])
        kinect.start()
        kinect.getDepthFrames(nFrames = 100,delay=.01,maxDepth=2049)
        kinect.stop()
        blinked.switchColor('c',[1])
        kinect.backgroundSubstract(blur=True,level=15)
        dX,dY,angle,angleZ = kinect.derivateFrames()
    except Exception as e: 
        print(traceback.format_exc())
 

    blinked.switchColor('g',[5,6])
    draw = drawer.DrawerNet()    
    draw.penUp()
    #draw.squareCorner(0,0,widthPaper,heightPaper)
    blinked.switchColor('g',[5,6,7])
    nLines = 400
    size = 0

    nx0=0
    scale,nx,dist,offsetX,offsetY =  spacer(kinect.frames,nx0,100)
    print("scale : "+str(scale))
    print("n     : "+str(nx))
    print("offsetX  : "+str(offsetX))
    print("offsetY : "+str(offsetY))
    print("dist : "+str(dist))
    xu,yu = scaler(1,1,scale=scale,offsetX=0,offsetY=0)
    offsetA=[[-np.pi/3,0,np.pi/3],[-2*np.pi/3,np.pi,2*np.pi/3]]    
    blinked.switchColor('a',[0])
    blinked.switchColor('g',[1])




    offsetX0 = 1-offsetY
    offsetY0 = 1-offsetX


    if np.random.random()<.12:
        Nmin = np.random.randint(300,600)
        Nmax = np.random.randint(50,200)

        nL = np.linspace(Nmin,Nmax,nx,dtype = int)
        if random.random()<.5:
            nL = np.flip(nL) 
    else:
        nL = random.randint(250,350) * np.ones(nx, dtype=int)  


    if np.random.random()<.098:
        dMin =  .05 + .5*(1-np.random.power(5))
        dMax = 1+4*np.random.random()

        d = np.linspace(dMin,dMax,nx)
        if random.random()<.5:
            d = np.flip(d) 
    else:
        d = (.2 + (1-np.random.power(3))) * np.ones(nx)  
    

    if np.random.random()<.105:
        speedMin = .1 + .2*np.random.random()
        speedMax = .5 + np.random.random()

        speed = np.linspace(speedMin,speedMax,nx)
        if np.random.random()<.5:
            speed = np.flip(speed) 
    else:
        speed = (.1 + .1*np.random.random()) * np.ones(nx)      
    
    if np.random.random()<.106:
        cropMin = 0 + .1*np.random.random()
        cropMax = .1 + .4*np.random.random()

        crop = np.linspace(cropMin,cropMax,nx)
        if random.random()<.5:
            crop = np.flip(crop) 
    else:
        crop = ( .05*random.random()) * np.ones(nx)

    if np.random.random()<.085:
        noiseMin = (1-np.random.power(11))
        noiseMax = noiseMin + 1.0*np.random.random()

        noise = np.linspace(noiseMin,noiseMax,nx)
        if np.random.random()<.5:
            noise = np.flip(noise) 
    else:
        noise = (1-np.random.power(11)) * np.ones(nx)

    if np.random.random()<.19:
        colors = 2
    else:
        colors = 1
    A0=0
    X2 = []

    print("----- Parameters -----")
    print("-- Lines : " + str(nL) + "--" )
    print("-- dista : " + str(d) + "--")
    print("-- speed : " + str(speed) + "--" )
    print("-- crops : " + str(crop) + "--")
    print("-- noise : " + str(noise) + "--")
    print("-- color : " + str(colors) + "--")
    
    try:
        for l in range(0,colors):
            print("color : "+str(l))
            for j in range(0,nx):

                blinked.progressColor(j/nx,'v','y',[4])
                
                kFrames = j+nx0
                #dist = random.uniform((j-nx*math.floor(j/nx)),1+(j-nx*math.floor(j/nx)))*5
                #
                
                offsetX = offsetX0
                offsetY = offsetY0+j*dist

                #print("offset : "+str((offsetX,offsetY)))
                X2 = drawing(kFrames,kinect.frames,angle,angleZ,draw,nLines = nL[j],scale = scale,A0=A0,\
                        offsetX = offsetX,offsetY=offsetY,figurePosition = X2,distanceLine = d[l]  ,speed = speed[l],cropFactor=crop[l],\
                        noise = noise[l])
            if l==0:
                time.sleep(0)
                X2 = []
                A0=math.pi/2.0
            

    except Exception as e: 
        print(traceback.format_exc())
        draw.toPosition(0,0)
    draw.closeDrawer()    
    switchColor(1)
Ejemplo n.º 3
0
def main():
    global save
    mouseThread = threading.Thread(target=mouseListener)
    mouseThread.daemon = True
    mouseThread.start()

    draw = drawer.DrawerNet(2)

    draw.penUp()
    draw.toPosition(0, 0)
    set_brightness(.05)
    blinked.switchColor('g', [0])

    k0 = 0
    j0 = 0
    #while(not backgroundSub):
    #    time.sleep(.1)

    if os.path.isfile(savePath + "parameters.p"):
        dist = [0, 0]
        print("---- load --- -")
        k0, j0, nL, scale, A0, X2, d1, d2, speed, crop, noise, dist, nx, ny = loadState(
        )
        frames, angle, angleZ, offset = loadFrames()
        print("--- loaded -- -")

    else:
        if os.path.isfile(savePath + "frames.p"):
            dist = [0, 0]
            print("---- load --- -")
            frames, angle, angleZ, offset = loadFrames()
            print("--- loaded -- -")
        else:
            try:
                kinect = kinecter.kinect()
                blinked.switchColor('o', [1])
                kinect.start()
                kinect.backGroundSubstractor(nFrames=100)
                kinect.stop()
                blinked.switchColor('p', [1])
                while (not drawLoop):
                    time.sleep(1)
                for k in range(0, 6):
                    time.sleep(.4)
                    blinked.switchColor('r', [7])
                    time.sleep(.2)
                    blinked.switchColor('k', [7])

                for k in range(0, 5):
                    time.sleep(.3)
                    blinked.switchColor('o', [7])
                    time.sleep(.1)
                    blinked.switchColor('k', [7])

                for k in range(0, 5):
                    deltaT = .3 / ((k + 1))
                    time.sleep(.9 * deltaT)
                    blinked.switchColor('g', [7])
                    time.sleep(.1 * deltaT)
                    blinked.switchColor('k', [7])
                kinect.start()
                kinect.getDepthFrames(nFrames=50, delay=.01, maxDepth=2049)
                kinect.stop()
                blinked.switchColor('c', [1])
                kinect.backgroundSubstract(blur=True, level=15)
                dX, dY, angle, angleZ = kinect.derivateFrames()
                frames = kinect.frames
            except Exception as e:
                print(traceback.format_exc())

        blinked.switchColor('g', [5, 6])

        draw.penUp()
        #draw.squareCorner(0,0,widthPaper,heightPaper)
        blinked.switchColor('g', [5, 6, 7])
        nLines = 400
        size = 0

        scale, nx, ny, dist, offset = spacer(frames)
        print("scale : " + str(scale))
        print("n     : " + str(nx))

        print("dist : " + str(dist))
        xu, yu = scaler(1, 1, scale=scale, offsetX=0, offsetY=0)
        offsetA = [[-np.pi / 3, 0, np.pi / 3],
                   [-2 * np.pi / 3, np.pi, 2 * np.pi / 3]]
        blinked.switchColor('a', [0])
        blinked.switchColor('g', [1])

        #offsetX0 = 5-offsetY
        #offsetY0 = 5-offsetX

        nL = 30  #random.randint(80,100)

        d1 = .01  #+ (1-np.random.power(3)))

        d2 = 1  #+ (1-np.random.power(3)))

        speed = (.1 + .1 * np.random.random())

        crop = 0  #( .0*random.random())

        noise = 0  #.1*(1-np.random.power(11))

        nLStep = 1
        A0 = 0
        X2 = []

        print("----- Parameters -----")
        print("-- Lines : " + str(nL) + "--")
        print("-- dista : " + str(d1) + "--")
        print("-- speed : " + str(speed) + "--")
        print("-- crops : " + str(crop) + "--")
        print("-- noise : " + str(noise) + "--")

        saveState(0, 0, nL, scale, A0, X2, d1, d2, speed, crop, noise, dist,
                  nx, ny)
        saveFrames(frames, angle, angleZ, offset)

    try:
        for k in range(k0, ny):
            for j2 in range(j0, nx):
                while pause:

                    if save:
                        print("---- save -----")
                        saveState(k, j2, nL, scale, A0, X2, d1, d2, speed,
                                  crop, noise, dist, nx, ny)
                        save = False
                        draw.toPosition(0, 0)
                    time.sleep(1)

                if k % 2 == 0:
                    j = j2
                else:
                    j = nx - 1 - j2
                blinked.progressColor(((k * ny) + j) / (nx * ny), 'v', 'y',
                                      [4])

                kFrames = random.randint(0, len(frames) - 1)
                #dist = random.uniform((j-nx*math.floor(j/nx)),1+(j-nx*math.floor(j/nx)))*5
                #
                rInt = .2
                rMin = offset[kFrames][1] + np.max((0, (k - rInt) * dist[1]))
                rMax = -offset[kFrames][1] + np.min(
                    (heightPaper, (k + rInt) * dist[1]))
                offsetX = random.uniform(rMin, rMax)
                rMin = offset[kFrames][0] + np.max((0, (j - 1) * dist[0]))
                rMax = -offset[kFrames][0] + np.min(
                    (widthPaper, (j + 1) * dist[0]))
                offsetY = random.uniform(rMin, rMax)

                #print("offset : "+str((offsetX,offsetY)))
                X2 = drawing(kFrames,frames,angle,angleZ,draw,nLines = nL,scale = scale,A0=A0,\
                        offsetX = offsetX,offsetY=offsetY,figurePosition = X2,distanceLine = d1  ,distanceFigure=d2,speed = speed,cropFactor=crop,\
                        noise = noise,resolution = 0.1)

                while len(X2) > 500000:
                    del X2[0]
            j0 = 0

    except Exception as e:
        print(traceback.format_exc())
        draw.toPosition(0, 0)
    draw.closeDrawer()
    switchColor(1)
Ejemplo n.º 4
0
def main():
    mouseThread = threading.Thread(target = mouseListener)
    mouseThread.daemon = True
    mouseThread.start()

    draw = drawer.DrawerNet(2)

    draw.penUp()
    draw.toPosition(0,0)
    set_brightness(.05)
    blinked.switchColor('g',[0])

    while(not backgroundSub):
        time.sleep(.1)

    try:
        kinect = kinecter.kinect()
        blinked.switchColor('o',[1])
        kinect.start()
        kinect.backGroundSubstractor(nFrames=100)
        kinect.stop()
        blinked.switchColor('p',[1])
        while(not drawLoop):
            time.sleep(1)
        for k in range(0,6):
            time.sleep(.4)
            blinked.switchColor('r',[7])
            time.sleep(.2)
            blinked.switchColor('k',[7])

        for k in range(0,5):
            time.sleep(.3)
            blinked.switchColor('o',[7])
            time.sleep(.1)
            blinked.switchColor('k',[7])
        
        for k in range(0,5):
            deltaT = .3/((k+1))
            time.sleep(.9*deltaT)
            blinked.switchColor('g',[7])
            time.sleep(.1*deltaT)
            blinked.switchColor('k',[7])
        kinect.start()
        kinect.getDepthFrames(nFrames = 50,delay=.01,maxDepth=2049)
        kinect.stop()
        blinked.switchColor('c',[1])
        kinect.backgroundSubstract(blur=True,level=15)
        dX,dY,angle,angleZ = kinect.derivateFrames()
    except Exception as e: 
        print(traceback.format_exc())
 

    blinked.switchColor('g',[5,6])
  
    draw.penUp()
    #draw.squareCorner(0,0,widthPaper,heightPaper)
    blinked.switchColor('g',[5,6,7])
    nLines = 400
    size = 0


    scale,nx,ny,dist,offset =  spacer(kinect.frames)
    print("scale : "+str(scale))
    print("n     : "+str(nx))

    print("dist : "+str(dist))
    xu,yu = scaler(1,1,scale=scale,offsetX=0,offsetY=0)
    offsetA=[[-np.pi/3,0,np.pi/3],[-2*np.pi/3,np.pi,2*np.pi/3]]    
    blinked.switchColor('a',[0])
    blinked.switchColor('g',[1])




    #offsetX0 = 5-offsetY
    #offsetY0 = 5-offsetX


    nL = 55#random.randint(80,100) 


    d = .1 #+ (1-np.random.power(3)))   

    d2 = 1 #+ (1-np.random.power(3)))   
    

    speed = (.1 + .1*np.random.random())       
    
    crop = ( .0*random.random())

    noise = .1*(1-np.random.power(11))

    nLStep = 1
    A0=0
    X2 = [] 

    print("----- Parameters -----")
    print("-- Lines : " + str(nL) + "--" )
    print("-- dista : " + str(d) + "--")
    print("-- speed : " + str(speed) + "--" )
    print("-- crops : " + str(crop) + "--")
    print("-- noise : " + str(noise) + "--")
     
    try:
        for k in range(0,ny):
            for j2 in range(0,nx):
                if k%2==0:
                    j=j2
                else:
                    j=nx-1-j2
                blinked.progressColor(((k*ny)+j)/(nx*ny),'v','y',[4])
                
                kFrames = random.randint(0,len(kinect.frames)-1)
                #dist = random.uniform((j-nx*math.floor(j/nx)),1+(j-nx*math.floor(j/nx)))*5
                #
                offsetY = -9999
                offsetX = -9999
                while offsetY<offset[kFrames][0] or offsetY>widthPaper+offset[kFrames][0]:
                    offsetY = offset[kFrames][0]+j*dist[0]+random.uniform(-dist[0],dist[0])

                while offsetX<offset[kFrames][1] or offsetX>heightPaper+offset[kFrames][1]:
                    offsetX = offset[kFrames][1]+k*dist[1]+0.2*random.uniform(-dist[1],dist[1])
               
                

                #print("offset : "+str((offsetX,offsetY)))
                X2 = drawing(kFrames,kinect.frames,angle,angleZ,draw,nLines = nL,scale = scale,A0=A0,\
                        offsetX = offsetX,offsetY=offsetY,figurePosition = X2,distanceLine = d  ,distanceFigure=d2,speed = speed,cropFactor=crop,\
                        noise = noise)
                
                while len(X2)>15000:
                    del X2[0]
                

    except Exception as e: 
        print(traceback.format_exc())
        draw.toPosition(0,0)
    draw.closeDrawer()    
    switchColor(1)