image I want to detect edges from: click here edges drawn by finding canny edges in program: click here I am using the opencv library with processing so that I can perform edge detection in order to split my image into different objects / components. I have been able to achieve this using canny edge detection. This gives me a second image of a black background with grey lines representing where edges have been detected. However, I then need to be able to separate this black image with edges into recognizable regions / objects that the program will understand as being different - I was thinking if I could assign a unique color for each region bounded by an edge. Then I would be able to loop through the whole image's pixel array and treat each region differently depending on its unique color.
However, my problem is that I do not know how to get processing to assign a unique color for each region which is bounded by an edge. I have tried using for loops in countless ways so that it can find and assign different regions but no matter what I try it hasn't worked. Was wondering if anyone has any solutions? Here is the code:
import gab.opencv.*;
import processing.video.*;
OpenCV opencv;
Capture src;
PImage canny, ref, comb, comb2, tiles;
color [] combColour = new color [0];
int c = 0;
int threshold = 20;
int a = 100;
int b = 100;
int x = 0;
int y = 0;
Boolean dir = true;
int ydirection = 1;
int xdirection = 1;
void setup(){
src = new Capture(this, 640, 480);
size(640, 480, P2D);
src.start();
ref = createImage(width/2, height/2, HSB);
tiles = loadImage("tiles2.png");
opencv = new OpenCV(this, tiles);
opencv.findCannyEdges(20, 75);
canny = opencv.getSnapshot();
}
void draw(){
updatePixels();
src.read();
loadPixels();
pushMatrix();
image(tiles, 0, 0, width/2, height/2);
opencv.loadImage(tiles);
opencv.findCannyEdges(20, 75);
canny = opencv.getSnapshot();
image(canny, 0, height/2, width/2, height/2);
if (c == 5){
comb = get(0, height/2, width/2, height/2);
comb2 = get(0, height/2, width/2, height/2);
}
if ( c >= 5){
comb.loadPixels();
int loc = x + y*comb.width;
color currentColor = comb.pixels[loc];
if (brightness(currentColor) < 10){
comb.pixels[loc] = color(hue(a), saturation(b), brightness(currentColor));
}
else if (brightness(currentColor) > 150){
comb.pixels[loc] = currentColor;
if ( a >= 235){
a = 0;
}
else{
a += 20;
}
if ( b >= 235){
b = 0;
}
else {
b += 20;
}
}
if (y >= comb.height -1){
x += 1;
y = 0;
println("one" + x);
}
else{
y += 1;
println("two" + y);
}
println("a " + a);
comb.updatePixels();
image(comb, width/2, height/2);
image(comb2, width/2, 0);
}
popMatrix();
updatePixels();
c += 1;
}