import diewald_bardcode.*;
import diewald_bardcode.CONSTANTS.*;
import processing.video.*;
Capture video;
void setup() {
size(1140640, 480);
video = new Capture(this, 640, 480, 30);
video.start();
}
void draw() {
if (video.available()) {
background(0);
video.read();
image(video, 0, 0);
// DecodingResult result = Barcode.decodeMulti(video, CHARACTER_SET.DEFAULT, true, DECODE.values());
DecodingResult result = Barcode.decode(video, CHARACTER_SET.DEFAULT, true, DECODE.QR_CODE);
// DecodingResult result = Barcode.decode(video, CHARACTER_SET.DEFAULT, true, DECODE.CODE_128);
if (!result.decodingFailed()) {
PVector center = getCenter(result);//new PVector(0, 0);
float rotation = getRotation(result);
pushMatrix();
translate(center.x, center.y);
rotate(rotation);
stroke(0);
strokeWeight(2);
ellipse(0, 0, 2050, 2050);
line(0, 0, -1025, 0);
popMatrix();
println(degrees(rotation));
}
}
}
PVector getCenter(DecodingResult result) {
PVector returnVector = new PVector(0, 0);
for (int i = 0; i < result.getCorners ().length; i++) {
returnVector.x += result.getCorners()[i].x;
returnVector.y += result.getCorners()[i].y;
}
returnVector.x /= result.getCorners().length;
returnVector.y /= result.getCorners().length;
return returnVector;
}
float getRotation(DecodingResult result) {
PVector p1 = new PVector(result.getCorners()[0].x, result.getCorners()[0].y);
PVector p2 = new PVector(result.getCorners()[1].x, result.getCorners()[1].y);
PVector p3 = p2.sub(p1);
return p3.heading()+PI/2;
} |