当前位置: 首页 > news >正文

网站策划总结wordpress点赞功能纯代码

网站策划总结,wordpress点赞功能纯代码,做维修那个网站发布信息好,杜桥做网站哪家好安装库 pip install Pillow pip install opencv-python confidence作用 confidence 参数是用于指定图像匹配的信度(或置信度)的,它表示图像匹配的准确程度。这个参数的值在 0 到 1 之间,数值越高表示匹配的要求越严格。 具体来…

安装库 

pip install Pillow
pip install opencv-python

confidence作用

confidence 参数是用于指定图像匹配的信度(或置信度)的,它表示图像匹配的准确程度。这个参数的值在 0 到 1 之间,数值越高表示匹配的要求越严格。
具体来说,confidence 参数用于调整在屏幕上搜索目标图像时的匹配精度:
0.0 表示完全不匹配。
1.0 表示完全匹配。
在实际应用中,图像匹配的信度可以帮助你处理一些图像上的细微差异。例如,屏幕上的图像可能因为分辨率、光线、颜色等原因与原始图像有些不同。通过调整 confidence 参数,你可以设置一个合理的阈值,使得图像匹配过程既不太严格(导致找不到图像),也不太宽松(导致误匹配)。
举个例子,如果你设置 confidence=0.8,那么只有当屏幕上的图像与目标图像的相似度达到 80% 以上时,才会被认为是匹配的。

识别图片点击

import pyautogui
import time
import osdef locate_and_click_image(image_path, retry_interval=2, max_retries=5, click_count=1, confidence=None):"""定位图片并点击指定次数。:param image_path: 图片路径:param retry_interval: 重试间隔时间(秒):param max_retries: 最大重试次数:param click_count: 点击次数:param confidence: 图像匹配的信度(0到1之间),需要安装 OpenCV:return: 图片的位置 (x, y, width, height) 或 None(如果未找到)"""if not os.path.isfile(image_path):print(f"错误:图片路径无效或文件不存在: {image_path}")return Noneretries = 0while retries < max_retries:try:if confidence is not None:location = pyautogui.locateOnScreen(image_path, confidence=confidence)else:location = pyautogui.locateOnScreen(image_path)if location is not None:print(f"找到图片: {image_path},位置: {location}")center = pyautogui.center(location)for _ in range(click_count):pyautogui.click(center)print(f"点击图片中心位置。点击次数:{_ + 1}")return locationelse:print(f"未找到图片: {image_path},{retry_interval}秒后重试...(重试次数: {retries + 1}/{max_retries})")time.sleep(retry_interval)retries += 1except pyautogui.ImageNotFoundException:print(f"未找到图片: {image_path},{retry_interval}秒后重试...(重试次数: {retries + 1}/{max_retries})")time.sleep(retry_interval)retries += 1print(f"达到最大重试次数: {max_retries},未找到图片: {image_path}")return Nonedef main():image_path = '1.png'  # 替换为你的图片路径retry_interval = 2max_retries = 5click_count = 1confidence = 0.8  # 如果不使用 OpenCV,请将此参数设置为 Nonelocation = locate_and_click_image(image_path, retry_interval, max_retries, click_count, confidence)if location:print("操作完成。")else:print("未能定位到图片,程序结束。")if __name__ == "__main__":locate_and_click_image('1.png', retry_interval=2, max_retries=5, click_count=2, confidence=0.8)

优化代码,识别多张图片并点击

import pyautogui
import time
import osdef locate_and_click_image(path, retry_interval=2, max_retries=5, click_count=1, confidence=None):if not os.path.isfile(path):print(f"错误:图片路径无效或文件不存在: {path}")return Noneretries = 0while retries < max_retries:try:if confidence is not None:location = pyautogui.locateOnScreen(path, confidence=confidence)else:location = pyautogui.locateOnScreen(path)if location is not None:print(f"找到图片: {path},位置: {location}")center = pyautogui.center(location)for _ in range(click_count):pyautogui.click(center)print(f"点击图片中心位置。点击次数:{_ + 1}")return locationelse:print(f"未找到图片: {path},{retry_interval}秒后重试...(重试次数: {retries + 1}/{max_retries})")time.sleep(retry_interval)retries += 1except pyautogui.ImageNotFoundException:print(f"未找到图片: {path},{retry_interval}秒后重试...(重试次数: {retries + 1}/{max_retries})")time.sleep(retry_interval)retries += 1print(f"达到最大重试次数: {max_retries},未找到图片: {path}")return Nonedef main():images = [{'path': '1.png', 'retry_interval': 2, 'max_retries': 5, 'click_count': 1, 'confidence': 0.8},{'path': '3.png', 'retry_interval': 2, 'max_retries': 5, 'click_count': 1, 'confidence': 0.8},# 添加更多图片]for image in images:location = locate_and_click_image(**image)if location:print(f"图片 {image['path']} 操作完成。")else:print(f"未能定位到图片 {image['path']},程序结束。")if __name__ == "__main__":main()

优化代码,识别多张图片,只要识别到图片就结束循环

import pyautogui
import time
import osdef locate_and_click_image(path, retry_interval=2, max_retries=5, click_count=1, confidence=None):if not os.path.isfile(path):print(f"错误:图片路径无效或文件不存在: {path}")return Noneretries = 0while retries < max_retries:try:if confidence is not None:location = pyautogui.locateOnScreen(path, confidence=confidence)else:location = pyautogui.locateOnScreen(path)if location is not None:print(f"找到图片: {path},位置: {location}")center = pyautogui.center(location)for _ in range(click_count):pyautogui.click(center)print(f"点击图片中心位置。点击次数:{_ + 1}")return Trueelse:print(f"未找到图片: {path},{retry_interval}秒后重试...(重试次数: {retries + 1}/{max_retries})")time.sleep(retry_interval)retries += 1except pyautogui.ImageNotFoundException:print(f"未找到图片: {path},{retry_interval}秒后重试...(重试次数: {retries + 1}/{max_retries})")time.sleep(retry_interval)retries += 1print(f"达到最大重试次数: {max_retries},未找到图片: {path}")return Falsedef main():images = [{'path': '1.png', 'retry_interval': 2, 'max_retries': 5, 'click_count': 1, 'confidence': 0.8},{'path': '3.png', 'retry_interval': 2, 'max_retries': 5, 'click_count': 1, 'confidence': 0.8},{'path': '4.png', 'retry_interval': 2, 'max_retries': 5, 'click_count': 1, 'confidence': 0.8},# 添加更多图片]for image in images:success = locate_and_click_image(**image)if success:print(f"图片 {image['path']} 操作完成。")breakelse:print(f"未能定位到图片 {image['path']}。")if __name__ == "__main__":main()

如有帮助,请多多支持作者! 你鼓励是我最大的动力~QAQ~

http://www.yayakq.cn/news/395725/

相关文章:

  • 做自媒体搬运文章的网站支部品牌建设实施方案
  • 张家口百度免费做网站用discuz做商城网站
  • 网络班级网站建设优化大师apk
  • 高明网站设计收费创意设计图片
  • 怎么查找网站是谁做的网址查询ip解析
  • 青海网站开发建设wordpress标签字段
  • 网站开发制作费用网络营销是什么模式
  • 电商网站开发周期wordpress前端插件
  • 网站建设注意要点网站开发教程收费版
  • wordpress怎么禁google潍坊关键词优化软件
  • 肇庆网站建设cz0758织梦网站模板制作
  • 做年会的网站做网站 租服务器
  • iview可以做门户网站吗网站设计团队分工
  • 长沙建网站一般要多少钱wordpress网址转跳页面插件
  • 网站制作计划书有哪些网站做的比较好
  • 丝绸之路网站建设意义网站建设公司价位
  • seo关键词排名优化app重庆seo优化公司哪家好
  • 湖南住房和城乡建设网站wordpress 文章添加字段
  • 网站建设需要步骤wordpress网站不显示系列
  • 有名的wordpress网站网站建设解决
  • 手机网站设计图标qq是哪个公司
  • 拓吧网站wordpress自动采集软件
  • 有了阿里云服务器怎么做网站360郑州房产网
  • 宁波网页网站制作热点军事新闻
  • 商务网站建设论文答辩ppt中国建筑装饰网排行
  • 个人网站可以做点什么企业投资建设公益性项目
  • 企业网站文章后台添加做幼儿手工网站
  • 北京中心网站建设国外虚拟主机 两个网站
  • 瑞安电影城网站建设即墨网站建设
  • 营销型网站建设大千番茄网络营销策划方案