Skip to content

Commit

Permalink
feat: 合并yolov5-dnf项目
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverComet7 committed Aug 11, 2022
1 parent 93ad4e5 commit 0c56330
Show file tree
Hide file tree
Showing 10 changed files with 479 additions and 409 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# yolov5

1. 代码中涉及到使用opencv对小地图和技能栏进行模板匹配和二值化等操作,注意,不同游戏分辨率和电脑显示器分辨率是不一致的,代码中给出的(0,0,1280,800)是本人游戏中的分辨率,而small_recgonize.py和skill_recgonize.py中的img[45:65, 1107:1270], img[733: 793, 538:750, 2]是根据不同显示器的分辨率决定的,使用时需要自己调整。

2. 本人训练的yolov5模型还有待提高,我的训练集只有294张图片,因此效果一般。
详细教学请移步b站,有很详细的讲解:https://www.bilibili.com/video/BV18r4y1A7BF/


1. 屏幕检测
2. 怪物,材料的图像识别
3. 控制打怪和捡材料
4. 下一关


1. 识别地图中怪物
2. 寻找位置,释放技能,清理残余,寻找下一个门,进图
3.
2. 寻找位置,释放技能,清理残余,寻找下一个门,进图
805 changes: 403 additions & 402 deletions main2.py

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,61 @@ def forward(self, x):
return self.cv4(self.act(self.bn(torch.cat((y1, y2), dim=1))))


import warnings

class SPPF(nn.Module):
# Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
def __init__(self, c1, c2, k=5): # equivalent to SPP(k=(5, 9, 13))
super().__init__()
c_ = c1 // 2 # hidden channels
self.cv1 = Conv(c1, c_, 1, 1)
self.cv2 = Conv(c_ * 4, c2, 1, 1)
self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)

def forward(self, x):
x = self.cv1(x)
with warnings.catch_warnings():
warnings.simplefilter('ignore') # suppress torch 1.9.0 max_pool2d() warning
y1 = self.m(x)
y2 = self.m(y1)
return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))




class CrossConv(nn.Module):
# Cross Convolution Downsample
def __init__(self, c1, c2, k=3, s=1, g=1, e=1.0, shortcut=False):
# ch_in, ch_out, kernel, stride, groups, expansion, shortcut
super(CrossConv, self).__init__()
c_ = int(c2 * e) # hidden channels
self.cv1 = Conv(c1, c_, (1, k), (1, s))
self.cv2 = Conv(c_, c2, (k, 1), (s, 1), g=g)
self.add = shortcut and c1 == c2

def forward(self, x):
return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))

class C3(nn.Module):
# Cross Convolution CSP
def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5): # ch_in, ch_out, number, shortcut, groups, expansion
super(C3, self).__init__()
c_ = int(c2 * e) # hidden channels
self.cv1 = Conv(c1, c_, 1, 1)
self.cv2 = nn.Conv2d(c1, c_, 1, 1, bias=False)
self.cv3 = nn.Conv2d(c_, c_, 1, 1, bias=False)
self.cv4 = Conv(2 * c_, c2, 1, 1)
self.bn = nn.BatchNorm2d(2 * c_) # applied to cat(cv2, cv3)
self.act = nn.LeakyReLU(0.1, inplace=True)
self.m = nn.Sequential(*[CrossConv(c_, c_, 3, 1, g, 1.0, shortcut) for _ in range(n)])

def forward(self, x):
y1 = self.cv3(self.m(self.cv1(x)))
y2 = self.cv2(x)
return self.cv4(self.act(self.bn(torch.cat((y1, y2), dim=1))))



def autopad(k, p=None): # kernel, padding
# Pad to 'same'
if p is None:
Expand Down
Binary file added resource/best.pt
Binary file not shown.
2 changes: 1 addition & 1 deletion small_recgonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np


img_path = "datasets/guiqi/test/61_93.jpg"
img_path = "test/DNF.png"
img = cv.imread(img_path)

def img_show(img):
Expand Down
Binary file added test/DNF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/cv2_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import cv2
from ..grabscreen import grab_screen

img = grab_screen((0, 0, 1280, 800))
img0 = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
dnf = cv2.imread(img0)
cv2.imshow('rgb', dnf)
# BGR = cv2.cvtColor(dnf,cv2.COLOR_RGB2BGR)
# cv2.imshow('BGR',BGR)
Binary file added test/test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added test/yoloModel.py
Empty file.
6 changes: 3 additions & 3 deletions wx-read/globalSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def sortWay(book):
return book['bookInfo']['newRating']


def getWXBooks(queryPath):
def getWXBooks(queryPath,searchWord):
# booksTitleSet = client.hget(searchKeyWord, 'booksTitleSet') or set()
# maxIdx = int(client.hget(searchKeyWord, 'maxIdx')) if client.hget(searchKeyWord, 'maxIdx') is not None else 0
maxIdx = 0
Expand All @@ -33,7 +33,7 @@ def getWXBooks(queryPath):
rTime = random.randint(1, 3) # 随机延迟,从1到3内取一个整数值
time.sleep(rTime) # 把随机取出的整数值传到等待函数中
res = requests.get(
queryPath, params={'maxIdx': maxIdx, 'keyword': searchKeyWord, 'fragmentSize': 120, 'count': 20})
queryPath, params={'maxIdx': maxIdx, 'keyword': searchWord, 'fragmentSize': 120, 'count': 20})
books = res.json()['books']
if not totalCount:
totalCount = res.json()['totalCount']
Expand All @@ -60,5 +60,5 @@ def getWXBooks(queryPath):
return bookList


books = getWXBooks('https://weread.qq.com/web/search/global')
books = getWXBooks('https://weread.qq.com/web/search/global',searchKeyWord)
mongodbWrite(searchKeyWord, books)

0 comments on commit 0c56330

Please sign in to comment.