counting array without draw loop
in
Programming Questions
•
2 years ago
((disclaimer : i will delete all related posts prior to this one to stop confusion))
hello guys, im working on a tree mapper, and during the night, i realised how to identify certain patterns of colours that a tree top would have. so now i have a bunch of points that represent where trees are located. the next thing BIG THING i need to do is to combine near points into one. BUT for the moment, im stuck at the
- ArrayList pts = new ArrayList();
- PVector point = new PVector(x, y);
- pts.add(point);
- for (int n : pts.size)
- {
- total += n;
- }
- println(total);
part, for some reason, the points arnt grouping up ..? or that i cant access the PVector array? im not really sure what is going on there.
below is the complete code:
- ArrayList[][] pts;
- PImage img;
- int count;
- int n;
- int num;
- void setup() {
- size(542, 166);
- background(255);
- img = loadImage("test small 1.jpg");
- image(img, 0, 0);
- }
- void draw() {
- img.loadPixels();
- for (int y = 7; y < height-7; y++) {
- for (int x = 7; x < width-7; x++) {
- // int loc1 = x - 5 + (y-5)*width;
- // int loc2 = x + (y-6)*width;
- // int loc3 = x + 5 + (y-5)*width;
- // int loc4 = x - 3 + (y-3)*width;
- // int loc5 = x + (y-3)*width;
- // int loc6 = x + 3 + (y-3)*width;
- int loc7 = x - 6 + y*width;
- int loc8 = x - 3 + y*width;
- int loc9 = x + y*width;
- int loc10 = x + 3 + y*width;
- int loc11 = x + 6 + y*width;
- // int loc12 = x - 3 + (y+3)*width;
- // int loc13 = x + (y+3)*width;
- // int loc14 = x + 3 + (y+3)*width;
- // int loc15 = x - 5 + (y+5)*width;
- // int loc16 = x + (y+6)*width;
- // int loc17 = x + 5 + (y+5)*width;
- /*
- float r1 = red(img.pixels[loc1]);
- float g1 = green(img.pixels[loc1]);
- float b1 = blue(img.pixels[loc1]);
- float r2 = red(img.pixels[loc2]);
- float g2 = green(img.pixels[loc2]);
- float b2 = blue(img.pixels[loc2]);
- float r3 = red(img.pixels[loc3]);
- float g3 = green(img.pixels[loc3]);
- float b3 = blue(img.pixels[loc3]);
- float r4 = red(img.pixels[loc4]);
- float g4 = green(img.pixels[loc4]);
- float b4 = blue(img.pixels[loc4]);
- float r5 = red(img.pixels[loc5]);
- float g5 = green(img.pixels[loc5]);
- float b5 = blue(img.pixels[loc5]);
- float r6 = red(img.pixels[loc6]);
- float g6 = green(img.pixels[loc6]);
- float b6 = blue(img.pixels[loc6]);
- */
- float r7 = red(img.pixels[loc7]);
- float g7 = green(img.pixels[loc7]);
- float b7 = blue(img.pixels[loc7]);
- float r8 = red(img.pixels[loc8]);
- float g8 = green(img.pixels[loc8]);
- float b8 = blue(img.pixels[loc8]);
- float r9 = red(img.pixels[loc9]);
- float g9 = green(img.pixels[loc9]);
- float b9 = blue(img.pixels[loc9]);
- float r10 = red(img.pixels[loc10]);
- float g10 = green(img.pixels[loc10]);
- float b10 = blue(img.pixels[loc10]);
- float r11 = red(img.pixels[loc11]);
- float g11 = green(img.pixels[loc11]);
- float b11 = blue(img.pixels[loc11]);
- /*
- float r12 = red(img.pixels[loc12]);
- float g12 = green(img.pixels[loc12]);
- float b12 = blue(img.pixels[loc12]);
- float r13 = red(img.pixels[loc13]);
- float g13 = green(img.pixels[loc13]);
- float b13 = blue(img.pixels[loc13]);
- float r14 = red(img.pixels[loc14]);
- float g14 = green(img.pixels[loc14]);
- float b14 = blue(img.pixels[loc14]);
- float r15 = red(img.pixels[loc15]);
- float g15 = green(img.pixels[loc15]);
- float b15 = blue(img.pixels[loc15]);
- float r16 = red(img.pixels[loc16]);
- float g16 = green(img.pixels[loc16]);
- float b16 = blue(img.pixels[loc16]);
- float r17 = red(img.pixels[loc17]);
- float g17 = green(img.pixels[loc17]);
- float b17 = blue(img.pixels[loc17]);
- */
- if (
- /*
- r1 < 190+10 && g1 < 130+10 && b1 < 80+10
- && r2 < 30+10 && g2 < 50+10 && b2 < 17+10
- && r3 < 135+10 && g3 < 160+10 && b3 < 120+10
- && r4 < 120+10 && g4 < 140+10 && b4 < 95+10
- && r5 < 100+10 && g5 < 130+10 && b5 < 90+10
- && r6 < 110+10 && g6 < 130+10 && b6 < 100+10
- */
- r7 < 130 && g7 < 150 && b7 < 110
- && r8 < 95 && g8 < 115 && b8 < 85
- && r9 < 40 && g9 < 60 && b9 < 35
- && r10 < 105 && g10 < 120 && b10 < 85
- && r11 < 120 && g11 < 140 && b11 < 105
- /*
- && r12 < 40+10 && g12 < 60+10 && b12 < 30+10
- && r13 < 55+10 && g13 < 70+10 && b13 < 50+10
- && r14 < 125+10 && g14 < 140+10 && b14 < 105+10
- && r15 < 60+10 && g15 < 80+10 && b15 < 45+10
- && r16 < 95+10 && g16 < 110+10 && b16 < 85+10
- && r17 < 60+10 && g17 < 70+10 && b17 < 50+10
- */
- )
- {
- noFill();
- stroke(255, 0, 0);
- point(x, y);
- ArrayList pts = new ArrayList();
- PVector point = new PVector(x, y);
- pts.add(point);
- for (int n : pts.size)
- {
- total += n;
- }
- println(total);
- }
- }
- }
- }
here is the accompanying image
yun
1