We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello. I'm new to processing and I decided to start with a simple script: something that allows me to identify black pixels in a picture. I have the code included below and as a checker I included the print command, just to see if the coordinates were moving forward (for loops).
Nothing is printing in my console and nothing is showing in my sketch, what am I doing wrong? Thanks in advance
void setup(){
PImage myImage = loadImage("test.jpg");
loadPixels();
size(myImage.width,myImage.height);
}
void draw(){
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; i++){
color c = get(i,j);
if (c == color(0)){
point(i,j);
print(i+","+j);
}
}
}
}
Answers
Nevermind, I found the error, problem was I was using i++ for both width and height, I made some changes to the code:
Warning: calling println too much can cause real problems
Draw is being called up to 60 times a second. You probably don't want this. So use noLoop()
Thanks @koogs. I uploaded the resutl here: https://www.youtube.com/watch?v=cLZt0GYTxzw
Post the changed code. I think there are some serious inefficiencies in your code still, based on the YouTube clip.
Also you don't want to load the image OR calculate color(0) Or for every pixel. Try this
Thanks Quark, I'll try that!
Koogs, Here's my final code, before Quark's comments:
Also, before reading your previous comments, I went ahead and did some more changes. Now, instead of replacing black pixels with a rect, I'm replacing pixels with fonts and using the original image's color as reference.
The result: https://drive.google.com/file/d/0BwTV1gIcOedwLXdPUzE0cUQyWUU/view?usp=sharing