import numpy as np import cv2 import time import tkinter as tk import tkinter.font as font from tkinter import * from tkinter.ttk import *

import numpy as numpy

import sys

import cv2

from os import path import os import math import numpy as np ''' import skimage.data as data import skimage.segmentation as seg from skimage import filters from skimage import draw from skimage import color from skimage import exposure import skimage ''' import numpy as np from PIL import Image, ImageFilter, ImageOps import cv2 try: from PIL import Image except ImportError: import Image import pytesseract from pytesseract import Output import pytesseract as pt from PIL import Image import math

arr = [bool firstShot, bool isHit, bool isHeadShot, bool left]

def dataAnalysis(): for j in range(len(fireFight)): masterArr = [] firstShots=[] retArr=[] HeadShot=0 firstHeadShot=0 firstHits=0 Hits=0 leftShots=0 for i in range(len(frameCount)): data = input(list("Program")) masterArr = masterArr+data LS=len(masterArr) for j in range(len(masterArr)): if masterArr[j][0]: firstShots=firstShots+masterArr[j] FLS=len(firstShots) for i in range(len(firstShots)): if firstShots[i][2]: firstHeadShot=firstHeadShot+1

    for i in range(len(firstShots)):
        if firstShots[i][1]:
            firstHits=firstHits+1

    for i in range(len(masterArr)):
        if masterArr[i][1]:
            Hits=Hits+1

    for i in range(len(masterArr)):
        if masterArr[i][3]:
            leftShots=leftShots+1

    for i in range(len(masterArr)):
        if masterArr[i][2]:
            HeadShot=HeadShot+1

    retArr=retArr+[Hits/LS, HeadShot/LS, firstHits/FLS, firstHeadShot/FLS, leftShots/LS]
finalArr=[]
totalSum=0
size=len(retArr)
for i in range(len(retArr)):
    for j in range(len(retArr)):
        totalSum=totalSum+retArr[i][j]
    finalArr.append(totalSum/size)
    totalSum=0
return finalArr

def image_show(image, nrows=1, ncols=1, cmap='gray', **kwargs): fig, ax = plt.subplots(nrows=nrows, ncols=ncols, figsize=(16, 16)) ax.imshow(image, cmap='gray') ax.axis('off') return fig, ax

def anotherFunction(): import matplotlib.pyplot as plt import numpy as np from PIL import Image, ImageFilter, ImageOps from matplotlib import image, pyplot import cv2 try: from PIL import Image except ImportError: import Image import pytesseract from pytesseract import Output import pytesseract as pt from PIL import Image cap = cv2.VideoCapture('Valorant.MP4') #input video if (cap.isOpened()== False): print("Error opening video stream or file") while(cap.isOpened()): ret, frame = cap.read() if ret == True:

        filename = "frame%d.jpg"
        im = Image.open(filename)
        #im = Image.open(frame)

        border = (1270,985,587+740,33+1020)

        im1 = frame.crop(border)
        im1.save('newPic.png')

        fname = r'C:\Users\Jarrett\newPic.png'
        ima = Image.open(fname).convert("L")
        arr = np.asarray(ima)

        ori_image = Image.open(fname)
        ori_image_rgb = ori_image.convert("RGB")

        rgb_pixel_value = ori_image_rgb.getpixel((17,33))

        imgss = Image.open(fname)
        data = np.array(imgss)

        converted = np.where(data == 255, 0, 255)

        imgss = Image.fromarray(converted.astype('uint8')).convert("RGB")

        imgss.save('new_pic.jpg')

        custom_config = r'--oem 3 -c tessedit_char_whitelist=1234567890 --psm 6 outputbase digits'
        text = pytesseract.image_to_string(Image.open(r'C:\Users\Jarrett\new_pic.jpg'), config=custom_config)
        print(text)

Enemy

def detectEnemy(): cap = cv2.VideoCapture('Valorant.MP4') #input video if (cap.isOpened()== False): print("Error opening video stream or file") while(cap.isOpened()): ret, frame = cap.read() if ret == True: #image = cv2.imread('/Users/edmond/Desktop/ValorantCode/full2.png') #image adress

        x2 = int(frame.shape[1]/3)
        y2 = int(frame.shape[0]/2)

        #print("x2: ", x2)
        #print("y2: ", y2)
        ROI = frame[0:y2, 0:x2]

        hsv = cv2.cvtColor(ROI, cv2.COLOR_BGR2HSV)
        rgb = cv2.cvtColor(ROI,cv2.COLOR_HSV2BGR)
        #for RGB for enemy circle + dead x
        RGBlower = np.array([0,0,174]) 
        RGBupper = np.array([255,78,255])

        #for HSV for enemy circle
        HSVlower = np.array([171,159,155]) 
        HSVupper = np.array([255,255,255])

        mask = cv2.inRange(hsv, HSVlower, HSVupper)

        contours, h = cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

        count = 0
        if(len(contours)>0):
            for c in contours:
                area = cv2.contourArea(c)
                cv2.drawContours(ROI, c, -1, (0, 255, 0), 3)
                if area > 5.0:
                    #print("An enemy exists!")
                    detectHitbox()
                    count = 1
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

Hitbox

def detectHitbox():

ROI = cv2.imread('/Users/edmond/Desktop/ValorantCode/enemyOutline.png') #image adress
x2 = int(ROI.shape[1])
y2 = int(ROI.shape[0])
#print(x2)
#print(y2)


hsv = cv2.cvtColor(ROI, cv2.COLOR_BGR2HSV)
rgb = cv2.cvtColor(ROI,cv2.COLOR_HSV2BGR)

#for RGB for enemy circle + dead x
RGBlower = np.array([0,0,174]) 
RGBupper = np.array([255,78,255])

#for HSV for enemy circle
HSVlower = np.array([171,197,53]) 
HSVupper = np.array([227,255,255])

mask = cv2.inRange(hsv, HSVlower, HSVupper)

contours, h = cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)


arrayX = []
arrayY = []

#print(contours)
if(len(contours)>0):
    for c in contours:
        area = cv2.contourArea(c)
        print(area)

        #draws contours for each red value detected
        cv2.drawContours(ROI, c, -1, (0,255,0), 0)
        (x, y), radius = cv2.minEnclosingCircle(c)
        arrayX.append(x)
        arrayY.append(y)

#Sort x and y values of contour centers into respective arrays
arrayX = sorted(arrayX)
arrayY = sorted(arrayY)
lengthX = len(arrayX)
lengthY = len(arrayY)



#Draw Rectangle
output = cv2.rectangle(ROI, (int(arrayX[0]), int(arrayY[0])), (int(arrayX[lengthX-1]), int(arrayY[lengthY-1])), (0, 255, 0), 2)



#vertical line down center of body
midX = (arrayX[0] + arrayX[lengthX-1]) / 2
output = cv2.line(ROI, (int(midX), int(arrayY[0])), (int(midX), int(arrayY[lengthY-1])), (0, 255, 0), thickness=1)

#horizontal line separating head and body
yval = ((arrayY[lengthY-1] - arrayY[0])/5)
headLev = arrayY[0] + yval
output = cv2.line(ROI, (int(arrayX[0]), int(headLev)), (int(arrayX[lengthX-1]), int(headLev)), (0, 255, 0), thickness=1)

#locate center
centerX = x2/2 
centerY = y2/2

#cursor location relative to target
if centerX > midX:
    print("The cursor is to the right of the target.")
if centerX < midX:
    print("The cursor is to the left of the target.")
if centerX == midX:    
    print("The cursor is on the horizontal center of the target.")

if centerY < arrayY[0]:
    print("The cursor is above the target.")
if centerY >= arrayY[0] and centerY < headLev:
    print("The cursor is aimed for a headshot.")
if centerY >= headLev and centerY <= arrayY[lengthY-1]:    
    print("The cursor is aimed for a body shot.")   
if centerY > arrayY[lengthY-1]:
    print("The cursor is below the target.")

#Displaying the image  
#cv2.imshow("ROI", ROI)
#cv2.imshow("window_name", output)
#cv2.imshow("mask",mask)

import tkinter as tk import tkinter.font as font from tkinter import * from tkinter.ttk import *

import numpy as numpy

import sys

import cv2

from os import path import os import math

root = tk.Tk() root.title("ValorantAccuracyProgram")

def findFile(filename): test = filename.get() isExist = os.path.exists(test) if(isExist): return True else: return False

def makeGraph(myArray = [], *args): statsFrame.place(relx=0.1,rely=0.1, relwidth = 0.85, relheight = 0.85) graphLabel.place(relx = 0.2, rely = 0.05) for x in range(len(myArray)): if x == 0: stats = tk.Label(statsFrame, text="General Accuracy Percentage: " + str(myArray[x]) + "%", fg = '#f2e122', bg = "black") stats['font']= myFont stats.place(relx=0, rely=0.2, relwidth = 1, relheight = 0.15) if x == 1: stats = tk.Label(statsFrame, text="Headshot Percentage: " + str(myArray[x]) + "%", fg = '#f2e122', bg = "black") stats['font']= myFont stats.place(relx=0, rely=0.35, relwidth = 1, relheight = 0.15) if x == 2: stats = tk.Label(statsFrame, text="First Shot Accuracy: " + str(myArray[x]) + "%", fg = '#f2e122', bg = "black") stats['font']= myFont stats.place(relx=0, rely=0.50, relwidth = 1, relheight = 0.15) if x == 3: stats = tk.Label(statsFrame, text="First Shot Headshot Percentage: " + str(myArray[x]) + "%", fg = '#f2e122', bg = "black") stats['font']= myFont stats.place(relx=0, rely=0.65, relwidth = 1, relheight = 0.15)

def button_clicked(): if(findFile(entryReal)): frame.destroy() makeGraph(data)

else:
    label3.place(relx = 0.12, rely = 0.7)

def main(): anotherFunction()

HEIGHT = 700
WIDTH = 800

myFont = font.Font(family='Calibri')
headerFont = font.Font(family = 'Calibri', size = 40, weight = 'bold')
canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()

background_image = tk.PhotoImage(file = 'LogoVersion_Beta_Key_Art_VALORANT.png')
background_label = tk.Label(root, image = background_image)
background_label.place(relwidth=1,relheight=1)

frame = tk.Frame(root, bg = '#1a23c9')
frame.place(relx = 0.1, rely = 0.1, relwidth = 0.85, relheight = 0.85)



statsFrame = tk.Frame(root, bg = 'black')



label = tk.Label(frame, text="Please enter your file path here: ", bg ='#1a23c9', fg = 'white')
label['font']= myFont
label.place(relx = 0, rely = 0.6)


label2 = tk.Label(frame, text= "Hello! This program will calculate your first shot \n accuracy and a lot more statistics from one of your gameplays. All \n you have to do is upload a video of one of your matches in the box below,\n and the program will analyze and  return to you detailed information \n about your stats during that game. Hope you improve from this info!", fg = '#FFDF00', bg = 'black')
label2['font']= myFont
label2.place(relx=0, rely=0, relwidth = 1, relheight = 0.4)

label3 = tk.Label(frame, text= "Sorry, we weren't able to find that file. Check again and retry.", fg = 'red')
label3['font'] = myFont


graphLabel = tk.Label(statsFrame, text = "Valorant Statistics", fg = '#1a23c9', bg = 'black')
graphLabel['font'] = headerFont

entryReal = tk.Entry(frame)
entryReal['font']= myFont
entryReal.place(relx = 0.45, rely = 0.603, relwidth = 0.5, relheight = 0.05)

button = tk.Button(frame, text="Go!", bg = 'black', fg='white', command=lambda: button_clicked())
button['font']= myFont
button.place(relx = 0.46, rely = 0.8, relwidth = 0.07, relheight = 0.07)



root.mainloop()

Built With

Share this project:

Updates