From df186ab985e18dd4c72a22056db601dcaccf26b1 Mon Sep 17 00:00:00 2001 From: Carmine De Rosa Date: Sat, 5 Oct 2019 11:06:42 +0200 Subject: [PATCH] calibration --- ephimera/ephimera.pde | 45 +++++++++++++++++++++++++++++++---------- ephimera/frames.pde | 4 ++-- ephimera/percentage.pde | 20 +++++++++++++++--- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/ephimera/ephimera.pde b/ephimera/ephimera.pde index 0a39e8d..e773671 100644 --- a/ephimera/ephimera.pde +++ b/ephimera/ephimera.pde @@ -1,37 +1,60 @@ import processing.io.*; import processing.serial.*; -import processing.video.*; -import processing.serial.*; +//import processing.video.*; +import gohai.glvideo.*; Serial port; -Capture video; + +// ----------------------- camera --------------------------------------------------------------------------------- +//Capture video; +GLCapture video; PImage img; +boolean countingColors = false, makeBackup = false, takePicture = true; +int videoWidth = 480; +int videoHeight = 240; -int videoWidth = 640; -int videoHeight = 480; int sending = 0; void setup() { - size(640, 480, P2D); + size(480, 240, P2D); frameRate(2); colorMode(HSB, 100, 100, 100); String portName = Serial.list()[0]; port = new Serial(this, portName, 9600); - video = new Capture(this, width, height); + String[] cameras = GLCapture.list(); + video = new GLCapture(this, cameras[0], width, height, 30); video.start(); + GPIO.pinMode(4, GPIO.INPUT); + +// video = new Capture(this, width, height); +// video.start(); + background(0); + } -void draw() { - ephPercentage(); +void draw() { + ephPercentage(); + + if (GPIO.digitalRead(4) == GPIO.LOW && takePicture == true){ + takePicture = false; + video.pause(); + delay(4000); + makePicture(); + } + if(GPIO.digitalRead(4) == GPIO.HIGH && takePicture == false){ + takePicture = true; + video.start(); + } + } void keyPressed() { if (key == 'S' || key == 's') { - video.stop(); + video.pause(); makePicture(); } if (key == 'B' || key == 'b') { @@ -40,4 +63,4 @@ void keyPressed() { if (key == 'G' || key == 'g') { video.start(); } -} +} \ No newline at end of file diff --git a/ephimera/frames.pde b/ephimera/frames.pde index 24b236e..dc7f2c4 100644 --- a/ephimera/frames.pde +++ b/ephimera/frames.pde @@ -3,7 +3,7 @@ void makePicture() { img = loadImage("shot.gif"); //ephPercentage(); ephSerial(); - video.start(); + //video.start(); } void backupFrame() { @@ -13,4 +13,4 @@ void backupFrame() { nf(hour(), 2) + nf(minute(), 2) + nf(second(), 2) + ".gif"); println("color count image saved"); -} +} \ No newline at end of file diff --git a/ephimera/percentage.pde b/ephimera/percentage.pde index 6d4059a..fcf79bc 100644 --- a/ephimera/percentage.pde +++ b/ephimera/percentage.pde @@ -7,6 +7,7 @@ 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()) { @@ -36,11 +37,11 @@ void ephPercentage() { // if greater then 80% increace white counter, // if lower then 20% increace black counter, // otherwise increase color counters - if(briVal > 20 && briVal < 80) { - colorValues[constrain(int(hueVal/colorsRange),0,colorsN-3)]++; + if(briVal > 20 && briVal < 99) { + colorValues[hueCal(hueVal)]++; } else if(briVal <= 20) { colorValues[colorsN-2]++; - } else if(briVal >= 80) { + } else if(briVal >= 99) { colorValues[colorsN-1]++; } @@ -66,3 +67,16 @@ void ephPercentage() { 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; +} \ No newline at end of file