User Tools

Site Tools


Sidebar

en:objects:webpage:work_img:get_pos_in_webpage_picture

get_pos_in_webpage_picture

get_pos_in_webpage_picture($picture_filepath,$similar_koeff=0.95,$similar_algoritm=5); - get coordinates of the specified image on the current page (available from version 7.0.3)

The function accepts parameters as input:

  • $picture_filepath – path to the image file
  • $similar_koeff – similarity coefficient (from 0 to 1) - available from version 7.0.3
  • $similar_algoritm – similarity search algorithm (from 0 to 5) - available from version 7.0.3 :
    • 0 - R(x,y)=sumx',y'[T(x',y')-I(x+x',y+y')]2 - Squared difference (the difference in the square)
    • 1 - R(x,y)=sumx',y'[T(x',y')-I(x+x',y+y')]2/sqrt[sumx',y'T(x',y')2 sumx',y'I(x+x',y+y')2] - (normalized difference in square)
    • 2 - R(x,y)=sumx',y'[T(x',y') I(x+x',y+y')] - Cross correlation (a correlation)
    • 3 - R(x,y)=sumx',y'[T(x',y') I(x+x',y+y')]/sqrt[sumx',y'T(x',y')2 sumx',y'I(x+x',y+y')2] - Normalized cross correlation)
    • 4 - R(x,y)=sumx',y'[T'(x',y') I'(x+x',y+y')], where T'(x',y')=T(x',y') - 1/(wxh) sumx",y"T(x",y") I'(x+x',y+y')=I(x+x',y+y') - 1/(wxh) sumx",y"I(x+x",y+y") - Cosine coefficient)
    • 5 - R(x,y)=sumx',y'[T'(x',y') I'(x+x',y+y')]/sqrt[sumx',y'T'(x',y')2 sumx',y'I'(x+x',y+y')2] - Normalized cosine coefficient (normalized cosine coefficient)
After testing, the function returns the result of its work to the script :
  • pos – coordinates of the specified image on the page (XHEPosition : pos->x and pos->y)

    PHP example:

    <?php $xhe_host = "127.0.0.1:7013";
     
    //connect the object to control the emulator, if not already connected
    if(!isset($path))
      $path = "../../../Templates/xweb_human_emulator.php";
    require($path);
     
    //Start
    echo "<hr> <font color = blue> webpage->".basename(__FILE__)."</font> <hr>";
     
    //screenshot name
    $screen_name = "test/kak.bmp";
    if($browser->get_model() == "chromium")
      $screen_name = "test/kak1.bmp";
     
    //1
    echo "1.Let's go to the site from which we have a screenshot:";
    echo $browser->navigate("http://bigfozzy.com")."<br>";
     
    //2
    echo "2.Get the coordinates of the picture in the browser picture:";
    $pos = $webpage->get_pos_in_webpage_picture($screen_name);
    echo "upper left corner of picture $pos->x x $pos->y <br>";
     
    //3
    echo "3.Let's go to the given place:";
    echo $mouse->move($pos->x, $pos->y)."<br>";
    sleep(7);
     
    //4
    echo "4.Let's go to the site, from which we have a screenshot:";
    echo $browser->navigate("https://vk.com/soft_seo")."<br>";
     
    //five
    echo "5.Get the coordinates of the picture in the browser picture:";
    $pos = $webpage->get_pos_in_webpage_picture($screen_name, 0.86,4);
    echo "upper left corner of picture $pos->x x $pos->y <br>";
     
    //6
    echo "6.Let's go to the given place:";
    echo $mouse->move($pos->x, $pos->y)."<br>";
     
    //end
    echo "<hr> <br>";
     
    //Quit
    $app->quit();
    ?>

    Python example:

    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
     
    xhe_host = "127.0.0.1:7070"
    from xweb_human_emulator import *
     
    # Start
    echo("<hr> <font color = blue> webpage.xxxxxxxxx </font> <hr>")
     
    # screenshot name
    screen_name = "test \ kak.bmp"
    if browser.get_model() == "chromium":
      screen_name = "test \ kak1.bmp"
     
    # 1
    echo("1.Let's go to the site from which we have a screenshot:")
    echo(browser.navigate("http://bigfozzy.com"), "<br>")
     
    # 2
    echo("2.Get the coordinates of the picture in the browser picture:")
    pos = webpage.get_pos_in_webpage_picture(screen_name)
    echo("upper left corner of picture" + str(pos.x) + "x" + str(pos.y) + "<br>")
     
    # 3
    echo("3.Click on the given location:")
    echo(mouse.move(pos.x, pos.y), "<br>")
     
    # 4
    echo("4.Let's go to the site from which we have a screenshot:")
    echo(browser.navigate("http://vk.com"), "<br>")
     
    # five
    echo("5.Get the coordinates of the picture in the browser picture:")
    pos = webpage.get_pos_in_webpage_picture(screen_name, 0.8,4)
    echo("upper left corner of picture" + str(pos.x) + "x" + str(pos.y) + "<br>")
     
    # 6
    echo("6.Click on the given location:")
    echo(mouse.move(pos.x, pos.y), "<br>")
     
    # end
    echo("<hr> <br>")
     
    # Quit
    app.quit()

    C# example:

    #region using
     
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
     
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
     
    using System.Drawing;
     
    #endregion
     
     class Program: XHEScript
     {
    static void Main(string [] args)
    {
    //init XHE
    server = "127.0.0.1:7070";
    InitXHE();
     
    //Start
    echo("<hr> <font color = blue> webpage.get_x_in_webpage_picture </font> <hr>");
     
    //screenshot name(link Briefly)
    string screen_name = "test \ kak.bmp";
    if(browser.get_model() == "chromium")
    screen_name = "test \ kak1.bmp";
     
    //1 step
    echo("1.Let's go to the site, from which we have a screenshot:");
    echo(browser.navigate("http://bigfozzy.com/") + "<br>");
     
    //step 2
    echo("2.Get the coordinates of the picture in the browser picture:");
    Point pos = webpage.get_pos_in_webpage_picture(screen_name);
    echo("upper left corner of the picture" + pos.X + "x" + pos.Y + "<br>");
     
    //step 3
    echo("3.Let's go to the given location:");
    echo(mouse.move(pos.X, pos.Y) + "<br>");
                sleep(2);
     
    //step 4
    echo("4.Let's go to the site, from which we have a screenshot:");
    echo(browser.navigate("vk.com") + "<br>");
     
    //step 5
    echo("5.Get the coordinates of the picture in the browser picture:");
    pos = webpage.get_pos_in_webpage_picture(screen_name, 0.9,0);
    echo("upper left corner of the picture" + pos.X + "x" + pos.Y + "<br>");
     
    //6 step
    echo("6.Let's go to the given location:");
    echo(mouse.move(pos.X, pos.Y) + "<br>");
     
    //end
    echo("<hr> <br>");
     
    app.quit();
    }
    }

    Java Script example:

    //connect the object to control the emulator, if not already connected
    xhe_host = "127.0.0.1:7070";
    echo = require("../../../Templates JS/xweb_human_emulator.js");
     
    //Start
    echo("<hr> <font color = blue> webpage.get_y_in_webpage_picture </font> <hr>");
     
    //screenshot name
    screen_name = "test \ kak.bmp";
    if(browser.get_model() == "chromium")
      screen_name = "test \ kak1.bmp";
     
    //1 step
    echo("1.Let's go to the site, from which we have a screenshot:");
    echo(browser.navigate("http://bigfozzy.com") + "<br>");
     
    //step 2
    echo("2.Get the coordinates of the picture in the browser picture:");
    var pos = webpage.get_pos_in_webpage_picture(screen_name);
    echo("upper left corner of the picture" + pos.x + "x" + pos.y + "<br>");
     
    //step 3
    echo("3.Click on the given location:");
    echo(mouse.move(pos.x, pos.y) + "<br>");
    app.sleep(2);
     
    //step 4
    echo("4.Let's go to the site, from which we have a screenshot:");
    echo(browser.navigate("http://vk.com") + "<br>");
     
    //step 5
    echo("5.Get the coordinates of the picture in the browser picture:");
    var pos = webpage.get_pos_in_webpage_picture(screen_name, 0.9,0);
    echo("upper left corner of the picture" + pos.x + "x" + pos.y + "<br>");
     
    //step 6
    echo("6.Click on the given location:");
    echo(mouse.move(pos.x, pos.y) + "<br>");
     
    //end
    echo("<hr> <br>");
     
    //Quit
    app.quit();
  • en/objects/webpage/work_img/get_pos_in_webpage_picture.txt · Last modified: 2020/10/13 18:51 (external edit)