Exemplo n.º 1
0
def colorsChosen():
    kk = [5, 6, 7]
    for k in range(0, len(kk)):
        if colorK == k:
            blinked.switchColor('b', [kk[k]])
        else:

            blinked.switchColor('r', [kk[k]])
Exemplo n.º 2
0
    def depthAcq(self, dev, data, timestamp):

        blinked.switchColor('r', [3])

        depth = np.float32(data)
        depth[depth > self.maxDepth] = np.nan
        if np.isnan(depth).all() or len(depth[~np.isnan(depth)]) < self.nMin:
            print('all nan')
        else:

            #depthMin = np.min(depth[~np.isnan(depth)])
            #depthMax = np.max(depth[~np.isnan(depth)])

            #self.frames.append(1-(depth-depthMin)/(depthMax-depthMin))
            self.frames.append(depth)
        blinked.switchColor('g', [3])
Exemplo n.º 3
0
    def backAcq(self, dev, data, timestamp):

        blinked.switchColor('r', [3])
        self.background.append(np.float32(data))

        blinked.switchColor('g', [3])
Exemplo n.º 4
0
def main():

    mouseThread = threading.Thread(target=mouseListener)
    mouseThread.daemon = True
    mouseThread.start()
    draw = drawer.Drawer()
    draw.penInvert()
    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.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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def main():
    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(10)
        kinect.start()
        kinect.getDepthFrames(nFrames=40, delay=.01, maxDepth=2049)
        kinect.stop()
        blinked.switchColor('c', [1])
        kinect.backgroundSubstract(blur=True, level=20)
        dX, dY, angle, angleZ = kinect.derivateFrames()
    except Exception as e:
        print(traceback.format_exc())
        noProblem = False

    draw = drawer.Drawer(output=False)
    switchColor(2)
    print('---Switch is strating')
    #intializeDrawer()
    flip = False

    z = kinect.frames[6]
    A = angle[6]
    idx = [6, 7, 8]
    nLines = 200
    size = 0
    X = []
    X2 = []
    scale = 70
    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])
    rounder = .5
    speed = 2 * rounder

    rounder2 = 3 * rounder
    if speed < rounder:
        speed = rounder

    try:
        for j in range(0, 64):
            X3 = []
            blinked.progressColor(j / 10, 'v', 'y', [4])
            nLines = 200  #75*(3*l+j+1)
            kFrames = random.randint(0, len(angle) - 1)
            z = kinect.frames[kFrames]
            A = angle[kFrames]
            dist = random.uniform((j - 8 * math.floor(j / 8)), 1 +
                                  (j - 8 * math.floor(j / 8))) * 25
            offsetX = 5 + math.floor(j / 8) * 10
            offsetY = 5 + dist
            print('offset : ' + str((offsetX, offsetY)))
            #offsetY = 5+j*27
            #offsetX = 5
            rounder = .5
            speed = 2 * rounder

            rounder2 = 3 * rounder
            if speed < rounder:
                speed = rounder
            for k in range(0, nLines):
                blinked.progressColor(k / nLines, 'v', 'y', [5])
                size = 0
                while (size == 0):
                    xLines = []
                    yLines = []

                    size = 0
                    xChecking = True
                    while xChecking:
                        kx = random.randint(0, 639)
                        ky = random.randint(0, 479)
                        x, y = scaler(kx,
                                      ky,
                                      scale=scale,
                                      offsetX=offsetX,
                                      offsetY=offsetY)
                        x = round(x + (.5 - random.random()) * xu,
                                  rounder / 2.0)
                        y = round(y + (.5 - random.random()) * yu,
                                  rounder / 2.0)
                        x2 = round(x, rounder2)
                        y2 = round(y, rounder2)
                        zTest = z[ky, kx]
                        Atest = A[ky, kx]
                        if (x2, y2) not in X2:
                            xChecking = False
                    running = True
                    if np.isnan(zTest) or np.isnan(Atest):
                        running = False
                    while running:
                        #print('x  : '+str((x,y)))
                        #print('k  : '+str((kx,ky)))
                        xLines.append(y)
                        yLines.append(x)
                        X.append((x, y))
                        X3.append((x2, y2))
                        dx = round(x + speed * np.cos(A[ky, kx]), rounder)
                        dy = round(y + speed * np.sin(A[ky, kx]), rounder)
                        dx2 = round(x + speed * np.cos(A[ky, kx]), rounder2)
                        dy2 = round(y + speed * np.sin(A[ky, kx]), rounder2)

                        dxk, dyk = scaler(dx,
                                          dy,
                                          scale=scale,
                                          offsetX=offsetX,
                                          offsetY=offsetY,
                                          invert=True)

                        if (dxk > -1) and (dxk < 640) and (dyk > -1) and (
                                dyk < 480) and size < 100 and (
                                    dx, dy) not in X and (dx2, dy2) not in X2:
                            x = dx
                            y = dy
                            kx = dxk
                            ky = dyk
                            zTest = z[ky, kx]
                            Atest = A[ky, kx]
                            size += speed
                            if np.isnan(zTest) or np.isnan(Atest):
                                running = False
                        else:
                            running = False

                print('new Line : ' + str(k))
                draw.lines(xLines, yLines)
            for x3 in X3:
                if x3 not in X2:
                    X2.append(x3)
        #line(50,50,length=50,angle=0)
        #line(50,50,length=55,angle=.1)
        #line(50,50,length=60,angle=.2)
        #line(50,50,length=65,angle=.4)
        #line(50,50,length=70,angle=.8)
        #line(50,50,length=75,angle=1.6)
        #for k in range(0,10):
        #draw.square(100,70,10*k/2.0,noise = 3,speed=500)
        #for j in range(0,10):
        #square((k+1)*11,(j+1)*11,10,angle=math.pi*(k*j)/(400))
        #draw.circle((k+1)*11,(j+1)*11,k+j)
    except Exception as e:
        print(traceback.format_exc())
        draw.toPosition(0, 0)
    draw.closeDrawer()
    switchColor(1)
Exemplo n.º 7
0
def main():
    mouseThread = threading.Thread(target = mouseListener)
    mouseThread.daemon = True
    mouseThread.start()


    draw = drawer.Drawer(dx=450,dy=230)    
    draw.penInvert()
    draw.penUp()
    draw.toPosition(0,0)
    set_brightness(.05)
    blinked.switchColor('g',[0])
    #draw.squareCorner(0,0,heightPaper,widthPaper,polar=True,xOffset = -heightPaper/2.0,yOffset =20)
    #draw.lines([0,0,heightPaper,heightPaper],[0,widthPaper,widthPaper,0],xOffset = -heightPaper/2.0,yOffset =20,polar = True)
    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,12):
            time.sleep(.8)
            blinked.switchColor('r',[7])
            time.sleep(.2)
            blinked.switchColor('k',[7])

        for k in range(0,10):
            time.sleep(.35)
            blinked.switchColor('o',[7])
            time.sleep(.15)
            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 = 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])

    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,1200,nx)

    sp = np.linspace(.2,1.0,nx)
    crop = np.linspace(0,.6,nx)
    speedRange = np.linspace(1,10,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 = 200,scale = scale,A0=0,\
                    offsetX = offsetX,offsetY=offsetY,figurePosition = X2,distanceLine = .1  ,speed = .1 ,cropFactor=0,resolution=.05)
            

    except Exception as e: 
        print(traceback.format_exc())
        draw.toPosition(0,0)
    draw.closeDrawer()    
    switchColor(1)
Exemplo n.º 8
0
def main():
    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(120)
        kinect.start()
        kinect.getDepthFrames(nFrames=30, delay=.01, maxDepth=2049)
        kinect.stop()
        blinked.switchColor('c', [1])
        kinect.backgroundSubstract(blur=True, level=20)
        dX, dY, angle, angleZ = kinect.derivateFrames()
    except Exception as e:
        print(traceback.format_exc())
        noProblem = False

    draw = drawer.Drawer(output=False)
    switchColor(2)
    print('---Switch is strating')
    #intializeDrawer()
    flip = False

    speed = 3
    z = kinect.frames[6]
    A = angle[6]
    Az = angleZ[6]
    idx = [6, 7, 8]
    nLines = 200
    size = 0
    X = []
    scale = 200
    xu, yu = scaler(1, 1, scale=scale, offsetX=0, offsetY=0)
    offsetA = np.pi / 3  #[[-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])
    try:
        for l in range(0, 1):
            for j in range(0, 1):
                nLines = 1000000  #75*(3*l+j+1)

                #z = frames[j]
                #A = angle[j]
                offsetX = 5 + j * 80
                offsetY = 5 + l * 80
                for k in range(0, nLines):
                    size = 0
                    while (size == 0):
                        print('new Line : ' + str(k))
                        xLines = []
                        yLines = []

                        size = 0
                        kx = random.randint(0, 639)
                        ky = random.randint(0, 479)
                        x, y = scaler(kx,
                                      ky,
                                      scale=scale,
                                      offsetX=offsetX,
                                      offsetY=offsetY)
                        x = round(x + (.5 - random.random()) * xu, .1)
                        y = round(y + (.5 - random.random()) * yu, .1)
                        zTest = z[ky, kx]
                        Atest = A[ky, kx]
                        Aztest = Az[ky, kx]
                        running = True
                        if np.isnan(zTest) or np.isnan(Atest) or np.isnan(
                                Aztest):
                            running = False
                        if running:
                            R = random.random() * (
                                speed * (1 + np.sin(A[ky, kx] + offsetA)) *
                                np.sin(Az[ky, kx]))
                            xLines.append(round(x - R * np.cos(A[ky, kx]), .1))
                            xLines.append(round(x + R * np.cos(A[ky, kx]), .1))
                            yLines.append(round(y - R * np.sin(A[ky, kx]), .1))
                            yLines.append(round(y + R * np.sin(A[ky, kx]), .1))

                            draw.lines(xLines, yLines)
                            size += 1

        #line(50,50,length=50,angle=0)
        #line(50,50,length=55,angle=.1)
        #line(50,50,length=60,angle=.2)
        #line(50,50,length=65,angle=.4)
        #line(50,50,length=70,angle=.8)
        #line(50,50,length=75,angle=1.6)
        #for k in range(0,10):
        #draw.square(100,70,10*k/2.0,noise = 3,speed=500)
        #for j in range(0,10):
        #square((k+1)*11,(j+1)*11,10,angle=math.pi*(k*j)/(400))
        #draw.circle((k+1)*11,(j+1)*11,k+j)
    except Exception as e:
        print(traceback.format_exc())
        draw.toPosition(0, 0)
    draw.closeDrawer()
    switchColor(1)
Exemplo n.º 9
0
def main():
    global speedList
    global speedMinList
    global A0List
    mouseThread = threading.Thread(target=mouseListener)
    mouseThread.daemon = True
    mouseThread.start()

    draw = drawer.Drawer(dx=350, dy=230)
    draw.penInvert(True)
    draw.penUp()
    draw.toPosition(0, 0)
    set_brightness(.05)
    blinked.switchColor('g', [0])
    #draw.squareCorner(0,0,heightPaper,widthPaper,polar=True,xOffset = -heightPaper/2.0,yOffset =20)
    #draw.lines([0,0,heightPaper,heightPaper],[0,widthPaper,widthPaper,0],xOffset = -heightPaper/2.0,yOffset =20,polar = True)
    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,12):
        #    time.sleep(.8)
        #    blinked.switchColor('r',[7])
        #    time.sleep(.2)
        #    blinked.switchColor('k',[7])

        for k in range(0, 10):
            time.sleep(.35)
            blinked.switchColor('o', [7])
            time.sleep(.15)
            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=1, delay=.01, maxDepth=2049)
        kinect.stop()
        blinked.switchColor('c', [1])
        kinect.backgroundSubstract(blur=True, level=5)
        dX, dY, angle, angleZ = kinect.derivateFrames()
    except Exception as e:
        print(traceback.format_exc())

    colorsChosen()
    nLines = 400
    size = 0

    X2 = []
    nx0 = np.int(len(kinect.frames) / 2)
    scale, offsetX, offsetY = spacer(kinect.frames)
    print("scale : " + str(scale))

    print("offsetX  : " + str(offsetX))
    print("offsetY : " + str(offsetY))

    xu, yu = scaler(1, 1, scale=scale, offsetX=0, offsetY=0)

    blinked.switchColor('a', [0])
    blinked.switchColor('g', [1])

    offsetX0 = 5 - offsetY
    offsetY0 = 5 - offsetX

    for k in range(0, nColors):
        A0List.append(2 * np.pi * np.random.rand())
        speedMinList.append(1 + 10 * (1 - np.random.power(6)))
        speedList.append(10 + 10 * (1 - np.random.power(3)))
    A1 = 2 * np.pi * np.random.rand()
    try:

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

        offsetX = offsetX0
        offsetY = offsetY0
        #print("offset : "+str((offsetX,offsetY)))
        X2 = drawing(0,kinect.frames,angle,angleZ,draw,nLines = 40000,scale = scale,A0=A0List[colorK],A1=A1,noise = 0,\
                offsetX = offsetX,offsetY=offsetY,figurePosition = X2,distanceLine = .1  ,speed = speedList[colorK] ,speedMin = speedMinList[colorK],cropFactor=0,resolution=.05)

    except Exception as e:
        print(traceback.format_exc())
        draw.toPosition(0, 0)
    draw.closeDrawer()
    switchColor(1)
Exemplo n.º 10
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)
Exemplo n.º 11
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)