Now comes the hazy part: I need to read the distance between the two outer red stripes and split it by 95 to get the unit width and then getting the binary code.
How can I do this??
As far as I know, to use dist() you have to know the point location; is there another way to get the measure?
I suppose the point are not the libraries, but their usage… probably there is some piece missing and I’m not able to fix it. On Windows I’m having some troubles with gstreamer, here’s the screenshot while running Zxing for Processing, the BarcodeReaderCam example:
@jafal thank you for your support.
Before opening this topic I discarded that solution as seems to import too many libraries and it’s unclear if it’s oriented only to QR codes.
no libraries and its multi task you can modifies it as logic analyses or any other idea by replacing the ir receiver in Arduino
there is much to learn in this sketch despite its easy arrays, drawing lines in pattern, briny conversion, serial communication, spiting, timing and much more … you can play a lot with it
i am on win 7 64 bit i download the library now its working but my pc without camera
/*
QRcode reader
Generate images from a QRcode generator such as
http://qrcode.kaywa.com/ and put them in this sketch's
data folder.
Press spacebar to read from the camera, generate an image,
and scan for barcodes. Press f to read from a file and scan.
Press s for camera settings.
Created 9 June 2007
by Tom Igoe / Daniel Shiffman
*/
import processing.video.*;
import qrcodeprocessing.*;
Capture video; // instance of the video capture library
String statusMsg = "Waiting for an image"; // a string to return messages:
// Decoder object from prdecoder library
Decoder decoder;
void setup() {
size(400, 320);
video = new Capture(this, 320, 240);
video.start();
// Create a decoder object
decoder = new Decoder(this);
}
// When the decoder object finishes
// this method will be invoked.
void decoderEvent(Decoder decoder) {
statusMsg = decoder.getDecodedString();
}
void captureEvent(Capture video) {
video.read();
}
void draw() {
background(0);
// Display video
image(video, 0, 0);
// Display status
text(statusMsg, 10, height-4);
// If we are currently decoding
if (decoder.decoding()) {
// Display the image being decoded
PImage show = decoder.getImage();
image(show, 0, 0, show.width/4, show.height/4);
statusMsg = "Decoding image";
for (int i = 0; i < (frameCount/2) % 10; i++) statusMsg += ".";
}
}
void keyReleased() {
// Depending on which key is hit, do different things:
switch (key) {
case ' ':
// Spacebar takes a picture and tests it:
// copy it to the PImage savedFrame:
PImage savedFrame = createImage(video.width, video.height, RGB);
savedFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
savedFrame.updatePixels();
// Decode savedFrame
decoder.decodeImage(savedFrame);
break;
case 'f': // f runs a test on a file
PImage preservedFrame = loadImage("qrcode.png");
// Decode file
decoder.decodeImage(preservedFrame);
break;
}
}
Well yes I tried to rerun the sketch QRCode example from QRCode library and by pressing spacebar or f it acquires the image to be read from the camera or from the file, despite of the error messages in the console.
However it seems to be working only with QR codes, I need 1D barcodes instead
if you want to process images as the sample you shown, image processing can be a fun project.
but if you want to process images from webcam, i will recommand using Zxing too. dealing with “real life” images, with poor contrast , noises, rotation artefact, color artefact and … it is really hard
and in the other hand, Zxing require only one jar:
org.apache.servicemix.bundles.zxing-3.4.1_1.jar
Get rid of the sides by finding the first black pixel in each direction
Find the size of each band by dividing pixel total width (in pixels) by expected nb of bands
sum and average pixel values of each band to determine if 0 or 1.
Of course it implies that the image is straight and the bar code centered but this can be done easily with openCV for example.
Here the code:
import java.util.Arrays;
final int bitNB = 95;
PImage barCode;
int[] singleRow;
int[] result = new int[bitNB];
int beg, end;
float stepSize;
void setup() {
barCode = loadImage("barCode.jpeg");
// Get the middle row of the picture
int midRow = barCode.height / 2;
// Extract the color value of the middle row
barCode.loadPixels();
beg = midRow * barCode.width;
end = beg + barCode.width;
singleRow = Arrays.copyOfRange(barCode.pixels, beg, end);
// Convert the value to 0 or 1
for (int i = 0; i < singleRow.length; i++) {
singleRow[i] = (singleRow[i] & 0xFF) > 125 ? 1 : 0;
}
// Find first black pixels
for (int i = 0; i < singleRow.length; i++) {
if (singleRow[i] == 0) {
beg = i;
break;
}
}
// Find last black pixels
for (int i = singleRow.length - 1; i >= 0; i--) {
if (singleRow[i] == 0) {
end = i;
break;
}
}
// Find "width" of each bar
stepSize = (float)(end - beg) / bitNB;
float left = 0;
float right = stepSize;
// Read the bar code
for (int n = 0; n < bitNB; n++) {
// Set start point
beg = floor(left);
if (left - beg > 0.6) beg++; // the width can be a float number. Consider a pixel if at least 40% is within the range
// Set end point
end = ceil(right);
if(end - right > 0.6) right--; // the width can be a float number. Consider a pixel if at least 40% is within the range
// Sum and average the value
float sum = 0;
for (int i = beg; i < end + 1; i++) {
sum += singleRow[i];
}
sum /= end - beg + 1;
// Store value in result
result[n] = sum > 0.5 ? 1 : 0;
left = right;
right += stepSize;
}
println(singleRow);
println(beg, end);
println(result);
}