Ejemplo n.º 1
0
            cv2.imshow("preview", frame)

        #facerect = cascade.detectMultiScale(frame_gray, scaleFactor=1.01, minNeighbors=3, minSize=(3, 3))
        if len(facerect) > 0:
            print('face detected')
            color = (255, 255, 255)  # 白
            for rect in facerect:
                # 创建围绕检测的面部的矩形
                #cv2.rectangle(frame, tuple(rect[0:2]), tuple(rect[0:2] + rect[2:4]), color, thickness=2)

                x, y = rect[0:2]
                width, height = rect[2:4]
                image = frame[y - 10:y + height, x:x + width]

                result = model.predict(image)
                if result == 0:  # boss
                    print('Boss is approaching')
                    #show_image()
                else:
                    print('Not boss')

        #10msec键输入等待
        k = cv2.waitKey(100)
        #Esc退出按下该键
        if k == 27:
            break

    #退出拍摄
    cap.release()
    cv2.destroyAllWindows()
Ejemplo n.º 2
0
                cv2.imshow('Recognizing', buffer)
                #cv2.namedWindow('Recognizing', cv2.WINDOW_AUTOSIZE | cv2.WINDOW_KEEPRATIO | cv2.WINDOW_GUI_EXPANDED)

            for rect in facerect:
                [x, y, width, height] = extendFaceRect(rect)

                # Crop the face
                if GRAY_MODE == True:
                    img_predict = frame_gray[y:y + height, x:x + width]
                else:
                    img_predict = frame[y:y + height, x:x + width]

                # Predict face
                if GRAY_MODE == True:
                    result = model.predict(img_predict, img_channels=1)
                else:
                    result = model.predict(img_predict)

                if DEBUG_OUTPUT == True:
                    outimg = frame[y:y + height, x:x + width]
                    if result == 0:
                        write_image(
                            './output/isme/' + str(random.randint(1, 999999)) +
                            '.jpg', outimg)
                    else:
                        write_image(
                            './output/notme/' +
                            str(random.randint(1, 999999)) + '.jpg', outimg)

                if result == 0:  # Is me
Ejemplo n.º 3
0
        # Recognize faces
        facerect = cascade.detectMultiScale(frame_gray, 1.3, 5)

        recStatus = 0
        if len(facerect) > 0:
            print(timestamp(), 'Cara detectada.')
            color = (255, 255, 255)  # 白

            for rect in facerect:
                [x, y, width, height] = extendFaceRect(rect)

                # Crop the face
                img_predict = frame[y:y + height, x:x + width]

                # Predict face
                result = model.predict(img_predict)

                if result == 0:  # Is me
                    print(timestamp(), "!Eres tu Raul! :)")
                    isme += 1
                    recStatus = 1
                else:
                    print(timestamp(), 'No eres Raul >:(')
                    notme += 1
                    if recStatus == 0:
                        recStatus = -1

                print(timestamp(), 'yo', isme, 'otro', notme)

        # End if Face Detected
        if recStatus == -1 or (recStatus == 0 and