Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleBeispiel QR-Code Generieren
collapsetrue
import diewald_bardcode.*;
import diewald_bardcode.CONSTANTS.*;

int code_size = 500;
String content = "http://iad.zhdk.ch";

void setup() 
{
  size(code_size, code_size);

  EncodingResult result = Barcode.encode(content, ENCODE.QR_CODE, code_size, code_size, CHARACTER_SET.DEFAULT, ERROR_CORRECTION.DEFAULT);
  if( result.encodingFailed() )   {
    println( result.getEncodingException() );
  } else 
  {
    result.setBgColor(255, 255, 255, 255);
    result.setCodeColor(0, 0, 0, 255);
  
    PImage barcode = result.asImage(this);
    if ( barcode != null) {
      image(barcode, 0, 0);
    }
      
    barcode.save("qrcode.jpg");
  }
}

void draw()  {
}
Code Block
languagejava
titleBeispiel QR-Code Lesen
collapsetrue
import diewald_bardcode.*;
import diewald_bardcode.CONSTANTS.*;
import processing.video.*;

Capture video;

void setup()  {
  size(1140, 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);
        ellipse(0, 0, 20, 20);
        line(0, 0, -10, 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) {

 float returnValue;
  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);
  returnValue =return p3.heading()+PI/2;
  return returnValue;
}

Fiducials