pyautogui将图片存入oracle,pyautogui:继续尝试直到找到图片

importloggingimportpyautoguiaspagfromPILimportImageimporttimedefpag_suf(img,x,y,margin,clicks=0,duration=0,interval=0,debug_msg='',time_limit=None,sample_dump=None):"""

Pyautogui - Search Until Find

Searches the image indefinitely at a specific point on the screen

considering as the search area, the image size plus an expansion margin.

If found, you can click on the center of the image.

:param img: String. Fullpath image | List. List of Fullpath image

:param x: coordinate x

:param y: coordinate y

:param margin: Integer. expansion margin to expand the search area

:param clicks: Integer. number of clicks

:param duration: Float. duration of mouse movement

:param interval: Float. sleep time after click

:param time_limit: Integer. Time limit in seconds

:param debug_msg: String. Debug message to identify log

:param sample_dump: String. File name if image .bmp

:return: List. Coordinates of the center of the found image. |

False. If time_limit reached.

"""is_string=type(img)==str

list_img=[]ifis_string:list_img.append(img)else:list_img=img# Search for image at the indicated location with tolerance marginsreturn_value=Nonelogging.debug(f"{debug_msg}: Finding...")first_loop=Truestart_time=time.time()whilereturn_valueisNone:# Scape in time_limitiftime_limitisnotNone:elapsed_time=time.time()-start_timeifelapsed_time>time_limit:returnFalseelse:passelse:passiffirst_loopisFalse:time.sleep(0.5)else:first_loop=Falseforimginlist_img:im=Image.open(img)# Defining variablesimg_width,img_height=im.size

coor_x=x-img_width/2-margin

coor_y=y-img_height/2-margin

region_x=img_width+margin*2region_y=img_height+margin*2# Save collected samplescreen_sample=pag.screenshot(imageFilename=sample_dump,region=(coor_x,coor_y,region_x,region_y))return_value=pag.locate(img,screen_sample)ifreturn_valueisnotNone:# logging.debug(img)breaklogging.debug(f"{debug_msg}: Found.")click_x=coor_x+return_value[0]+img_width/2click_y=coor_y+return_value[1]+img_height/2# Click on the center of the found locationifclicks!=0:pag.click(click_x,click_y,clicks,duration=duration,interval=interval)click_arr=[]click_arr.append(click_x)click_arr.append(click_y)returnclick_arr

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值