-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetweapon.py
More file actions
100 lines (85 loc) · 2.75 KB
/
Copy pathGetweapon.py
File metadata and controls
100 lines (85 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import mss
import time
import numpy as np
import cv2
import os
from PIL import Image
wpath = os.path.join('weapon')
dirlist = os.listdir(wpath)
monitor = {'zhu': {'left': 1850, 'top': 837, 'width': 40, 'height': 14},
'fu': {'left': 1830, 'top': 920, 'width': 61, 'height': 17}}
mdimg = {'zhu': ['ak47.jpg', 'awp.jpg', 'm4a4.jpg'], 'fu': ['shamo.jpg']}
sct = mss.mss()
def generate_weapon_txt(wdir, wtype):
imglist = os.listdir(wpath + '/{}'.format(wdir))
cutedimg = []
for img in imglist:
if img.endswith('.jpg') == False:
continue
yimg = Image.open(wpath + '/{}/{}'.format(wdir, img))
if yimg.mode in ('RGBA', 'P'):
yimg = yimg.convert('RGB')
cutedimg.append(yimg.convert('L'))
# ret, thresh1=cv2.threshold(GrayImage, 200, 255, cv2.THRESH_BINARY)
print(len(cutedimg))
scount = 0
width, height = cutedimg[0].size
print(width, height)
sbimg = Image.new("L", (width, height), color=0)
for x in range(width):
for y in range(height):
color = cutedimg[0].getpixel((x, y)) > 150
# print(x, y, color)
same = True
for i in range(1, len(cutedimg)):
irgb = cutedimg[i].getpixel((x, y)) > 150
# print(x, y, color, irgb)
if irgb != color:
same = False
break
if same:
# print('same', x, y)
sbimg.putpixel((x, y), 255)
scount += 1
print(scount)
sbimg.save('{}/{}.jpg'.format(wpath, wdir))
def Cap(wname, wtype):
i = 0
while True:
i += 1
st = sct.grab(monitor[wtype])
img = Image.frombytes("RGB", st.size, st.bgra, "raw", "BGRX")
while os.path.exists('{}/{}/{}.jpg'.format(wpath, wname, i)):
i += 1
img.save('{}/{}/{}.jpg'.format(wpath, wname, i))
time.sleep(0.5)
def detectWeapon():
for m in monitor:
st = sct.grab(monitor[m])
img = Image.frombytes("RGB", st.size, st.bgra, "raw", "BGRX")
img = img.convert('L')
for wp in mdimg[m]:
Mbimg = Image.open(wpath + '/{}'.format(wp))
width, height = Mbimg.size
hd, match, zbds = 0, 0, 0
for x in range(width):
for y in range(height):
clw = img.getpixel((x, y)) > 150
mclw = Mbimg.getpixel((x, y)) > 150
if mclw:
zbds += 1
if clw and mclw:
match += 1
else:
hd += 1
if hd > int(0.5 * width * height) and match == zbds:
# print(hd, match, zbds, width, height)
print(wp.split('.')[0])
return wp.split('.')[0]
return 'ak47'
# detectWeapon()
# generate_weapon_txt('shamo', 'fu')
# generate_weapon_txt('ak47', 'zhu')
# generate_weapon_txt('ak47', 'zhu')
# generate_weapon_txt('m4a4', 'zhu')
# Cap('m4a4')