octalmage / robotjs

Node.js Desktop Automation.
http://robotjs.io
MIT License
12.3k stars 949 forks source link

Problem with colorAt ,It's too slow #648

Open arsize opened 3 years ago

arsize commented 3 years ago

Expected Behavior

I hope to get results within 100ms

Current Behavior

It takes me half an hour

Possible Solution

I have no solution,but I guess it is the problem of the function colorAt

Steps to Reproduce (for bugs)

var bitmap = robot.screen.capture(0, 0, 1000, 1000);
var color
for (let i = 0; i < 999; i++) {
    for (let j = 0; j < 999; j++) {
        color = bitmap.colorAt(i, j);
    }
}

Context

I cannot continue with my project...

Your Environment

Azperin commented 3 years ago

You could try to use opencv, don't know if it's faster. Something like that:

const cv = require('opencv4nodejs');

let img = cv.imread(robot.screen.capture(0, 0, 1000, 1000));
let i = 1000;
let j = 1000;
let [b, g, r] = [0, 0 ,0];
while(i--) {
    while(j--) {
        [b, g, r] = img.atRaw(i, j); // BLUE GREEN RED [0-255]
    };
};
img.release();
arsize commented 3 years ago

You could try to use opencv, don't know if it's faster. Something like that:

const cv = require('opencv4nodejs');

let img = cv.imread(robot.screen.capture(0, 0, 1000, 1000));
let i = 1000;
let j = 1000;
let [b, g, r] = [0, 0 ,0];
while(i--) {
  while(j--) {
      [b, g, r] = img.atRaw(i, j); // BLUE GREEN RED [0-255]
  };
};
img.release();

Thank you. It's really helpful.