You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.3 KiB
82 lines
2.3 KiB
int cellSize = 20;
|
|
int cols = videoWidth / cellSize;
|
|
int rows = videoHeight / cellSize;
|
|
int cellN = (cols)*(rows);
|
|
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() {
|
|
|
|
if (video.available()) {
|
|
video.read();
|
|
video.loadPixels();
|
|
|
|
for(int i = 0; i<colorsN; i++) {
|
|
colorValues[i] = 0;
|
|
}
|
|
|
|
for (int i = 0; i < cols; i++) {
|
|
for (int j = 0; j < rows; j++) {
|
|
|
|
int x = i*cellSize;
|
|
int y = j*cellSize;
|
|
int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image
|
|
|
|
// Get hue and brightness values
|
|
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);
|
|
|
|
// Check brightness values,
|
|
// if greater then 80% increace white counter,
|
|
// if lower then 20% increace black counter,
|
|
// otherwise increase color counters
|
|
if(briVal > 20 && briVal < 99) {
|
|
colorValues[hueCal(hueVal)]++;
|
|
} else if(briVal <= 20) {
|
|
colorValues[colorsN-2]++;
|
|
} else if(briVal >= 99) {
|
|
colorValues[colorsN-1]++;
|
|
}
|
|
|
|
pushMatrix();
|
|
translate(x+cellSize/2, y+cellSize/2);
|
|
rectMode(CENTER);
|
|
fill(c);
|
|
noStroke();
|
|
rect(0, 0, cellSize+6, cellSize+6);
|
|
popMatrix();
|
|
}
|
|
}
|
|
|
|
// Print colors percentage values
|
|
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, 5*(colorsN-2)+5, map(colorValues[colorsN-2]/(cellN/100),0,100,0,width), 5);
|
|
fill(100);
|
|
rect(0, 5*(colorsN-1)+5, map(colorValues[colorsN-1]/(cellN/100),0,100,0,width), 5);
|
|
}
|
|
}
|
|
|
|
int hueCal(float val){
|
|
int result = 0;
|
|
if(val<11){result = 0;}
|
|
if(val>=11 && val<22){result = 1;}
|
|
if(val>=22 && val<44){result = 2;}
|
|
if(val>=44 && val<56){result = 3;}
|
|
if(val>=56 && val<80){result = 4;}
|
|
if(val>=80){result = 5;}
|
|
//if(val>=90){result = 0;}
|
|
|
|
return result;
|
|
}
|