Skip to content

Commit

Permalink
Merge pull request #128 from infstellar/dev
Browse files Browse the repository at this point in the history
Dev -> Main
  • Loading branch information
infstellar authored Nov 16, 2023
2 parents 313908f + e756590 commit 579dd7f
Show file tree
Hide file tree
Showing 38 changed files with 256 additions and 335 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,4 @@ dev_assets/tlpp/*
!dev_assets/tlpp/QXV220230513083258i0.pydict
requirements2.txt
config/missiondownload/missiondownload_meta.json
config/cookies/web_genshin_cookies.json
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ scipy
py7zr

PyAutoGUI==0.9.53
PyQt5
pywebio
pydirectinput

Expand Down
2 changes: 1 addition & 1 deletion snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def jwa_3(imsrc):
input('wait')
i += 1
num_i += 1
cap = itt.capture(jpgmode=0)
cap = itt.capture(jpgmode=NORMAL_CHANNELS)
# cap = itt.png2jpg(cap, channel = 'ui', alpha_num = 50)# 22 no Q
cv2.imwrite(ROOT_PATH + '\\' + "tools\\snapshot\\" + str(time.time()) + ".jpg", cap) # type: ignore
x = str(time.time())
Expand Down
2 changes: 1 addition & 1 deletion source/combat/aim_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def get_enemy_feature(self, ret_mode=1):
Returns:
_type_: _description_
"""
cap = self.itt.capture()
cap = self.itt.capture(jpgmode=FOUR_CHANNELS)
orsrc = cap.copy()
imsrc = combat_lib.get_enemy_blood_bar_img(cap)
_, imsrc2 = cv2.threshold(imsrc, 1, 255, cv2.THRESH_BINARY)
Expand Down
2 changes: 1 addition & 1 deletion source/combat/switch_character_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _check_and_reborn(self,x) -> bool:
succ_flag_1 = False
print(self.died_character)
for i in range(10):
if ocr.is_img_num_plus(itt.capture(posi=asset.AreaCombatRevivalFoods.position, jpgmode=0))[0]:
if ocr.is_img_num_plus(itt.capture(posi=asset.AreaCombatRevivalFoods.position, jpgmode=NORMAL_CHANNELS))[0]:
break
time.sleep(0.15)
if self.checkup_stop_func(): # break
Expand Down
8 changes: 4 additions & 4 deletions source/combat/tactic_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def is_e_available(self): # 被击飞时不可用
return True

def _is_e_release(self, show_res = False):
cap = self.itt.capture(posi=posi_manager.posi_chara_e)
cap = self.itt.capture(posi=posi_manager.posi_chara_e, jpgmode=FOUR_CHANNELS)
cap = self.itt.png2jpg(cap, channel='ui', alpha_num=100)
if show_res:
cv2.imshow("_is_e_release", cap)
Expand All @@ -127,7 +127,7 @@ def _is_e_release(self, show_res = False):
if ret:
return True
else:
cap = self.itt.capture(posi=posi_manager.posi_chara_e)
cap = self.itt.capture(posi=posi_manager.posi_chara_e, jpgmode=FOUR_CHANNELS)
cap = self.itt.png2jpg(cap, channel='ui', alpha_num=100)
ret, t = ocr_light.is_img_num_plus(cap)

Expand All @@ -137,7 +137,7 @@ def _is_e_release(self, show_res = False):
return False

def _is_longE_release(self, show_res = False):
cap = self.itt.capture(posi=posi_manager.posi_chara_e)
cap = self.itt.capture(posi=posi_manager.posi_chara_e, jpgmode=FOUR_CHANNELS)
cap = self.itt.png2jpg(cap, channel='ui', alpha_num=100)
if show_res:
cv2.imshow("_is_e_release", cap)
Expand Down Expand Up @@ -353,7 +353,7 @@ def is_q_ready(self, show_res=False):
bool: Whether Q-Skill can be triggered
"""

cap = self.itt.capture(jpgmode=0)
cap = self.itt.capture(jpgmode=NORMAL_CHANNELS)

imsrc = cap
imsrc_q_skill = crop(imsrc, posi_manager.posi_complete_chara_q)
Expand Down
6 changes: 3 additions & 3 deletions source/commission/commission_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def traverse_mondstant(self):
genshin_map.get_bigmap_posi()
genshin_map._move_bigmap(posi.tianli, force_center = True)
cap_posi = [220,240,1920-200,1080-150]
img = itt.capture(jpgmode=0)
img = itt.capture(jpgmode=NORMAL_CHANNELS)
img = crop(img, cap_posi)
img = recorp(img,cap_posi)
positions = itt.match_multiple_img(img, template=asset.IconBigmapCommission.image)
positions = match_multiple_img(img, template=asset.IconBigmapCommission.image)
if len(positions)>0:
curr_posi = genshin_map.get_bigmap_posi()
for i in positions:
Expand Down Expand Up @@ -119,7 +119,7 @@ def _set_and_save_and_load_commission_dicts(self) -> bool:
return True

def _detect_commission_type(self)->str:
img = itt.capture(jpgmode=0)
img = itt.capture(jpgmode=NORMAL_CHANNELS)
img_choose = crop(img.copy(), asset.AreaBigmapChoose.position)
img_sidebar = crop(img.copy(), asset.AreaBigmapSidebarCommissionName.position)

Expand Down
4 changes: 2 additions & 2 deletions source/commission/general/DangerousHaul.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def __init__(self, commission_position):
super().__init__("DangerousHaul", commission_position, is_CCT=True, is_CFCF=False)

def _aim_to_commission_icon(self):
cap = itt.capture(jpgmode=0)
cap = itt.capture(jpgmode=NORMAL_CHANNELS)
ban_posi=asset.IconCommissionCommissionIcon.cap_posi
cap[ban_posi[1]:ban_posi[3],ban_posi[0]:ban_posi[2]]=0
r = movement.view_to_imgicon(cap, asset.IconCommissionInCommission)
if not r:
return False
if r<=30:
dist_cap = itt.capture([SCREEN_CENTER_X-80,SCREEN_CENTER_Y-100,SCREEN_CENTER_X+80,SCREEN_CENTER_Y+40],jpgmode=0)
dist_cap = itt.capture([SCREEN_CENTER_X-80,SCREEN_CENTER_Y-100,SCREEN_CENTER_X+80,SCREEN_CENTER_Y+40],jpgmode=NORMAL_CHANNELS)
dist_cap = extract_white_letters(dist_cap, threshold=90)
# is_num, dist = ocr.is_img_num_plus(dist_cap)
res = ocr_light.get_all_texts(dist_cap)
Expand Down
4 changes: 2 additions & 2 deletions source/commission/general/IncreasingDanger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def __init__(self, commission_position):
super().__init__("IncreasingDanger", commission_position, is_CCT=True, is_CFCF=False)

def _aim_to_commission_icon(self):
cap = itt.capture(jpgmode=0)
cap = itt.capture(jpgmode=NORMAL_CHANNELS)
ban_posi=asset.IconCommissionCommissionIcon.cap_posi
cap[ban_posi[1]:ban_posi[3],ban_posi[0]:ban_posi[2]]=0
r = movement.view_to_imgicon(cap, asset.IconCommissionInCommission)
if not r:
return False
if r<=30:
dist_cap = itt.capture([SCREEN_CENTER_X-80,SCREEN_CENTER_Y-100,SCREEN_CENTER_X+80,SCREEN_CENTER_Y+40],jpgmode=0)
dist_cap = itt.capture([SCREEN_CENTER_X-80,SCREEN_CENTER_Y-100,SCREEN_CENTER_X+80,SCREEN_CENTER_Y+40],jpgmode=NORMAL_CHANNELS)
dist_cap = extract_white_letters(dist_cap, threshold=90)
# is_num, dist = ocr.is_img_num_plus(dist_cap)
res = ocr_light.get_all_texts(dist_cap)
Expand Down
2 changes: 1 addition & 1 deletion source/common/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _trigger_e_ready(self):
return True

def _trigger_q_ready(self):
cap = self.itt.capture()
cap = self.itt.capture(jpgmode=FOUR_CHANNELS)
cap = self.itt.png2jpg(cap, channel='ui', alpha_num=20) # BEFORE V3D1
# cap = self.itt.png2jpg(cap, channel='bg', alpha_num = 175)

Expand Down
2 changes: 1 addition & 1 deletion source/dev_tool/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from source.interaction.interaction_core import itt
from source.util import *
while 1:
cap = itt.capture(jpgmode=0)
cap = itt.capture(jpgmode=NORMAL_CHANNELS)
cv2.imwrite(ROOT_PATH + '\\' + "tools\\snapshot\\" + str(time.time()) + ".jpg", cap) # type: ignore
input()
2 changes: 1 addition & 1 deletion source/dev_tool/video2path.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class VideoNotFoundError(Exception):pass
break
else:
iii = int(iii)
cv2.imshow(f'tper{iii}', genshin_map.get_img_near_posi(itt.capture(), rlist[iii].position))
cv2.imshow(f'tper{iii}', genshin_map.get_img_near_posi(itt.capture(jpgmode=FOUR_CHANNELS), rlist[iii].position))
cv2.waitKey(1)
genshin_map.init_position(rlist[iii].position)
logger.info(f"press any key to continue.")
Expand Down
26 changes: 13 additions & 13 deletions source/funclib/big_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ def get_tw_points(bigmatMat, stop_func):
Returns:
list: 坐标列表
"""
ret = itt.match_multiple_img(bigmatMat, asset.IconBigmapTeleportWaypoint.image)
ret = match_multiple_img(bigmatMat, asset.IconBigmapTeleportWaypoint.image)
if len(ret) == 0: # 自动重试
logger.warning("获取传送锚点坐标失败,正在重试")
time.sleep(5)
bigmatMat = itt.capture(jpgmode=0)
bigmatMat = itt.capture(jpgmode=NORMAL_CHANNELS)
ui_control.ui_goto(UIPage.page_bigmap)
# scene_manager.switchto_bigmapwin(scene_manager.default_stop_func)
return get_tw_points(bigmatMat, stop_func)
Expand All @@ -126,11 +126,11 @@ def get_gs_points(bigmatMat, stop_func):
Returns:
list: 坐标列表
"""
ret = itt.match_multiple_img(bigmatMat, asset.IconBigmapGodStatue.image, threshold=0.98)
ret = match_multiple_img(bigmatMat, asset.IconBigmapGodStatue.image, threshold=0.98)
if len(ret) == 0: # 自动重试
logger.warning("获取七天神像坐标失败,正在重试")
time.sleep(5)
bigmatMat = itt.capture(jpgmode=0)
bigmatMat = itt.capture(jpgmode=NORMAL_CHANNELS)
ui_control.ui_goto(UIPage.page_bigmap)
# scene_manager.switchto_bigmapwin(scene_manager.default_stop_func)
return get_gs_points(bigmatMat, stop_func)
Expand All @@ -145,7 +145,7 @@ def get_dm_points(bigmatMat, stop_func):
Returns:
list: 坐标列表
"""
ret = itt.match_multiple_img(bigmatMat, asset.IconBigmapDomain.image, threshold=0.98)
ret = match_multiple_img(bigmatMat, asset.IconBigmapDomain.image, threshold=0.98)
return np.asarray(ret)

def get_middle_gs_point(stop_func):
Expand All @@ -154,7 +154,7 @@ def get_middle_gs_point(stop_func):
Returns:
list: [x,y]
"""
a = itt.capture(jpgmode=0)
a = itt.capture(jpgmode=NORMAL_CHANNELS)
b = get_gs_points(a, stop_func)
b = np.asarray(b)
c = euclidean_distance_plist([1080/2,1920/2],b)
Expand All @@ -172,7 +172,7 @@ def get_closest_teleport_waypoint(object_img: img_manager.ImgIcon):
_type_: _description_
"""
return calculate_nearest_posi(
itt.match_multiple_img(itt.capture(jpgmode=0), object_img.image),
match_multiple_img(itt.capture(jpgmode=NORMAL_CHANNELS), object_img.image),
get_navigation_posi())

def reset_map_size():
Expand Down Expand Up @@ -229,12 +229,12 @@ def nearest_big_map_tw_posi(current_posi, target_posi, stop_func, include_gs = T
Returns:
_type_: 最近的传送锚点坐标
"""
twpoints = np.array(get_tw_points(itt.capture(jpgmode=0), stop_func)) # 获得所有传送锚点坐标
twpoints = np.array(get_tw_points(itt.capture(jpgmode=NORMAL_CHANNELS), stop_func)) # 获得所有传送锚点坐标
if include_gs:
twpoints = np.concatenate((twpoints, get_gs_points(itt.capture(jpgmode=0), stop_func)))
twpoints = np.concatenate((twpoints, get_gs_points(itt.capture(jpgmode=NORMAL_CHANNELS), stop_func)))
if include_dm:
if len(get_dm_points(itt.capture(jpgmode=0), stop_func)) > 0:
twpoints = np.concatenate((twpoints, get_dm_points(itt.capture(jpgmode=0), stop_func)))
if len(get_dm_points(itt.capture(jpgmode=NORMAL_CHANNELS), stop_func)) > 0:
twpoints = np.concatenate((twpoints, get_dm_points(itt.capture(jpgmode=NORMAL_CHANNELS), stop_func)))
if len(twpoints) == 0:
return []
twpoints_teyvat = twpoints.copy() # 拷贝
Expand All @@ -254,9 +254,9 @@ def nearest_teyvat_tw_posi(current_posi, target_posi, stop_func, include_gs = Tr
Returns:
_type_: _description_
"""
twpoints = np.array(get_tw_points(itt.capture(jpgmode=0), stop_func)) # 获得传送锚点坐标
twpoints = np.array(get_tw_points(itt.capture(jpgmode=NORMAL_CHANNELS), stop_func)) # 获得传送锚点坐标
if include_gs:
twpoints = np.concatenate((twpoints, get_gs_points(itt.capture(jpgmode=0), stop_func)))
twpoints = np.concatenate((twpoints, get_gs_points(itt.capture(jpgmode=NORMAL_CHANNELS), stop_func)))
twpoints_teyvat = twpoints.copy() # copy
twpoints_teyvat = bigmap_posi2teyvat_posi(current_posi, twpoints_teyvat) # 转换为提瓦特坐标
p = np.argmin(euclidean_distance_plist(target_posi, twpoints_teyvat))
Expand Down
12 changes: 6 additions & 6 deletions source/funclib/combat_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def extract_red(img):
return arrow_img

def get_enemy_arrow_direction():
orsrc = itt.capture()
orsrc = itt.capture(jpgmode=FOUR_CHANNELS)
arrow_img = get_arrow_img(orsrc.copy())
ret_contours = img_manager.get_rect(arrow_img, orsrc, ret_mode=3)
# ret_range = img_manager.get_rect(imsrc2, orsrc, ret_mode=0)
Expand Down Expand Up @@ -248,7 +248,7 @@ def combat_statement_detection():
# return: ret[0]: blood bar; ret[1]: enemy arrow
ret = [False,False]

im_src = itt.capture()
im_src = itt.capture(jpgmode=FOUR_CHANNELS)
orsrc = im_src.copy()
blood_bar_img = get_enemy_blood_bar_img(orsrc.copy())

Expand Down Expand Up @@ -294,7 +294,7 @@ def combat_statement_detection():
return ret

def get_chara_blood():
img = itt.capture(jpgmode=0,posi=asset.AreaCombatBloodBar.position)
img = itt.capture(jpgmode=NORMAL_CHANNELS,posi=asset.AreaCombatBloodBar.position)
img = extract_white_letters(img, threshold=251)
t = ocr_light.get_all_texts(img)
t2 = ','.join(str(i) for i in t).replace(',','')
Expand Down Expand Up @@ -326,7 +326,7 @@ def get_chara_blood_percentage():

def is_character_healthy():
if ui_control.verify_page(UIPage.page_main):
img = itt.capture(jpgmode=0)
img = itt.capture(jpgmode=NORMAL_CHANNELS)
if IS_DEVICE_PC:
col = img[1011,847]
target_col = [35,215,150]
Expand All @@ -335,7 +335,7 @@ def is_character_healthy():
def get_characters_name(max_retry = 50):
retry_times = 0
for retry_times in range(max_retry):
cap = itt.capture(jpgmode=0)
cap = itt.capture(jpgmode=NORMAL_CHANNELS)
# img = extract_white_letters(cap)
img = cap
ret_list = []
Expand Down Expand Up @@ -368,7 +368,7 @@ def get_team_chara_names_in_party_setup():
text_list = []
for i in [asset.AreaCombatPartySetupCharaName1,asset.AreaCombatPartySetupCharaName2,
asset.AreaCombatPartySetupCharaName3,asset.AreaCombatPartySetupCharaName4]:
img = itt.capture(jpgmode=0, posi=i.position)
img = itt.capture(jpgmode=NORMAL_CHANNELS, posi=i.position)
img2 = extract_white_letters(img)
text = ocr.get_all_texts(img2)
text_list.append(text[0])
Expand Down
2 changes: 1 addition & 1 deletion source/funclib/generic_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def recover_all(stop_func):
gsp = big_map.get_middle_gs_point(stop_func)
itt.move_and_click(gsp)
time.sleep(0.5)
p1 = ocr.get_text_position(itt.capture(jpgmode=0), "七天神像")
p1 = ocr.get_text_position(itt.capture(jpgmode=NORMAL_CHANNELS), "七天神像")
if p1 != -1:
itt.move_and_click([p1[0] + 30, p1[1] + 30], delay=1)

Expand Down
16 changes: 8 additions & 8 deletions source/funclib/movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ def change_view_to_angle(tangle, stop_func=lambda: False, maxloop=25, offset=5,

def view_to_angle_domain(angle, stop_func, deltanum=0.65, maxloop=100, corrected_num=CORRECT_DEGREE):
if IS_DEVICE_PC:
cap = itt.capture(posi=small_map.posi_map)
cap = itt.capture(posi=small_map.posi_map, jpgmode=FOUR_CHANNELS)
degree = small_map.jwa_3(cap)
i = 0
if not abs(degree - (angle - corrected_num)) < deltanum:
logger.debug(f"view_to_angle_domain: angle: {angle} deltanum: {deltanum} maxloop: {maxloop} ")
while not abs(degree - (angle - corrected_num)) < deltanum:
degree = small_map.jwa_3(itt.capture(posi=small_map.posi_map))
degree = small_map.jwa_3(itt.capture(posi=small_map.posi_map, jpgmode=FOUR_CHANNELS))
# print(degree)
cview((degree - (angle - corrected_num)))
time.sleep(0.05)
Expand All @@ -229,7 +229,7 @@ def view_to_angle_domain(angle, stop_func, deltanum=0.65, maxloop=100, corrected

def view_to_imgicon(cap: np.ndarray, imgicon: asset.ImgIcon):
corr_rate = 1
ret_points = itt.match_multiple_img(cap, imgicon.image)
ret_points = match_multiple_img(cap, imgicon.image)
if len(ret_points) == 0: return False
points_length = []
for point in ret_points:
Expand Down Expand Up @@ -317,16 +317,16 @@ def preprocessing(img):
mask = cv2.inRange(hsv, lower_white, upper_white)
return mask

cap = itt.capture()
cap = itt.capture(jpgmode=FOUR_CHANNELS)
cap = preprocessing(cap)
img1 = crop(cap.copy(), IconMovementClimb.cap_posi)
r1 = itt.similar_img(img1, IconMovementClimbing.image[:, :, 0])
r1 = similar_img(img1, IconMovementClimbing.image[:, :, 0])
img1 = crop(cap.copy(), IconMovementSwim.cap_posi)
r2 = itt.similar_img(img1, IconMovementSwimming.image[:, :, 0])
r2 = similar_img(img1, IconMovementSwimming.image[:, :, 0])
# cv2.imshow('flying', img1)
# cv2.waitKey(1)
img1 = crop(cap.copy(), IconMovementFly.cap_posi)
r3 = itt.similar_img(img1, IconMovementFlying.image[:, :, 0])
r3 = similar_img(img1, IconMovementFlying.image[:, :, 0])
if max(r1, r2, r3) > 0.8:
logger.trace(f"get_current_motion_state: climb{round(r1, 2)} swim{round(r2, 2)} fly{round(r3, 2)}")
if r1 > 0.85:
Expand Down Expand Up @@ -370,7 +370,7 @@ def move_to_posi_LoopMode(target_posi, stop_func, threshold=6):
time.sleep(0.2)
change_view_to_angle(90)
# print(genshin_map.get_rotation())
# cap = itt.capture(jpgmode=0)
# cap = itt.capture(jpgmode=NORMAL_CHANNELS)
# ban_posi=asset.IconCommissionCommissionIcon.cap_posi
# cap[ban_posi[1]:ban_posi[3],ban_posi[0]:ban_posi[2]]=0
# print(view_to_imgicon(cap, asset.IconCommissionInCommission))
Expand Down
6 changes: 3 additions & 3 deletions source/funclib/small_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ def jwa_3(imsrc, alpha_threshold = 503): # 503


def teyvat_smallmap_crusade_target_search(itt: interaction_core.InteractionBGD, imgicon):
imsrc = itt.capture(posi=posi_teyvat_map)
imsrc = itt.capture(posi=posi_teyvat_map, jpgmode=FOUR_CHANNELS)
imsrc = itt.png2jpg(imsrc, channel='ui')
img_target = imgicon.image
r, pp = itt.similar_img(imsrc, img_target, ret_mode=interaction_core.IMG_POSI)
r, pp = similar_img(imsrc, img_target, ret_mode=interaction_core.IMG_POSI)
p = [0, 0]
p[0] = pp[0] + img_target.shape[1] / 2
p[1] = pp[1] + img_target.shape[0] / 2
Expand Down Expand Up @@ -180,7 +180,7 @@ def teyvat_smallmap_crusade_target_search(itt: interaction_core.InteractionBGD,
if __name__ == '__main__':
# qshow(itt.capture(posi=posi_map))
while 1:
r = jwa_3(itt.capture(posi=posi_map))
r = jwa_3(itt.capture(posi=posi_map, jpgmode=FOUR_CHANNELS))
# print(r)
# teyvat_smallmap_crusade_target_search(itt)
time.sleep(0.1)
Expand Down
4 changes: 2 additions & 2 deletions source/interaction/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Capture():
def __init__(self):
self.capture_cache = np.zeros_like((1080,1920,3), dtype="uint8")
self.max_fps = 180
self.max_fps = 180 # 60 or 30 may be better
self.fps_timer = timer_module.Timer(diff_start_time=1)
self.capture_cache_lock = threading.Lock()
self.capture_times = 0
Expand All @@ -35,7 +35,7 @@ def _check_shape(self, img:np.ndarray):
return False


def capture(self, is_next_img = False, recapture_limit = 0) -> np.ndarray:
def capture(self, is_next_img = False, recapture_limit:float = 0) -> np.ndarray:
"""
is_next_img: 强制截取下一张图片
"""
Expand Down
Loading

0 comments on commit 579dd7f

Please sign in to comment.