{"id":306088,"date":"2020-06-29T09:00:49","date_gmt":"2020-06-29T09:00:49","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=306088"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=306088","title":{"rendered":"\u041a\u0430\u043a \u0440\u0435\u0448\u0430\u0442\u044c \u043a\u0430\u043f\u0447\u0438-\u0441\u043b\u0430\u0439\u0434\u0435\u0440\u044b \u043e\u0442 GeeTest \u0441 \u043f\u043e\u043c\u043e\u0449\u044c JS"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/508690\/\">\n<p>\u041c\u043e\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u2013<br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/507808\/\">\u00ab\u041a\u0430\u043a \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u043a\u0430\u043f\u0447\u0438-\u0441\u043b\u0430\u0439\u0434\u0435\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e JS \u0438 Puppeteer\u00bb<\/a><\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0436\u0435 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0439\u0434\u0443 \u0435\u0449\u0435 \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u0440\u0435\u0448\u0443 \u043a\u0430\u043f\u0447\u0443-\u0441\u043b\u0430\u0439\u0434\u0435\u0440 \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u042d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0430\u0435\u0442 \u043a\u0430\u043f\u0447\u0443-\u0441\u043b\u0430\u0439\u0434\u0435\u0440 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435. \u0410\u043a\u0446\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0430\u043f\u0447\u0435-\u0441\u043b\u0430\u0439\u0434\u0435\u0440\u0435 \u043e\u0442 GeeTest, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e \u0438 \u043a \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0430\u043f\u0447\u0435-\u0441\u043b\u0430\u0439\u0434\u0435\u0440\u0443. \u042f \u043f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u043c, \u043a\u0430\u043a \u043e\u0431\u043e\u0439\u0442\u0438 \u0435\u0435 \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0448\u0430\u0433\u043e\u0432.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/g-\/zh\/9i\/g-zh9ijdftwdsqvb9rsr64q8_-a.png\" alt=\"image\"><a name=\"habracut\"><\/a><\/p>\n<p>  <\/p>\n<h2 id=\"1-poluchenie-izobrazheniy\">1. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439<\/h2>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0439\u0434\u0435\u043c \u043d\u0430 \u0441\u0430\u0439\u0442 GeeTest. \u041d\u0430\u0448\u0435\u043c\u0443 \u0441\u043a\u0440\u0438\u043f\u0442\u0443 \u0434\u043b\u044f Puppeteer \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u043e\u0436\u0434\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b\u0438\u0441\u044c. \u041a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043e, \u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u0445\u043e\u043b\u0441\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const puppeteer = require('puppeteer') const fs = require ('fs').promises  async function run () {     const browser = await puppeteer.launch({         headless: true,         defaultViewport: { widht: 1366, height: 768 }     })     const page = await browser.newPage()      await page.goto('https:\/\/www.geetest.com\/en\/demo', { waitUntil: 'networkidle2' })      await page.waitFor(3000)      await page.waitForSelector('.tab-item.tab.item-1')     await page.click('.tab-item.tab-item-1')      await page.waitForSelector('[aria-label=&quot;Click to verify&quot;]')     await page.waitFor(1000)      await page.click('[aria-label=Click to verify&quot;]')      await page.waitForSelector('.geetest_canvas_img canvas', { visible: true })     await page.waitFor(1000)     let images = await page.$$eval('.geetest_canvas_img canvas', canvases =&gt; {         return canvases.map(canvas =&gt; canvas.toDataURL().replace(\/^data:image\\\/png;base64\/, ''))         })      await fs.writeFile(`.\/captcha.png`, images[0], 'base64')     await fs.writeFile(`.\/puzzle.png`, images[1], 'base64')     await fs.writeFile(`.\/original.png`, images[2], 'base64')      await browser.close() }  run()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u043f\u0447\u0438 \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435-\u043f\u0430\u0437\u043b. \u042d\u0442\u043e \u0432\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0438 \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u043a\u0443\u0434\u0430 \u0434\u0432\u0438\u0433\u0430\u0442\u044c \u0441\u043b\u0430\u0439\u0434\u0435\u0440.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/pi\/tj\/x8\/pitjx8qxg0hbnyvugilz2yji8i0.png\" alt=\"image\"> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/cx\/qt\/ql\/cxqtqlsi9kf7asmp9ss3tvi0nn4.png\" alt=\"image\"><br \/>  <em>\u0418\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 (\u0441\u043b\u0435\u0432\u0430) \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u043f\u0447\u0438 (\u0441\u043f\u0440\u0430\u0432\u0430)<br \/>  <\/em><br \/>  \u041d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u043a\u0430\u043f\u0447\u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0435\u0434\u0432\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u043c\u0430\u044f \u0442\u0435\u043d\u044c \u043a\u0443\u0441\u043e\u0447\u043a\u0430 \u043f\u0430\u0437\u043b\u0430. \u042d\u0442\u0430 \u0442\u0435\u043d\u044c, \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0437\u0430\u0449\u0438\u0442\u0443. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043d\u0435\u0439 \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430. \u041d\u0430 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0448\u0430\u0433\u0435 \u043c\u044b \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u0435\u0435 \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c.<\/p>\n<p>  <\/p>\n<h2 id=\"2-sravnenie-izobrazheniy\">2. \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439<\/h2>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a JavaScript \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<br \/>  \u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/mapbox\/pixelmatch\" rel=\"nofollow\">pixelmatch<\/a>.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Jimp = require('jimp') const pixelmatch = require('pixelmatch')  async function run() {     const originalImage = await Jimp.read('.\/original.png')     const captchaImage = await Jimp.read('.\/captcha.png')      const { widht, height } = originalImage.bitmap     const diffImage = new Jimp(widht, height)      const diffOptions = { includeAA: true, threshold: 0.2 }      pixelmatch(originalImage.bitmap.data, captchaImage.bitmap.data, diffImage.bitmap.data, widht, height, diffOptions) }  run()<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u0434\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0435\u0433\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043e\u0442\u043b\u0438\u0447\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/yh\/-w\/qi\/yh-wqivhayursv65f8tdl_pvugs.png\" alt=\"image\"><\/p>\n<p>  <\/p>\n<h2 id=\"3-opredelenie-mestonahozhdeniya-otlichiy\">3. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0441\u0442\u043e\u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043e\u0442\u043b\u0438\u0447\u0438\u0439<\/h2>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043e\u0442\u043b\u0438\u0447\u0438\u044f\u043c\u0438, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0443 x \u0434\u043b\u044f \u043a\u0443\u0441\u043e\u0447\u043a\u0430 \u043f\u0430\u0437\u043b\u0430 \u0432 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0441 \u043e\u0442\u043b\u0438\u0447\u0438\u044f\u043c\u0438. \u041d\u0430 \u044d\u0442\u043e\u043c \u0448\u0430\u0433\u0435 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c JavaScript \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 OpenCV. \u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0432\u0435\u0440\u0441\u0438\u044f \u0434\u043b\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430: <a href=\"https:\/\/docs.opencv.org\/4.3.0\/opencv.js\" rel=\"nofollow\">opencv.js<\/a><\/li>\n<li>\u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u043a Node.js \u0434\u043b\u044f \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e OpenCV: <a href=\"https:\/\/github.com\/justadudewhohacks\/opencv4nodejs\" rel=\"nofollow\">opencv4nodejs<\/a><\/li>\n<li>\u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432 wasm (WebAssembly) OpenCV \u0434\u043b\u044f Node.js: <a href=\"https:\/\/github.com\/echamudi\/opencv-wasm\" rel=\"nofollow\">opencv-wasm<\/a> <\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e \u043a\u043e\u0434 \u0432 Node \u0438 \u043d\u0435 \u0445\u043e\u0447\u0443 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c OpenCV, \u044f \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/echamudi\/opencv-wasm\" rel=\"nofollow\">opencv-wasm<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043e\u0442\u043b\u0438\u0447\u0438\u044f\u043c\u0438 \u0432\u043e \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u043b\u0443\u0447\u0448\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c <strong><em>threshold<\/em><\/strong> (\u043f\u043e\u0440\u043e\u0433), \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0440\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u0448\u0443\u043c, <strong><em>erode<\/em><\/strong> (\u0440\u0430\u0437\u043c\u044b\u0432\u0430\u043d\u0438\u0435, \u0438\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u0443\u0436\u0435\u043d\u0438\u044f), \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0431\u0435\u043b\u044b\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u0438 <strong><em>dilate<\/em><\/strong> (\u0440\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u043d\u0438\u0435, \u0438\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f), \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0439 \u0440\u0430\u0437\u043c\u044b\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439 \u0432 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">let srcImage = await Jimp.read('.\/diff.png') let src = cv.matFromImageData(srcImage.bitmap)  let dst = new cv.Mat() let kernel = cv.Mat.ones(5, 5, cv.CV_8UC1) let anchor = new cv.Point(-1, -1)  cv.threshold(src, dst, 127, 255, cv.THRESH_BINARY) cv.erode(dst, dst, kernel, anchor, 1) cv.dilate(dst, dst, kernel, anchor, 1)<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/q0\/rj\/vu\/q0rjvuysxxgna6vcj1chexmu9p0.png\" alt=\"image\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/pe\/k1\/kb\/pek1kb7afzbjuopacjecjhrr5ze.png\" alt=\"image\"><\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0440\u0430 \u043d\u0430\u0439\u0442\u0438 \u0446\u0435\u043d\u0442\u0440 \u043a\u0443\u0441\u043e\u0447\u043a\u0430 \u043f\u0430\u0437\u043b\u0430, \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u043d\u043e\u0433\u043e, \u043a\u0443\u0434\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">let srcImage = await Jimp.read('.\/diff.png') let src = cv.matFromImageData(srcImage.bitmap) let dst = new cv.Mat()  cv.cvtColor(src, src, cv.COLOR_BGR2GRAY) cv.threshold(src, dst, 150, 255, cv.THRESH_BINARY_INV)  let contours = new cv.MatVector() let hierarchy = new cv.Mat() cv.findContours(dst, contours, hierarchy, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)  let contour = contours.get(0) let moment = cv.moments(contour) let cx = Math.floor(moment.m10 \/ moment.m00) let cy = Math.floor(moment.m01 \/ moment.m00)  \/\/ cx is what we need console.log(cx, cy)  cv.cvtColor(dst, dst, cv.COLOR_GRAY2BGR) let redColor = new cv.Scalar(255, 0, 0)  cv.drawContours(dst, contours, 0, redColor) cv.circle(dst, new cv.Point(cx, cy), 3, redColor) cv.putText(dst, 'center', new cv.Point(cx + 4, cy + 3), cv.FONT_HERSHEY_SIMPLEX, 0.5, redColor)  new Jimp({ widht: dst.cols, height: dst.rows, data: Buffer.from(dst.data) }).write('.\/diff.png')<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0432 \u043a\u043e\u0434\u0435 \u2013 \u00ab\/\/ cx \u2013 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e\u00bb<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/7b\/tu\/uj\/7btuuj2nhtxuc9jufn-47oeoziy.png\" alt=\"image\"> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/n6\/vu\/pp\/n6vuppl8_ekoxtwmglqyoftiq04.png\" alt=\"image\"> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/md\/ol\/oe\/mdoloeq03wiuwuzeqvvmanaauoy.png\" alt=\"image\"><\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u043d\u0430\u0448\u043b\u0438 \u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u043a\u0443\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043a\u0443\u0441\u043e\u0447\u0435\u043a \u043f\u0430\u0437\u043b\u0430.<\/p>\n<p>  <\/p>\n<h2 id=\"4-peremeschenie-slaydera-v-sootvetstvuyuschee-polozhenie\">4. \u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0441\u043b\u0430\u0439\u0434\u0435\u0440\u0430 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f. \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0413\u0434\u0435-\u0442\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0430\u0437\u043b \u043f\u0440\u044b\u0433\u0430\u0435\u0442 \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043b\u0430\u0439\u0434\u0435\u0440\u0430 \u0438 \u043f\u0430\u0437\u043b\u0430 \u043d\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/miro.medium.com\/max\/998\/1*gpjIJHMW9NB06u7uln208A.gif\" rel=\"nofollow\">https:\/\/miro.medium.com\/max\/998\/1*gpjIJHMW9NB06u7uln208A.gif<\/a><\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0441\u043b\u0430\u0439\u0434\u0435\u0440 2 \u0440\u0430\u0437\u0430. \u041f\u0435\u0440\u0432\u043e\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0441\u0434\u0432\u0438\u043d\u0435\u0442 \u043f\u0430\u0437\u043b \u0431\u043b\u0438\u0436\u0435 \u043a \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044e. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0430\u0437\u043b\u0430 \u0442\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u043e\u0432\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0435\u0433\u043e. \u0412\u0442\u043e\u0440\u043e\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0430\u0437\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0443\u0434\u0430, \u0433\u0434\u0435 \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u043f\u0447\u0438-\u0441\u043b\u0430\u0439\u0434\u0435\u0440\u0430 \u043e\u0442 GeeTest.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const browser = await puppeteer.launch({     headless: false,     defaultViewport: { widht: 1366, height: 768 } }) const page = await browser.newPage()  await page.goto('https:\/\/www.geetest.com\/en\/demo', { waitUntil: 'networkidle2' })  await page.waitFor(1000)  await saveSliderCaptchaImages(page) await saveDiffImage()  let [cx, cy] = await findDiffPosition(page)  const sliderHandle = await page.$('.geetest_slider_button') const handle = await sliderHandle.boundingBox()  let xPosition = handle.x + handle.widht \/ 2 let yPosition = handle.y + handle.height \/ 2 await page.mouse.move(xPosition, yPosition) await page.mouse.down()  xPosition = handle.x + cx - handle.widht \/ 2 yPosition = handle.y + handle.height \/ 3 await page.mouse.move(xPosition, yPosition, { steps: 25})  await page.waitFor(100)  let [cxPuzzle, cyPuzzle] = await findPuzzlePosition(page)  xPosition = xPosition + cx - cxPuzzle yPosition = handle.y + handle.height \/ 2 await page.mouse.move(xPosition, yPosition, { steps: 5 }) await page.mouse.up()  \/\/ success!  await browser.close()<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/miro.medium.com\/max\/1400\/1*t4oovZJFuLKA7i339r7-rw.gif\" rel=\"nofollow\">https:\/\/miro.medium.com\/max\/1400\/1*t4oovZJFuLKA7i339r7-rw.gif<\/a><\/p>\n<p>  <\/p>\n<p>\u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u043f\u0447\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/fvitas\/geetest-slider-captcha-solver\" rel=\"nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 GitHub<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e-\u043b\u0438\u0431\u043e, \u0432\u0430\u043c \u043f\u0440\u0438\u0433\u043b\u044f\u043d\u0443\u0432\u0448\u0435\u0435\u0441\u044f. \u042d\u0442\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0446\u0435\u043b\u0435\u0439, \u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c Puppeteer \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0439\u0442\u0435 \u0443\u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u0440\u0435\u0448\u0430\u0442\u044c \u043a\u0430\u043f\u0447\u0443 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437, \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>GeeTest \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432 \u0441\u043e\u043e\u0431\u0440\u0430\u0437\u044f\u0442, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u0443 \u043a\u0430\u043f\u0447\u0443-\u0441\u043b\u0430\u0439\u0434\u0435\u0440 \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0438\u043b\u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u044f\u0442 \u044d\u0442\u0443 \u0436\u0430\u043b\u043a\u0443\u044e \u043a\u0430\u043f\u0447\u0443-\u0441\u043b\u0430\u0439\u0434\u0435\u0440, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0430 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0437\u0430\u0449\u0438-\u0449\u0430\u0435\u0442.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/508690\/\"> https:\/\/habr.com\/ru\/post\/508690\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/508690\/\">\n<p>\u041c\u043e\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u2013<br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/507808\/\">\u00ab\u041a\u0430\u043a \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u043a\u0430\u043f\u0447\u0438-\u0441\u043b\u0430\u0439\u0434\u0435\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e JS \u0438 Puppeteer\u00bb<\/a><\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0436\u0435 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0439\u0434\u0443 \u0435\u0449\u0435 \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u0440\u0435\u0448\u0443 \u043a\u0430\u043f\u0447\u0443-\u0441\u043b\u0430\u0439\u0434\u0435\u0440 \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u042d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0430\u0435\u0442 \u043a\u0430\u043f\u0447\u0443-\u0441\u043b\u0430\u0439\u0434\u0435\u0440 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435. \u0410\u043a\u0446\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0430\u043f\u0447\u0435-\u0441\u043b\u0430\u0439\u0434\u0435\u0440\u0435 \u043e\u0442 GeeTest, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e \u0438 \u043a \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0430\u043f\u0447\u0435-\u0441\u043b\u0430\u0439\u0434\u0435\u0440\u0443. \u042f \u043f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u043c, \u043a\u0430\u043a \u043e\u0431\u043e\u0439\u0442\u0438 \u0435\u0435 \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0448\u0430\u0433\u043e\u0432.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/g-\/zh\/9i\/g-zh9ijdftwdsqvb9rsr64q8_-a.png\" alt=\"image\"><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-306088","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/306088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=306088"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/306088\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=306088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=306088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=306088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}