Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
1. Star detection error
2. Unexpected crash
3. Add star distribution
  • Loading branch information
ProblemFactory committed Apr 24, 2021
1 parent f27594d commit 797cd0a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
artifacts.genshinart.json
ArtScanner/artifacts.genshinart.json
ArtScanner/artifacts.dat
ArtScanner/artifacts.dat.index
ArtScanner/artifacts.dat.lock
ArtScanner/artifacts.dat.tmp
**/__pycache__/**
ArtScanner/build/**
ArtScanner/dist/**
ArtScanner/*.spec
1 change: 0 additions & 1 deletion ArtScanner/art_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def add(self, info, art_img):
transaction.commit()
return True
except Exception as e:
raise
return False

def exportGenshinArtJSON(self, path):
Expand Down
1 change: 1 addition & 0 deletions ArtScanner/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyinstaller --onefile --add-data "mn_model.h5;." --hidden-import=h5py --hidden-import=h5py.defs --hidden-import=h5py.utils --hidden-import=h5py.h5ac --hidden-import=h5py._proxy --uac-admin -n ArtScanner main.py
12 changes: 11 additions & 1 deletion ArtScanner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def is_admin():
saved = 0
skipped = 0
failed = 0
star_dist = [0,0,0,0,0]

os.makedirs('artifacts', exist_ok=True)

Expand Down Expand Up @@ -121,7 +122,9 @@ def artscannerCallback(art_img):
global art_id
global skipped
global failed
global star_dist
info = ocr_model.detect_info(art_img)
star_dist[info['star']-1] += 1
if decodeValue(info['level'])<level_threshold:
skipped += 1
elif art_data.add(info, art_img):
Expand Down Expand Up @@ -150,11 +153,18 @@ def artscannerCallback(art_img):
else:
print("在最后点击位置未检测到圣遗物,自动终止")
except Exception as e:
raise
print()
print(f"因为\"{e}\"而意外停止扫描,将保存已扫描的圣遗物信息")
if saved != 0:
art_data.exportGenshinArtJSON('artifacts.genshinart.json')
print(f'总计扫描了{skipped+saved}/{art_id}个圣遗物,保存了{saved}个到artifacts.genshinart.json,失败了{failed}个')
print('无效识别/失败结果请到artifacts路径中查看')
print('----------------------------')
print('圣遗物星级分布:')
print(f'5星:{star_dist[4]}')
print(f'4星:{star_dist[3]}')
print(f'3星:{star_dist[2]}')
print(f'2星:{star_dist[1]}')
print(f'1星:{star_dist[0]}')
print('----------------------------')
input('已完成,按回车退出')
2 changes: 1 addition & 1 deletion ArtScanner/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def extract_art_info(self, art_img):

def detect_star(self, art_img):
star = art_img.crop([i*self.scale_ratio for i in Config.star_coords])
cropped_star = self.crop(self.to_gray(star))
cropped_star = self.crop(self.normalize(self.to_gray(star)))
coef = cropped_star.shape[1]/cropped_star.shape[0]
coef = coef/1.30882352+0.21568627
return int(round(coef))
Expand Down

0 comments on commit 797cd0a

Please sign in to comment.