i have an irl card that has the rgb value:11, 96, 133.
i made a code that, scans the screen for that color so when you have the app camera open it says kaart gevonden (found card in dutch) on the screen. but it is not working, any ideas why?
here is the code
int x=1;
int y=1;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
color pas = color(11, 96, 133);
Robot robot;
void setup() {
size(1500, 3000);
try {
robot = new Robot();
}
catch (Exception e) {
println(e.getMessage());
}
}
void draw() {
background(0);
Rectangle r = new Rectangle(y, x, width, height);
BufferedImage img1 = robot.createScreenCapture(r);
PImage img2 = new PImage(img1);
image(img2, 0, 0);
get(x,y);
x++;
y++;
color colorFromGet = get(x,y);
if(colorFromGet==(colorFromGet+pas)/2){
textSize(50);
text("kaart gevonden", width/2, height/2);
}
}
screen capture a small area at the center of your display monitor
display the image at the center of the sketch window
check for color(0xFF, 0xFF, 0xFF) (white) at the center of the sketch window
I used white so I can move a window in and out of capture area
it will display "“kaart gevonden” if white is at center
// Screen Scanner
// v1.0.0
// GLV 2021-06-07
// Adapted from:
// http://www.magicandlove.com/blog/tag/screen-capture/
// https://discourse.processing.org/t/screencapture-with-robot-class-code-not-working/30551
int x=1;
int y=1;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
color pas = color(0xFF, 0xFF, 0xFF);
Robot robot;
void setup()
{
size(500, 600);
try
{
robot = new Robot();
}
catch (Exception e)
{
println(e.getMessage());
}
}
void draw()
{
background(0);
Rectangle r = new Rectangle(displayWidth/2-100, displayHeight/2-100, 300, 400);
BufferedImage img1 = robot.createScreenCapture(r);
PImage img2 = new PImage(img1);
imageMode(CENTER);
image(img2, width/2, height/2);
//get(x,y); // Not used in this code!
//x++;
//y++;
color colorFromGet = get(width/2, height/2); //Gets color from center of sketch window
// Examples of what you can do here:
//color colorFromGet = get(x, y);
//color colorFromGet = get(mouseX, mouseY);
if(colorFromGet == pas)
{
textSize(50);
fill(0, 255, 0);
textAlign(CENTER, CENTER);
text("kaart gevonden", width/2, height/2);
println("kaart gevonden");
}
println(frameRate);
println(hex(get(mouseX, mouseY))); //Gets color from mosue location and displays as hex
}
I just did a quick exploration of this; there are certainly other ways to do this.
You will have to go through code line by line and understand it.
Modify it as you wish.
I provided you with a tool to display the colors on the screen to get a sense of them:
println(hex(get(mouseX, mouseY))); //Gets color from mouse location and displays as hex
You can use this to get more of the color details and then write some code for that. println(hex(c), red(c), green(c), blue(c), hue(c), saturation(c), brightness(c)); //Gets color from mouse location and displays as hex
I found hue() to be useful and got this working for a range of hues (desktop folder in a screen capture in my case).
You are going to have to read the Processing color tutorial and look through color references and examples.