T
T
teodor7teodor72020-08-30 12:44:14
Node.js
teodor7teodor7, 2020-08-30 12:44:14

How to make screenshot opencv4nodejs + robotjs?

const cv = require('opencv4nodejs');
const robot = require('robotjs');
var Jimp = require( 'jimp' );

const findWaldo = async () => {

var screen = robot.captureScreen();
 //await screenCaptureToFile( screen );
  // Load images

//  const originalMat = await cv.imreadAsync(`${__dirname}/fone.png`);
console.log(screen);
  const originalMat = new cv.Mat(screen.image , screen.width, screen.height, cv.CV_8UC3);

  const waldoMat = await cv.imreadAsync(`${__dirname}/fire.png`);

  const matched = originalMat.matchTemplate(waldoMat, 5);

  const minMax = matched.minMaxLoc();
  const { maxLoc: { x, y } } = minMax;


  originalMat.drawRectangle(
    new cv.Rect(x, y, waldoMat.cols, waldoMat.rows),
    new cv.Vec(0, 255, 0),
    1,
    cv.LINE_8
  );

  cv.imshow('We\'ve found Waldo!', originalMat);
  cv.waitKey();

};

Result
5f4b749cbe4f8033431204.png

You need to make a desktop screen and find the object on it.
How can I get a full image, for recognition. At the same time, do not save the file but work with the buffer?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question