import cv2 as cv
import numpy as np
import os
from time import time
from mss import mss
from PIL import Image

# Change the working directory to the folder this script is in.
# Doing this because I'll be putting the files from each video in their own folder on GitHub
os.chdir(os.path.dirname(os.path.abspath(__file__)))

x = 0
y = 0
h = 1440
w = 2560 

mon = {'top': x, 'left': y, 'width': w , 'height': h}
sct = mss()

cascadeFaceDet = cv.CascadeClassifier('cascade/cascade.xml')

loop_time = time()

while(True):

    sct_img = sct.grab(mon)
    # get an updated image of the game
    img = Image.frombytes('RGB', (sct_img.size.width, sct_img.size.height), sct_img.rgb)
    imageCapture = cv.cvtColor(np.array(img), cv.COLOR_RGB2BGR)
    
    # do object detection
    rectangles = cascadeFaceDet.detectMultiScale(imageCapture)

    for (x, y, w, h) in rectangles:
        # determine the box positions
        top_left = (x, y)
        bottom_right = (x + w, y + h)
        # draw the box
        cv.rectangle(imageCapture, top_left, bottom_right, (255, 0, 0), 2)


    # display the images ie Screen Capture with Squares
    cv.imshow('Face Detection - Prototype', imageCapture)

    print('FPS {}'.format(1 / (time() - loop_time)))
    loop_time = time()

    key = cv.waitKey(1)

    if key == ord('q'):
        cv.destroyAllWindows()
        break
import cv2 as cv
import numpy as np
import os
from time import time
from mss import mss
from PIL import Image

# Change the working directory to the folder this script is in.
# Doing this because I'll be putting the files from each video in their own folder on GitHub
os.chdir(os.path.dirname(os.path.abspath(__file__)))

x = 0
y = 0
h = 1440
w = 2560 

mon = {'top': x, 'left': y, 'width': w , 'height': h}
sct = mss()

cascadeFaceDet = cv.CascadeClassifier('cascade/cascade.xml')

loop_time = time()

while(True):

    sct_img = sct.grab(mon)
    # get an updated image of the game
    img = Image.frombytes('RGB', (sct_img.size.width, sct_img.size.height), sct_img.rgb)
    imageCapture = cv.cvtColor(np.array(img), cv.COLOR_RGB2BGR)
    
    # do object detection
    rectangles = cascadeFaceDet.detectMultiScale(imageCapture)

    for (x, y, w, h) in rectangles:
        # determine the box positions
        top_left = (x, y)
        bottom_right = (x + w, y + h)
        # draw the box
        cv.rectangle(imageCapture, top_left, bottom_right, (255, 0, 0), 2)


    # display the images ie Screen Capture with Squares
    cv.imshow('Face Detection - Prototype', imageCapture)

    print('FPS {}'.format(1 / (time() - loop_time)))
    loop_time = time()

    key = cv.waitKey(1)

    if key == ord('q'):
        cv.destroyAllWindows()
        break
# Change the working directory to the folder this script is in. # Doing this because I'll be putting the files from each video in their own folder on GitHub # get an updated image of the game # do object detection # determine the box positions # draw the box # display the images ie Screen Capture with Squares