Пример #1
0
    def play(self):
        """
        Allows the bot to play the game with the human player

        @type max_guess: integer
        @param max_guess: holds the current max guess
        @type min_guess: integer
        @param min_guess: holds the current min guess
        @type guess_index: integer
        @param guess_index: holds the current number of guesses made
        @type answer: string
        @param answer: hold the bots answer to the guess
        """
        max_guess = self.MAX
        min_guess = self.MIN
        guess_index = 0
        answer = ''

        #While loop to run if they haven't guessed right
        while answer != 'Yeah! You guessed right!':
            guess_index += 1
            time.sleep(0.5)

            #Logic to change the max and min guess
            if answer == 'Lower!':
                max_guess = guess
            elif answer == 'Higher!':
                min_guess = guess

            #Calculate next guess
            guess = int((max_guess - min_guess) / 2) + min_guess
            print('{0}. Bot: Let\'s try {1}'.format(guess_index, guess))
            answer = main.api(guess)

        print('Bot: I have won!')
Пример #2
0
@software: PyCharm 
"""

import cv2
import os
from main import api
from PIL import Image

save_path = '/home/ai/Desktop/project3/datasets/wang'
font = cv2.FONT_HERSHEY_SIMPLEX
detector = cv2.CascadeClassifier(
    '/home/ai/.local/lib/python3.5/site-packages/cv2/data/haarcascade_frontalface_default.xml'
)
cap = cv2.VideoCapture(0)
print('ok')
id = 0
while True:
    id += 1
    ret, img = cap.read()
    if id % 10 == 0:
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        faces = detector.detectMultiScale(gray, 1.3, 5)
        for (x, y, w, h) in faces:
            crop_face = img[y:y + w, x:x + h]
            name = api(crop_face)
            cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
            cv2.putText(img, name, (x, y), font, 1.2, (255, 0, 0), 2)
        cv2.imshow('test', img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
Пример #3
0
class UIBot(Widget):
    """
        Graphical version of the bot class, which acts as the facilitator of the game.

        @type name: string
        @param name: The name of the bot
        @type MAX: integer
        @param MAX: maximum value of the guess
        @type MIN: integer
        @param MIN: minimum value of the guess    
        @type messages: string
        @param messages: message to be printed to the screen
        """
    name = 'John'
    messages = StringProperty('yaa\n')
    MAX = 100
    MIN = 0


    def welcome(self):
        """
        Welcomes the player to the game. Prints the name of the bot and the game.
        """
        self.write_msg('Hello! My name is {0} and I can play guessing game'.format(
            self.name))
        # Get game area from engine
        self.MIN, self.MAX = main.get_min_and_max()
        self.write_msg('Retrieved game area {0}, {1}'.format(self.MIN, self.MAX))

    def play(self):
          """
        Allows the bot to play the game with the human player

        @type max_guess: integer
        @param max_guess: holds the current max guess
        @type min_guess: integer
        @param min_guess: holds the current min guess
        @type guess_index: integer
        @param guess_index: holds the current number of guesses made
        @type answer: string
        @param answer: hold the bots answer to the guess
        """
        max_guess = self.MAX
        min_guess = self.MIN
        guess_index = 0
        answer = ''


        #While loop to run if they haven't guessed right
        while answer != 'Yeah! You guessed right!':
            guess_index += 1
            time.sleep(0.5)

            #Logic to change the max and min guess
            if answer == 'Lower!':
                max_guess = guess
            elif answer == 'Higher!':
                min_guess = guess

            #Calculate next guess
            guess = int((max_guess - min_guess) / 2) + min_guess
            self.write_msg('{0}. Bot: Let\'s try {1}'.format(guess_index, guess))
            answer = main.api(guess)

        self.write_msg('Bot: I have won!')
Пример #4
0
 def test_api(self):
     assert api() == 200
Пример #5
0
@file: read_camera.py 
@time: 2019/06/26
@contact: [email protected]
@software: PyCharm 
"""

import cv2
from main import api
import os
from PIL import Image
import numpy as np

save_path = r'E:\file\data\face\na'
detector = cv2.CascadeClassifier(r'E:\conda\pkgs\libopencv-3.4.2-h20b85fd_0\Library\etc\haarcascades\haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)
print('ok')
id = 0
while True:
    id += 1
    ret, img = cap.read()
    if id % 10 == 0:
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        faces = detector.detectMultiScale(gray, 1.3, 5)
        for (x, y, w, h) in faces:
            crop_face = img[x:x+w, y:y+h]
            api(Image.fromarray(crop_face))
            # cv2.imwrite(os.path.join(save_path, str(id) + '.jpg'), crop_face)
            cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        # cv2.imshow('test', img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
Пример #6
0
 def test_api(self):
     with patch.object(requests, "get") as get_mock:
         get_mock.return_value = mock_response = Mock()
         mock_response.status_code = 200
         assert api() == 200