|
|
@ -2,7 +2,10 @@ int cellSize = 20; |
|
|
|
int cols = videoWidth / cellSize; |
|
|
|
int rows = videoHeight / cellSize; |
|
|
|
int cellN = (cols)*(rows); |
|
|
|
byte[] colorValues = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
|
|
|
int[] colorValues = {0, 0, 0, 0, 0, 0, 0, 0}; |
|
|
|
byte[] colorByteValues = {0, 0, 0, 0, 0, 0, 0, 0}; |
|
|
|
int colorsN = colorValues.length; |
|
|
|
float colorsRange = float(100)/float(colorsN-2); |
|
|
|
|
|
|
|
void ephPercentage() { |
|
|
|
|
|
|
@ -10,7 +13,7 @@ void ephPercentage() { |
|
|
|
video.read(); |
|
|
|
video.loadPixels(); |
|
|
|
|
|
|
|
for(int i = 0; i<colorValues.length; i++) { |
|
|
|
for(int i = 0; i<colorsN; i++) { |
|
|
|
colorValues[i] = 0; |
|
|
|
} |
|
|
|
|
|
|
@ -22,9 +25,9 @@ void ephPercentage() { |
|
|
|
int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image |
|
|
|
|
|
|
|
// Get hue and brightness values |
|
|
|
float hueVal = hue(video.pixels[loc]); |
|
|
|
float briVal = brightness(video.pixels[loc]); |
|
|
|
float satVal = saturation(video.pixels[loc]); |
|
|
|
float hueVal = constrain(hue(video.pixels[loc]),0,100); |
|
|
|
float briVal = constrain(brightness(video.pixels[loc]),0,100); |
|
|
|
float satVal = constrain(saturation(video.pixels[loc]),0,100); |
|
|
|
|
|
|
|
// Set pixel color |
|
|
|
color c = color(hueVal, satVal, briVal); |
|
|
@ -34,11 +37,11 @@ void ephPercentage() { |
|
|
|
// if lower then 20% increace black counter, |
|
|
|
// otherwise increase color counters |
|
|
|
if(briVal > 20 && briVal < 80) { |
|
|
|
colorValues[int(hueVal/8.3)]++; |
|
|
|
colorValues[constrain(int(hueVal/colorsRange),0,colorsN-3)]++; |
|
|
|
} else if(briVal <= 20) { |
|
|
|
colorValues[12]++; |
|
|
|
} else if(briVal >= 20) { |
|
|
|
colorValues[13]++; |
|
|
|
colorValues[colorsN-2]++; |
|
|
|
} else if(briVal >= 80) { |
|
|
|
colorValues[colorsN-1]++; |
|
|
|
} |
|
|
|
|
|
|
|
pushMatrix(); |
|
|
@ -52,17 +55,14 @@ void ephPercentage() { |
|
|
|
} |
|
|
|
|
|
|
|
// Print colors percentage values |
|
|
|
for(int i = 0; i<colorValues.length-2; i++) { |
|
|
|
//print(colorValues[i]/(float(cellN)/100) + "\t"); |
|
|
|
|
|
|
|
fill(color((i*8.3)+5, 100, 100)); |
|
|
|
rect(0, (i*5)+5, colorValues[i], 5); |
|
|
|
for(int i = 0; i<colorsN-2; i++) { |
|
|
|
fill(color((i*colorsRange), 100, 100)); |
|
|
|
rect(0, (i*5)+5, map(colorValues[i]/(cellN/100),0,100,0,width), 5); |
|
|
|
} |
|
|
|
|
|
|
|
fill(0); |
|
|
|
rect(0, 65, colorValues[12], 5); |
|
|
|
rect(0, 5*(colorsN-2)+5, map(colorValues[colorsN-2]/(cellN/100),0,100,0,width), 5); |
|
|
|
fill(100); |
|
|
|
rect(0, 70, colorValues[13], 5); |
|
|
|
println(""); |
|
|
|
rect(0, 5*(colorsN-1)+5, map(colorValues[colorsN-1]/(cellN/100),0,100,0,width), 5); |
|
|
|
} |
|
|
|
} |
|
|
|