Processing 3+ webcam test – OpenCV, outlining, filters and blend randomizer. -Kenneth Udut

Processing 3+ webcam test – OpenCV, outlining, filters and blend randomizer. – Kenneth Udut

 

import gab.opencv.*;
import processing.video.*;

PGraphics pg;
Capture video;
OpenCV opencv;

ArrayList<Contour> contours;
int verticalscan = 90;
int horizontalscan = 90;
int i;
int j;
int threeDdepth = 0;
String blendtype = “BLEND”;
//String filtertype = “”;
String myFile = String.valueOf(day()) + String.valueOf(month()) + String.valueOf(year()) + String.valueOf(int(random(1000)));

int colora = 0;
int colorb = 255;
int colorc = 0;
PShape globe;
//float mySaveScale = 300/72.0;
int number = 0;

void setup() {
size(640, 480, P3D);
video = new Capture(this, 320, 240);
opencv = new OpenCV(this, 320, 240);
pg = createGraphics(640,480, P3D, “camstream.png”);

video.start();
}

void draw() {
myDrawing(this.g);
};

//was void draw()
void myDrawing(PGraphics pg) {
scale(2);
background(0);
opencv.loadImage(video);

//  opencv.findCannyEdges(30, 95);
//  opencv.findCannyEdges(70, 40);

opencv.findCannyEdges(verticalscan, horizontalscan);

//  opencv.invert();

//scaled output
//image(opencv.getOutput(), 0, 0 );

contours = opencv.findContours(); //finding contours to the canny filtered one

noFill();
for (Contour contour : contours) {

//
colora = int(random(255));
colorb = int(random(255));
colorc = int(random(255));

stroke(colora, colorb, colorc);

beginShape();
for (PVector point : contour.getPoints()) {

// texture(video);
//     vertex(point.x, point.y, int(random(-50)));

vertex(point.x, point.y);
// vertex(point.x, point.y,-36);
//s vertex(point.x, point.y,36);

//  pg.vertex(point.x, point.y, int(random(-3)));
}

endShape();

}

//  translate(width / 4, height / 4);
//  rotateY(map(mouseX, 0, width, -PI, PI));
//  rotateZ(PI/6);
//  beginShape();
//  texture(video);
//  vertex (-100, -100, 0, 0, 0);
//  vertex (100, -100, 0, 400, 0);
//  vertex (100, 100, 0, 400, 400);
//  vertex (-100, 100, 0, 0, 400);
//  endShape();

//blend(video, 0,0,320,240,0,0,640,480,i);

switch(i) {
case 1:
blend(video,0,0,320,240,0,0,640,480,BLEND);
blendtype = “BLEND”;
break;
case 2:
blend(video,0,0,320,240,0,0,640,480,ADD);
blendtype = “ADD”;
break;
case 3:
blend(video,0,0,320,240,0,0,640,480,SUBTRACT);
blendtype = “SUBTRACT”;
break;
case 4:
blend(video,0,0,320,240,0,0,640,480,DARKEST);
blendtype = “DARKEST”;
break;
case 5:
blend(video,0,0,320,240,0,0,640,480,LIGHTEST);
blendtype = “LIGHTEST”;
break;
case 6:
blend(video,0,0,320,240,0,0,640,480,DIFFERENCE);
blendtype = “DIFFERENCE”;
break;
case 7:
blend(video,0,0,320,240,0,0,640,480,EXCLUSION);
blendtype = “EXCLUSION”;
break;
case 8:
blend(video,0,0,320,240,0,0,640,480,MULTIPLY);
blendtype = “MULTIPLY”;
break;
case 9:
blend(video,0,0,320,240,0,0,640,480,SCREEN);
blendtype = “SCREEN”;
break;
case 10:
blend(video,0,0,320,240,0,0,640,480,OVERLAY);
blendtype = “OVERLAY”;
break;
case 11:
blend(video,0,0,320,240,0,0,640,480,HARD_LIGHT);
blendtype= “HARD_LIGHT”;
break;
case 12:
blend(video,0,0,320,240,0,0,640,480,SOFT_LIGHT);
blendtype = “SOFT_LIGHT”;
break;
case 13:
blend(video,0,0,320,240,0,0,640,480,DODGE);
blendtype = “DODGE”;
break;
case 14:
blend(video,0,0,320,240,0,0,640,480,BURN);
blendtype = “BURN”;
break;
}

// used for test but didn’t do much so commented it out
// switch(j) {
// case 1:
// filter(THRESHOLD);
// filtertype = “THRESHOLD”;
// break;
// case 2:
// filter(GRAY);
// filtertype = “GRAY”;
// break;
// case 3:
// filter(OPAQUE);
// filtertype = “OPAQUE”;
// break;
// case 4:
// filter(INVERT);
// filtertype = “INVERT”;
// break;
// case 5:
// filter(BLUR);
// filtertype = “BLUR”;
// break;
// case 6:
// filter(ERODE);
// filtertype = “ERODE”;
// break;
// case 7:
// filter(DILATE);
// filtertype = “DILATE”;
// break;
// case 8:
// filtertype = “NONE”;
// break;
// }

text(verticalscan + ” ” + horizontalscan + ” ” + blendtype,20,20);

image(pg,640, 480);

}

void captureEvent(Capture c) {
c.read();
}

void keyPressed() {

{
//  if (key == ‘s’) {
//  println(“SAVING to test.png”);
//    PGraphics pg = createGraphics(int(width), int(height), P3D);
//  pg.beginDraw();
////    pg.scale(mySaveScale);
//  myDrawing(pg);
//   pg.save(“test.png”);
//   pg.endDraw();
//  }

if(key == ‘s’){
println(“Saving…”);
String s = “images/” + myFile + nf(number,4) +”.png”;
save(s);
number++;
println(“Done saving.”);
return;
}

int keyIndex = -1;

verticalscan = int(random(255));

horizontalscan = int(random(255));

colora = int(random(255));
colorb = int(random(255));
colorc = int(random(255));

//threeDdepth = int(random(-1000));

i = int(random(13))+1;
println(i);
//j = int(random(8));
// println(j);
println();

}

}

Leave a comment

Your email address will not be published. Required fields are marked *


7 + = fourteen

Leave a Reply