Esempio n. 1
0
    def getDepthFrames(self, delay=.01, nFrames=10, maxDepth=2049):
        self.nFrames = nFrames
        self.delay = delay
        self.maxDepth = maxDepth
        freenect.start_depth(self.dev)
        freenect.set_depth_callback(self.dev, self.depthAcq)
        self.frames = []
        previousProgress = -1
        while len(self.frames) < nFrames:
            progress = len(self.frames) / nFrames
            if progress > previousProgress:
                blinked.progressColor(progress, 'c', 'o', pix=[2])
                previousProgress = progress

            freenect.process_events(self.ctx)
            time.sleep(delay)
Esempio n. 2
0
    def backGroundSubstractor(self, nFrames=100):
        self.nFrames = nFrames

        self.fgbg = cv2.createBackgroundSubtractorMOG2()
        freenect.start_depth(self.dev)
        freenect.set_depth_callback(self.dev, self.backAcq)
        self.background = []
        previousProgress = -1
        while len(self.background) < nFrames:

            freenect.process_events(self.ctx)
            time.sleep(.01)
            progress = len(self.background) / nFrames
            if progress > previousProgress:
                blinked.progressColor(progress, 'c', 'o', pix=[2])
                previousProgress = progress
        for frame in self.background:
            fgmask = self.fgbg.apply(frame, learningRate=0.01)
        self.background = []
Esempio n. 3
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)
Esempio 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)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
def drawing(kFrames,
            frames,
            angle,
            angleZ,
            draw,
            nLines=400,
            scale=70,
            A0=0,
            A1=0,
            resolution=.1,
            speed=.4,
            speedMin=5,
            distanceLine=.8,
            distanceFigure=5.0,
            noise=0,
            offsetX=0,
            offsetY=0,
            figurePosition=[],
            cropFactor=.3):
    kFrames = np.int(kFrames)

    imagePosition = []
    repetitionPosition = []

    z = frames[kFrames]
    A = angle[kFrames] + A0
    AZ = angleZ[kFrames]

    xL = []
    yL = []

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

    #if speed<distanceLine:
    #speed = distanceLine
    widthScanMin = 639
    widthStep = -1
    for k in range(0, nLines):

        while (pause):
            time.sleep(1)
            if A0 != A0List[colorK]:
                speedMin = speedMinList[colorK]
                speed = speedList[colorK]
                A0 = A0List[colorK]
                print('--- --- ---')
                print("A0 : " + str(A0))
                print("speed : " + str(speed))
                print("speedMin : " + str(speedMin))
                print('--- --- ---')

        if k % 100 == 0:
            print("number of Lines : " + str(k))
        blinked.progressColor(k / nLines, 'v', 'y', [4])
        size = 0
        trial = 0
        while (size == 0):
            linePosition = []
            trial += 1
            xLines = []
            yLines = []

            size = 0
            xChecking = True
            t0 = time.time()

            while xChecking:
                widthScanMin += widthStep
                widthScanMax = widthScanMin + 1
                if widthScanMin < 0:
                    widthStep = -widthStep
                    widthScanMin = 0
                    widthScanMax = 10
                if widthScanMax > 639:
                    widthStep = -widthStep
                    widthScanMax = 639
                    widthScanMin = 629

                kx0 = random.randint(widthScanMin, widthScanMax)
                ky0 = random.randint(0, 479)

                x, y = scaler(kx0,
                              ky0,
                              scale=scale,
                              offsetX=offsetX,
                              offsetY=offsetY)
                x0 = round(x + (.5 - random.random()) * xu, resolution / 2.0)
                y0 = round(y + (.5 - random.random()) * yu, resolution / 2.0)
                x = x0
                y = y0
                kx = kx0
                ky = ky0
                x1 = round(x, distanceLine)
                y1 = round(y, distanceLine)
                zTest = z[ky, kx]
                Atest = A[ky, kx]
                AZtest = AZ[ky, kx]

                if not np.isnan(zTest) and not np.isnan(
                        Atest) and not np.isnan(AZtest):
                    xChecking = False

            running = True
            t0 = time.time()

            linePosition.append((round(x, resolution), round(y, resolution)))

            angleD = A[ky, kx] + noise * (.5 - random.random())
            speedZ = speedMin + speed * (
                1 + np.cos(angleD + A0 + A1)) * np.cos(AZ[ky, kx])
            dxS = speedZ * (np.cos(angleD))
            dyS = speedZ * (np.sin(angleD))

            dx = round(dxS, resolution)
            dy = round(dyS, resolution)
            dx1 = round(dx, distanceLine)
            dy1 = round(dy, distanceLine)
            dx2 = round(dx, distanceFigure)
            dy2 = round(dy, distanceFigure)
            dxk, dyk = scaler(dx,
                              dy,
                              scale=scale,
                              offsetX=offsetX,
                              offsetY=offsetY,
                              invert=True)

            xLines.append(y + dy)
            yLines.append(heightPaper - (x + dx))
            xLines.append(y - dy)
            yLines.append(heightPaper - (x - dx))
            size = 2

        if size > 1:

            draw.lines(xLines,
                       yLines,
                       xOffset=-widthPaper / 2.0,
                       yOffset=20,
                       polar=True,
                       speed=750,
                       smooth=True)

    return figurePosition
Esempio n. 8
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)
Esempio n. 9
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)