一个轻量级的包,用于检测 windows 用户计算机上的 chrome、firefox、edge 和 opera 浏览器
项目描述
模板匹配研究
该项目的主要目的是创建一个轻量级脚本,可以检测用户屏幕上的浏览器。需要检测的浏览器有chrome、firefox、edge、opera。该项目将用作检测浏览器的 API。该项目在Adrian Rosebrock 的imutils 库和他的模板匹配优化的帮助下利用了OpenCV 库。
安装
使用pip包管理器安装脚本。
pip install templateMatchResearch
或者
git clone https://github.com/emire1/TemplateMatchResearch
用法
from browsers_detector import *
auto_detect_taskbar() # returns True if a browser is detected
detect_desktop("chrome") # moves mouse to location of browser and return True if browser is detected
detect_taskbar("opera") # moves mouse to location of browser and return True if browser is detected
使用 browser_detector 登录 BlackBoard
# This automatically detects any browser on the desktop
# to open it and go to the blackboard link.
from object_detection import *
import pyautogui
from time import sleep
detection = auto_detect_desktop()
if detection is False:
pyautogui.hotkey("win", "d")
detection = auto_detect_desktop()
if detection is False:
print()
else:
open_link("brockport.edu")
else:
open_link("brockport.edu")
更新
这仍然是一个持续的项目,大部分时间都会更新,不幸的是,截至目前,这仅在 Windows 操作系统上进行了测试
功能
抓取屏幕():
该函数截取屏幕截图并将其保存到“data/screenshots”文件夹中,并保存为“screen_shot.JPG”。这也会将图像转换为灰度,检测图像的边缘并将其返回进行检测。
grab_screen()
# returns image
加载模板(图像):
image = 位于“data/templates”文件夹中的任何文件的名称
此函数从“模板”文件夹中获取图像文件,将其读取为灰度,检测边缘并将其返回以进行检测。如果有错误,则返回 None。
load_template("chrome_taskbar.JPG")
# returns template or None if there is an error
start_scaling_match(模板,屏幕截图,比例,阈值):
template = load_template() 方法的返回值。
screen_shot = grab_screen() 方法的返回值。
scale = 默认值为“u”,表示放大,可以更改为“d”以缩小。这用于确定是否应在检测过程中放大主图像。
threshold = 阈值决定是否检测到图像。默认值为 .30
该函数接受模板对象、screen_shot 对象、比例值和阈值。该函数采用模板匹配算法,优化了OpenCV 库中的模板匹配函数。该算法基本上是在应用模板匹配函数并将匹配的值与阈值进行比较时放大或缩小,直到该值大于或等于阈值,然后是匹配的位置或坐标(x,y)以 False 的布尔值 (next_image) 返回。如果该值小于阈值,则位置将为 (0,0),next_image 布尔值为 True。next_image 用于确定是否应该使用不同的图像来检测浏览器。
template = load_template("chrome_desktop.JPG")
screen_shot = grab_screen()
start_scaling_match(template, screen_shot, "d", .75)
# if image is found returns x, y, next_image=False else return 0, 0, next_image=True
# or
# it could be called like:
start_scaling_match(load_template("chrome_taskbar.JPG"), grab_screen(), "d", .50)
过程(模板,规模):
template = 浏览器的实际文件名
scale = 默认值为“u”,表示放大,可以更改为“d”以缩小。这用于确定是否应在检测过程中放大主图像。
此函数调用 load_template()、grab_screen() 和 start_scaling_match() 将它们组合在一起以获得匹配在屏幕上的绝对位置和一个布尔值。它接受一个模板对象和一个比例值来确定在匹配过程中图像是放大还是缩小。
process("chrome_taskbar.JPG", "u")
# returns x, y of match and next_image=False if a match is found.
自动检测任务栏():
此功能将自动检测 Windows 任务栏上的任何浏览器。如果找到匹配项,则鼠标指针将移动到匹配项的位置,并返回一个布尔值 True。如果不匹配,则返回 False。
auto_detect_taskbar()
# returns True if the match is found and False if the match is not found
自动检测桌面():
此功能将自动检测 Windows 桌面上的任何浏览器。如果找到匹配项,则鼠标指针将移动到匹配项的位置,并返回一个布尔值 True。如果不匹配,则返回 False。
auto_detect_taskbar()
# returns True if the match is found and False if the match is not found
检测任务栏(浏览器):
browser = 任何浏览器的名称(chrome、opera、edge、firefox)
此函数将尝试检测 Windows 任务栏上的浏览器,如果找到,它将返回 True 并将鼠标指针移动到匹配的位置。如果没有找到匹配项,它将返回 False。
detect_taskbar("chrome")
# returns True if a match is found and False if there were no matches.
检测桌面(浏览器):
browser = 任何浏览器的名称(chrome、opera、edge、firefox)
此函数将尝试检测 Windows 桌面上的浏览器,如果找到,它将返回 True 并将鼠标指针移动到匹配的位置。如果没有找到匹配项,它将返回 False。
detect_desktop("firefox")
# returns True if a match is found and False if there were no matches.
打开链接(网址):
url = 要输入到浏览器中的实际 url
此函数在浏览器中自动输入链接并转到 url。如果 url 为空,则返回 false,否则返回 True。
open_link("brockport.edu")
# returns False if url is empty and returns True if the url is not empty
open_with_start(网址):
url = 要输入到浏览器中的实际 url
该功能在开始菜单中自动输入链接,并使用系统默认浏览器打开网址。如果 url 为空,则返回 false,否则返回 True。
open_with_start("suny.brockport.edu")
# returns False if url is empty and returns True if the url is not empty
发送电子邮件(消息,标题):
message = 要发送的消息 title = 消息的标题。默认值为 "" 或空字符串
此函数尝试在用户登录其黑板帐户后发送电子邮件
send_email("Hello World!", "Hello!")
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。