Beispiel #1
0
def isOnKeyboard(x, y, z):
    " Check if the index tip is on the keyboard "

    if x == 0 and y == 0:
        return True

    # z = ax + by + c <=> Ax + By + Cz + D = 0, E = sqrt(A^2 + B^2 + C^2)
    # A, B, C, D, E, keyboardTop = vals.planeParam
    # a, b, c = -A/C, -B/C, -D/C

    # distance = np.abs((A*x + B*y + C*z + D) / E)
    # zi = a*x + b*y + c
    # if zi < z:
    #     # this point is above the plane
    #     distance = -distance

    distance = getPlaneDistance(vals.planeParam, x, y, z)
    keyboardTop = vals.planeParam[-1]
    if distance > keyboardTop*vals.sens:
        ret = False
    else:
        ret = True

    if vals.testIsOnKeyboard:
        vals.test_array_IsOnKeyboard.append([x,y,z,ret])
    
    #print distance, keyboardTop, ret
    return ret
Beispiel #2
0
def checkSwitchBox(x, y, z):
    " Check if the finger is in valid height(inside swithch box)"
    distance = getPlaneDistance(vals.planeParam, x, y, z)
    upper, lower = vals.switchBoxParam

    if distance >= lower and distance <= upper:
        vals.inSwitchBox = True
    else:
        vals.inSwitchBox = False
Beispiel #3
0
def myIsOnKeyboard(x,y,z):
    " Check if the index tip is on the keyboard "
    if x == 0 and y == 0:
        return True
    distance = getPlaneDistance(vals.planeParam, x, y, z)
    keyboardTop = vals.planeParam[-1]
    if distance > keyboardTop*vals.sens:
        ret = False
    else:
        ret = True

    if vals.testIsOnKeyboard:
        vals.test_my_array_IsOnKeyboard.append([x,y,z,ret])
    return ret
Beispiel #4
0
def drawAllRecording(screen, rpt, rpt2, tipThumb,tipThumb2, kThumb,kThumb2, tipIndex,tipIndex2,kIndex,kIndex2,averageX,averageY,averageX2,averageY2,myfont, calibFont,depthFont):
#     screen.fill(vals.black)
    if not vals.testTypeFlag:
    # Normal Recording Mode
        mouseLabel=myfont.render("Mouse:"+" "+str(vals.mouseModeValue) ,1,(255,255,255))
        screen.blit(mouseLabel,(0,80))
        clickLabel=myfont.render("Click:"+" "+str(vals.clickValue) ,1,(255,255,255))
        screen.blit(clickLabel,(0,95))        

        Calib1=calibFont.render("tipThumb:"+str(int(vals.depthBuff[0].mean())),1,vals.white)
        screen.blit(Calib1,(0,115))

        Calib2=calibFont.render("kThumb:"+str(int(vals.depthBuff[1].mean())),1,vals.white)
        screen.blit(Calib2,(0,135))

        Calib3=calibFont.render("tipIndex:"+str(int(vals.depthBuff[2].mean())),1,vals.white)
        screen.blit(Calib3,(0,155))
        
        Calib4=calibFont.render("kIndex:"+str(int(vals.depthBuff[3].mean())),1,vals.white)
        screen.blit(Calib4,(0,175))

        #tipDistance=calibFont.render("Switch-Distance:"+str(int(vals.tipDistance)),1,vals.white)
        #screen.blit(tipDistance,(0,205))

        #clickDistance=calibFont.render("Click-Distance:"+str(int(vals.clickDistance)),1,vals.white)
        #screen.blit(clickDistance,(0,235))
        x,y = rpt[tipIndex][0], rpt[tipIndex][1]
        z = np.mean(fun.smooth(vals.depthBuff[2].data, window_len = vals.depthBuff[2].size()))

        distance = getPlaneDistance(vals.planeParam, x, y, z)
        keyboardTop = vals.planeParam[-1]

        tipDistance=calibFont.render("Distance:"+str((distance)),1,vals.white)
        screen.blit(tipDistance,(0,205))

        clickDistance=calibFont.render("Keyboard Top:"+str((keyboardTop)),1,vals.white)
        screen.blit(clickDistance,(0,235))




        distance3D=calibFont.render("3D-Distance:"+str(int(vals.dist3D)),1,vals.white)
        screen.blit(distance3D,(0,255))

        box3D=calibFont.render(str(int(vals.boxLimit)),1,vals.white)
        screen.blit(box3D,(0,285))

#Circles to check on mode switching
        # if doDepth.checkAllInBox(): # Used to log data
        if vals.inSwitchBox:
            pygame.draw.circle(screen, vals.green, (10,325),10)
        else:
            pygame.draw.circle(screen, vals.red, (10,325),10)

        inBox=calibFont.render("in 3dBox",1,vals.white)
        screen.blit(inBox,(20,325))

        vals.inrange, vals.LED1,vals.LED2,vals.LED3,vals.LED4=checkingInRange.rangeChecker(vals.rptList, vals.LED1, vals.LED2,vals.LED3,vals.LED4)
        if (vals.inrange==1):
            pygame.draw.circle(screen, vals.green, (10,345),10)
        else:
            pygame.draw.circle(screen, vals.red, (10,345),10)
        
        inBox=calibFont.render("inrange",1,vals.white)
        screen.blit(inBox,(20,345))

        if (not vals.mouseSwitched_flg): # Used to log data
            pygame.draw.circle(screen, vals.green, (10,365),10)
        else:
            pygame.draw.circle(screen, vals.red, (10,365),10)
        
        inBox=calibFont.render("open tips",1,vals.white)
        screen.blit(inBox,(20,365))

        # Show window size which is used to control the sensitivity
        windowSize = calibFont.render('window size X:{} Y:{}'.format(str(vals.windowX), str(vals.windowY)), 1, vals.white)
        screen.blit(windowSize, (0, 400))

        # Show the buffer size which is modified by the speed in the new feature(shift+f to turn on/off)
        if vals.featureFlag:
            buffSize = calibFont.render('current buffer size: {}'.format(str(vals.buff[0].size())), 1, vals.white)
        else:
            buffSize = calibFont.render('default buffer size: {}'.format(str(vals.defaultBuffSize)), 1, vals.white)
        screen.blit(buffSize, (0, 420))

        # Show the depth of the four LED : 440, 460, 480, 500
        ledDepthKey = ['tipThumb: ', 'knuThumb: ', 'tipIndex: ', 'knuIndex: ']
        for i in range(len(ledDepthKey)):
            ledDepth = calibFont.render(ledDepthKey[i] + str(vals.depthBuff[i].back()), 1, vals.white)
            screen.blit(ledDepth, (0, 440 + i * 20))

        if vals.relativeFlag:
            controlMode = calibFont.render('Relative Mode', 1, vals.white)
            screen.blit(controlMode, (0, 520))

            onKeyboard = calibFont.render('Keyboard Test: ' + str(vals.onKeyboardFlag), 1, vals.white)
            screen.blit(onKeyboard, (0, 540))
        else:
            controlMode = calibFont.render('Absolute Mode', 1, vals.white)
            screen.blit(controlMode, (0, 520))

        rawXY = calibFont.render('Raw X:{}, Y:{}'.format(rpt[tipIndex][0], rpt[tipIndex][1]), 1, vals.white)
        screen.blit(rawXY, (0, 560))

        traceXY = calibFont.render('Mouse X:{}, Y:{}'.format(int(vals.traceX), int(vals.traceY)), 1, vals.white)
        screen.blit(traceXY, (0, 580))

        smoothTipIndex = np.mean(fun.smooth(vals.depthBuff[2].data, window_len = vals.depthBuff[2].size()))
        distance = getPlaneDistance(vals.planeParam, rpt[tipIndex][0], rpt[tipIndex][1], smoothTipIndex)
        tipIndexDepth = calibFont.render('Tip Index Depth: {}'.format(distance), 1, vals.white)
        screen.blit(tipIndexDepth, (0, 600))

    #main circles
        pygame.draw.circle(screen, vals.red, (rpt[tipIndex][0]/3,rpt[tipIndex][1]/3),10)
        pygame.draw.circle(screen, vals.blue, (rpt[kIndex][0]/3,rpt[kIndex][1]/3),10)
        pygame.draw.circle(screen, vals.green, (rpt[tipThumb][0]/3,rpt[tipThumb][1]/3),10)
        pygame.draw.circle(screen, vals.white, (rpt[kThumb][0]/3,rpt[kThumb][1]/3),10)

        pygame.draw.circle(screen, vals.gray, (averageX/3,averageY/3),13)
        pygame.draw.circle(screen, vals.gray, (averageX2/3,averageY2/3),13)

        pygame.draw.circle(screen, vals.red, (rpt2[tipIndex2][0]/3,rpt2[tipIndex2][1]/3),10)
        pygame.draw.circle(screen, vals.blue, (rpt2[kIndex2][0]/3,rpt2[kIndex2][1]/3),10)
        pygame.draw.circle(screen, vals.green, (rpt2[tipThumb2][0]/3,rpt2[tipThumb2][1]/3),10)
        pygame.draw.circle(screen, vals.white, (rpt2[kThumb2][0]/3,rpt2[kThumb2][1]/3),10)

    #GUI for depth
        # pygame.draw.rect(screen, vals.gray, (500,0,1500,1500))
        depthGUILeft = int(vals.width * 0.35)
        depthGUITop = int(vals.height * 0.05)
        depthGUIWidth = int(vals.width * 0.45) - depthGUILeft
        depthGUIHeight = int(vals.height * 0.95) - depthGUITop
        pygame.draw.rect(screen, vals.gray, (depthGUILeft, depthGUITop, depthGUIWidth, depthGUIHeight))
        
        # 0left--1startPos--2green--3white--4red--5blue--6endPos--7label--8right
        objXPos = np.linspace(depthGUILeft, depthGUILeft + depthGUIWidth, 9)
        objXPos = [int(x) for x in objXPos]
        #Creating the lines
        for i in xrange(11):
            offsetY = 75
            startPos = (objXPos[1], offsetY + i*30)      # was 550
            endPos = (objXPos[6], offsetY + i*30)      # was 650 
            pygame.draw.line(screen, vals.black, startPos, endPos)
            depthLabel = depthFont.render( str(5*i), 1, vals.black)
            screen.blit(depthLabel, (objXPos[7], offsetY + i*30))
        #Depth circles. Was 560, 580, 600, 620
        pygame.draw.circle(screen, vals.green, (objXPos[2], int(75 + vals.depthBuff[0].mean()*6)), 10) #tipThumb
        pygame.draw.circle(screen, vals.white, (objXPos[3], int(75 + vals.depthBuff[1].mean()*6)), 10) #kThumb
        pygame.draw.circle(screen, vals.red, (objXPos[4], int(75 + vals.depthBuff[2].mean()*6)), 10) #tipindex
        pygame.draw.circle(screen, vals.blue, (objXPos[5], int(75 + vals.depthBuff[3].mean()*6)), 10)#kIndex

    #The gesture bounds
        pygame.draw.line(screen,vals.red, (vals.gestureLeftThreshHold/3,0),(vals.gestureLeftThreshHold/3,800))
        pygame.draw.line(screen,vals.blue, (0,vals.gestureDownThreshHold/3),(10000,vals.gestureDownThreshHold/3))
        pygame.draw.line(screen,vals.yellow, (0,vals.gestureUpThreshHold/3),(10000,vals.gestureUpThreshHold/3))
    #Mouses mode drawing
        if vals.mouse_flg:
            MouseKeyboard=myfont.render( "Mouse mode",1,(255,255,255))
        else:
            MouseKeyboard=myfont.render( "Keyboard mode",1,(255,255,255))
        screen.blit(MouseKeyboard,(0,50))

        #input rectangle
        pygame.draw.line(screen,vals.white, (vals.inputX1/3,vals.inputY1/3), (vals.inputX2/3,vals.inputY1/3))
        pygame.draw.line(screen,vals.white, (vals.inputX2/3,vals.inputY1/3), (vals.inputX2/3,vals.inputY2/3))
        pygame.draw.line(screen,vals.white, (vals.inputX2/3,vals.inputY2/3), (vals.inputX1/3,vals.inputY2/3))
        pygame.draw.line(screen,vals.white, (vals.inputX1/3,vals.inputY2/3), (vals.inputX1/3,vals.inputY1/3))
        
    else:
    # Testing Recording Mode: Show article text.
    # I canceled the text input area.

        testFont = 'textFiles/MonospaceTypewriter.ttf'
        # Text GUI on the left: show the text
        
        if vals.textContent == '':
        # Read from file        
            try:
                tcf = open(vals.textContentFile, 'r')
                vals.textContent = tcf.read()
                tcf.close()

                print vals.textContent
            except:
                print 'Error: Invalid type content file.'

        
        textGUILeft = int(vals.width * 0.05)
        textGUITop = int(vals.height * 0.05)
        textGUIWidth = int(vals.width * 0.45) - textGUILeft
        textGUIHeight = int(vals.height * 0.95) - textGUITop
        pygame.draw.rect(screen, vals.white, (textGUILeft, textGUITop, textGUIWidth, textGUIHeight))

        if vals.textGUI == None:
            textFontSize = 20
            textBorder = 10

            vals.textGUI = Reader(unicode(vals.textContent.expandtabs(4), 'utf8'), (textGUILeft + textBorder, textGUITop + textBorder), \
                textGUIWidth - 2 * textBorder, textFontSize, height = textGUIHeight - 2 * textBorder, \
                font = testFont, fgcolor = (0, 0, 0), hlcolor = (255,10,150,100), split = True)

        vals.textGUI.show()

        '''