C# 中的模板匹配
我想获取网页中特定图像的坐标(X,Y)。获取该图像坐标后,我将光标移动到该位置并以编程方式单击该图像。
我已将图像保存在本地,我必须进行比较,我将将此图像与网页进行比较并找到其在网页中的位置。 怎么可能
如果这在 C# 中不可能,那么这在 C# 中 ?有人会建议我在这种情况下进行任何黑客攻击吗?
I want to get the coordinates(X,Y) of specific image in a web page.After getting that image coordinates I shall move the cursor to this position and click programmatically over this image.
I have saved the image locally I have to compare I will compare this image with the web page and find its location in web page.
how is this possible in C#
if this is not possible in C#. Will anybody suggest me any hack in this scenario,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
任何网页都是特定于客户端浏览器的。您无法在 C# 中执行此操作,因为 C# 是一种服务器语言,在服务器上运行,然后以浏览器特定语言返回结果。每个客户端都有不同的分辨率,因此图像的位置也不同。为了获取图像的坐标,您需要使用 JavaScript,然后将指针移动到该位置。您可以使用 jQuery 并获取图像位置。
Any webpage is client's browser specific. You can't do that in C# since C# is a server language and runs at server and then returns the results in browser specific language. Each client will have different resolution and hence different position for the image. In order to get the coordinates of the image you'll need to use javascript and then move your pointer to that location. You can use jQuery and get image position.
AForge 中的模板匹配是通过 ExhaustiveTemplateMatch 类完成的:
http://www.aforgenet.com/framework/docs/html/17494328-ef0c-dc83-1bc3-907b7b75039f.htm
但您首先需要匹配浏览器窗口的屏幕截图。
Template Matching in AForge is done with the ExhaustiveTemplateMatch class:
http://www.aforgenet.com/framework/docs/html/17494328-ef0c-dc83-1bc3-907b7b75039f.htm
But you would first need the screenshot of the browser window to match to.
据我了解,您想要在浏览器上模拟点击事件,以显示包含您的图像的页面。如果是这样,你可以这样做 -
句柄是目标浏览器窗口句柄,(x,y)是要模拟单击的位置 - 可以是图像矩形的中心。
As I understand you want to simulate a click event on a browser that displays a page containing your image. If so, you can do somthing like this -
handle is target browser window handle, and (x, y) is the location where click is to be simulated - can be the center of your image rect.
我会使用纯 JavaScript 从网页获取信息。
如果需要相对于视口的位置:
如果需要在不使用鼠标的情况下对图像执行 onClick 操作:
要使用 C# 调用 JavaScript,您需要创建一个 WebBrowser 控件,加载网页,然后调用脚本。 您可以在此处了解如何执行此操作。
< href="http://msdn.microsoft.com/en-us/library/4b1a88bz.aspx" rel="nofollow noreferrer">MSDN 文档HtmlDocument.InvokeScript
I would use plain JavaScript to get the information from the web page.
If you need the position relative to the viewport:
If you need to perform the onClick action on the image without using the mouse:
To invoke JavaScript using C#, you'll need to create a WebBrowser control, load the web page, then invoke the script. You can find how to do that here.
MSDN documentation for HtmlDocument.InvokeScript