コード例 #1
0
def binaryMask(frame, x0, y0, width, height, flip, framecount, plot):
    global model, saveImg
    
    cv2.rectangle(frame, (x0,y0),(x0+width,y0+height),(0,255,0),1)
    #roi = cv2.UMat(frame[y0:y0+height, x0:x0+width])
    roi = frame[y0:y0+height, x0:x0+width]
    
    if flip:
        roi = cv2.flip(roi, 1)
    
    gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
    blur = cv2.GaussianBlur(gray,(5,5),2)
    
    th3 = cv2.adaptiveThreshold(blur,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,11,2)
    ret, res = cv2.threshold(th3, minValue, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
    res = cv2.resize(res, (40, 40))
    guess = ""
    
    if saveImg == True:
        saveROIImg(res, flip)

    guess = myNN.guessGesture(model, res)
    plot = np.zeros((512,512,3), np.uint8)
    plot = myNN.update(plot)

    return res, guess, plot
コード例 #2
0
ファイル: app.py プロジェクト: Interactics/tony-and-naeyo
def binaryMask(frame, x0, y0, width, height):

    global guessGesture, visualize, mod, lastgesture, saveImg

    cv2.rectangle(frame, (x0, y0), (x0 + width, y0 + height), (0, 255, 0), 1)
    roi = frame[y0:y0 + height, x0:x0 + width]

    gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
    blur = cv2.GaussianBlur(gray, (5, 5), 2)

    th3 = cv2.adaptiveThreshold(blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                cv2.THRESH_BINARY_INV, 11, 2)
    ret, res = cv2.threshold(th3, minValue, 255,
                             cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

    guess_res = "Bin"

    if saveImg == True:
        saveROIImg(res)

    elif guessGesture == True:
        retgesture, guess_res = myNN.guessGesture(mod, res)

        if lastgesture != retgesture:
            lastgesture = retgesture

    elif visualize == True:
        layer = int(raw_input("Enter which layer to visualize "))
        cv2.waitKey(1)
        myNN.visualizeLayers(mod, res, layer)
        visualize = False

    return res, guess_res
コード例 #3
0
def binaryMask(roi, framecount):
    global guess_gesture, visualize, mod, save_image

    gray = cv.cvtColor(roi, cv.COLOR_BGR2GRAY)
    blur = cv.GaussianBlur(gray, (5, 5), 2)

    th3 = cv.adaptiveThreshold(blur, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, 
                               cv.THRESH_BINARY_INV, 3, 1)
    ret, res = cv.threshold(th3, thresh_minvalue, 255,
                            cv.THRESH_BINARY_INV+cv.THRESH_OTSU)

    if guess_gesture and (not framecount % 5):
        # t = threading.Thread(target=nn.guessGesture, args=[mod, res])
        # t.start()
        nn.guessGesture(mod, res)
    elif visualize:
        pass
        # layer = int(input("Enter which layer to visualize"))
        # cv.waitKey(0)
        # nn.visualizeLayers(mod, res, layer)
        # visualize = False

    return res
コード例 #4
0
def skinMask(frame, x0, y0, width, height):
    global guessGesture, visualize, mod, lastgesture, saveImg
    # HSV values
    low_range = np.array([0, 50, 80])
    upper_range = np.array([30, 200, 255])

    cv2.rectangle(frame, (x0, y0), (x0 + width, y0 + height), (0, 255, 0), 1)
    roi = frame[y0:y0 + height, x0:x0 + width]

    hsv = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)

    #Apply skin color range
    mask = cv2.inRange(hsv, low_range, upper_range)

    mask = cv2.erode(mask, skinkernel, iterations=1)
    mask = cv2.dilate(mask, skinkernel, iterations=1)

    #blur
    mask = cv2.GaussianBlur(mask, (15, 15), 1)
    #cv2.imshow("Blur", mask)

    #bitwise and mask original frame
    res = cv2.bitwise_and(roi, roi, mask=mask)

    # color to grayscale
    res = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)

    retgesture = "^______^Skin"

    if saveImg == True:
        saveROIImg(res)

    elif guessGesture == True:
        retgesture = myNN.guessGesture(mod, res)

        if lastgesture != retgesture:
            lastgesture = retgesture
            print myNN.output[lastgesture]
            time.sleep(0.01)
            #guessGesture = False

    elif visualize == True:
        layer = int(raw_input("Enter which layer to visualize "))
        cv2.waitKey(0)
        myNN.visualizeLayers(mod, res, layer)
        visualize = False

    return res, retgesture
コード例 #5
0
def binaryMask(frame, x0, y0, width, height):

    global guessGesture, visualize, mod, lastgesture, saveImg

    cv2.rectangle(frame, (x0, y0), (x0 + width, y0 + height), (0, 255, 0), 1)
    roi = frame[y0:y0 + height, x0:x0 + width]

    gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
    blur = cv2.GaussianBlur(gray, (5, 5), 2)
    #blur = cv2.bilateralFilter(roi,9,75,75)

    th3 = cv2.adaptiveThreshold(blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                cv2.THRESH_BINARY_INV, 11, 2)
    ret, res = cv2.threshold(th3, minValue, 255,
                             cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
    #ret, res = cv2.threshold(blur, minValue, 255, cv2.THRESH_BINARY +cv2.THRESH_OTSU)

    retgesture = "^______^Bin"

    if saveImg == True:
        saveROIImg(res)

    elif guessGesture == True:
        retgesture = myNN.guessGesture(mod, res)

        if lastgesture != retgesture:
            lastgesture = retgesture
            #print lastgesture

            ## Checking for only PUNCH gesture here
            ## Run this app in Prediction Mode and keep Chrome browser on focus with Internet Off
            ## And have fun :) with Dino
            if lastgesture == 3:
                jump = ''' osascript -e 'tell application "System Events" to key code 49' '''
                #jump = ''' osascript -e 'tell application "System Events" to key down (49)' '''
                os.system(jump)
                print myNN.output[lastgesture] + "= Dino JUMP!"

            # time.sleep(0.01 )
            # guessGesture = False

    elif visualize == True:
        layer = int(raw_input("Enter which layer to visualize "))
        cv2.waitKey(1)
        myNN.visualizeLayers(mod, res, layer)
        visualize = False

    return res, retgesture
コード例 #6
0
def skinMask(frame, x0, y0, width, height):
    global mod, lastgesture
    # HSV values
    low_range = np.array([0, 50, 80])
    upper_range = np.array([30, 200, 255])

    cv2.rectangle(frame, (x0, y0), (x0 + width, y0 + height), (0, 255, 0), 1)
    roi = frame[y0:y0 + height, x0:x0 + width]

    hsv = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)

    #Apply skin color range
    mask = cv2.inRange(hsv, low_range, upper_range)

    mask = cv2.erode(mask, skinkernel, iterations=1)
    mask = cv2.dilate(mask, skinkernel, iterations=1)

    #blur
    mask = cv2.GaussianBlur(mask, (15, 15), 1)
    #cv2.imshow("Blur", mask)

    #bitwise and mask original frame
    res = cv2.bitwise_and(roi, roi, mask=mask)
    # color to grayscale
    res = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)

    retgesture = myNN.guessGesture(mod, res)
    if lastgesture != retgesture:
        lastgesture = retgesture

        if lastgesture == 4:
            jump = ''' osascript -e 'tell application "System Events" to key code 49' '''
            #jump = ''' osascript -e 'tell application "System Events" to key down (49)' '''
            os.system(jump)
            print myNN.output[lastgesture] + "= Dino JUMP!"

        if lastgesture == -1:
            print "Nothing"
        else:
            print myNN.output[lastgesture]

        time.sleep(0.01)

    return res, lastgesture
コード例 #7
0
def binaryMask(frame, x0, y0, width, height):
    global guessGesture, visualize, mod, lastgesture, saveImg

    cv2.rectangle(frame, (x0, y0), (x0 + width, y0 + height), (0, 255, 0), 1)
    roi = frame[y0:y0 + height, x0:x0 + width]

    gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
    blur = cv2.GaussianBlur(gray, (5, 5), 2)

    th3 = cv2.adaptiveThreshold(blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                cv2.THRESH_BINARY_INV, 11, 2)
    ret, res = cv2.threshold(th3, minValue, 255,
                             cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

    if guessGesture == True:
        retgesture = myNN.guessGesture(mod, res)
        if lastgesture != retgesture:
            lastgesture = retgesture
            print myNN.output[lastgesture]
            time.sleep(0.01)

    return res
コード例 #8
0
    def Guess(self,frame, x0, y0, width, height):
        low_range = np.array([0, 50, 80])
        upper_range = np.array([30, 200, 255])
        
        cv2.rectangle(frame, (x0,y0),(x0+width,y0+height),(0,255,0),1)
      
        roi = frame[y0:y0+height, x0:x0+width]
        
        hsv = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
        
       
        mask = cv2.inRange(hsv, low_range, upper_range)
        
        mask = cv2.erode(mask, self.skinkernel, iterations = 1)
        mask = cv2.dilate(mask, self.skinkernel, iterations = 1)
        
       
        mask = cv2.GaussianBlur(mask, (15,15), 1)
        
       
        res = cv2.bitwise_and(roi, roi, mask = mask)

        res = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
        return myNN.guessGesture(self.mod,res)