# QR code recognition is required in'Android'. Is there no workaround?

**URL:** <https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129>\
**Category:** Processing for Android\
**Tags:** homework\
**Created:** [February 28, 2021, 2:15am UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129 "2021-02-28T02:15:26Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [February 28, 2021, 2:15am UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/1 "2021-02-28T02:15:26Z")

</div>

QR code recognition is required in’Android’. Is there no workaround?

Reference link: [QR CODE library for Processing 3.0.2 Windows/Linux/MacOSX/Android.. writeQR() and readQR(). - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/15572/qr-code-library-for-processing-3-0-2-windows-linux-macosx-android-writeqr-and-readqr)

When implemented in the above way,

![photo](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/35d85cc897da0a4c15ba5191f63b37e7761108a6.jpeg)  
If you link with the actual smartphone cam, that photo should be recognized.  
However, that photo is not recognized by the QR code.

![qr1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0f47342b1cfebd62f5ec2f122d6aac7130a60e6f.png)  
Only those fixed images and only accurate images can be interpreted.

Is there any solution? Is there any way to receive and recognize ketai cam photo data?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [February 28, 2021, 9:08am UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/2 "2021-02-28T09:08:48Z")

</div>

this should give you camera data.

```auto
int w = 1400,h = 580;

PShader edges;
KetaiCamera cam;
float counter;
boolean mdown;

void settings(){
  size(w,h,P2D);
};

void setup() {
  orientation(LANDSCAPE);
  imageMode(CENTER);
  
  int n = 2;
  cam = new KetaiCamera(this, 1200*n, (280)*n, 60);
  frameRate(60);
}

void draw() {
  background(0);
  logic();
  if (frameCount>100&&!cam.isStarted()){cam.start();}
  image(cam, width/2, height/2);
  fill(0);
  text(frameRate,10,10);
  text(counter,100,10);
}

void onCameraPreviewEvent(){
  cam.read();
}

// start/stop camera preview by tapping the screen
void mousePressed(){
  if (cam.isStarted()){
    cam.stop();
  }else cam.start();
};

```

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [February 28, 2021, 7:17pm UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/3 "2021-02-28T19:17:37Z")

</div>

@GWAK ===  
I dont know to do that with Ketai but you can use the android native wy to display the camera data into a surfaceView; after that you have only to use the android mobile vision API and its barcode detector to get the code as a string, which can be passed as an url: tested, it works fine.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [February 28, 2021, 7:34pm UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/4 "2021-02-28T19:34:21Z")

</div>

Via Ketai camera

1. In recognizing the QR code on the screen of the camera
2. Fixed image is recognized by QR code,
3. Real-time video is not recognized.

@akenaton

> Hello. Thank you for answer. We would appreciate if you could give us the source code url.  
> Thank you.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [March 1, 2021, 5:42pm UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/5 "2021-03-01T17:42:25Z")

</div>

@GWAK === as for video within a surface view you can find on the forum many examples with code i have already given ; as for the barcode detector you can refer to the android API mobile vision importing some packages:

```auto
import com.google.android.gms.vision.CameraSource;
import com.google.android.gms.vision.Detector;
import com.google.android.gms.vision.barcode.Barcode;
import com.google.android.gms.vision.barcode.BarcodeDetector;

dont forget permissions for camera

```

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [March 1, 2021, 11:28pm UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/6 "2021-03-01T23:28:17Z")

</div>

Dear akenaton, @akenaton

Thank you for your kind answer.  
However, I can’t find your previous posts in the forums.  
Please tell me the’url address’ that contains the content of the test.

I can’t find it in the’Forum’. help me.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [March 2, 2021, 5:44pm UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/7 "2021-03-02T17:44:28Z")

</div>

@GWAK ===  
see here: [https://discourse.processing.org/t/play-videos-in-my-apps/23707](https://discourse.processing.org/t/play-videos-in-my-apps/23707)

– of course buttons and sliders are not useful for your app; what is important is the surfaceView (and perhaps the way to load your video)

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [March 2, 2021, 11:11pm UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/8 "2021-03-02T23:11:30Z")

</div>

@akenaton

I know what you mean.  
However, if you’ve solved it, you share the code, please.  
I need a code that recognizes’QR’, not video.

If you have any sample code, please share it.  
Thank you.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [March 3, 2021, 6:06pm UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/9 "2021-03-03T18:06:04Z")

</div>

@GWAK === the barcode dtector from android works with a video and from the video recognizes the barcode

---

<div class="post-metadata">

**Author:** ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)\
**Post date:** [December 7, 2022, 9:35pm UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/10 "2022-12-07T21:35:31Z")

</div>

Hello, do you need this code? I just fixed the zxing4p library to work on android. If you need it, I can share the project with you.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [December 7, 2022, 11:05pm UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/11 "2022-12-07T23:05:20Z")

</div>

@erkosone

Required.

Thank you for sharing. Thank you for your interest.

---

<div class="post-metadata">

**Author:** ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)\
**Post date:** [December 8, 2022, 6:06am UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/12 "2022-12-08T06:06:30Z")

</div>

Hi and good morning!  
I prepare an example to share.

---

<div class="post-metadata">

**Author:** ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)\
**Post date:** [December 8, 2022, 6:23am UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/13 "2022-12-08T06:23:51Z")

</div>

Hello, here is an example program, the original library that I have used is ZXING4P, I have modified one of the methods used to read QR codes and I have translated it to be compatible with the “android.graphics” framework libraries. Bitmap".

Basically the modification deals with building a Bitmap in android with the data from the PImage and then manually dumping the array of pixels from the PImage into the bitmap, everything that follows the process is the same as in windows and linux.

This also works for the video Stram example out there where it sends live webcam video over the network, with this way of creating a Bitmap on Android you could also use Daniel Shiffman’s library to send live video from the android phone.

It would be great if the creators of these libraries added the compatibility modifications to the libraries officially 😉

[[Dropbox - QRdecoderAndroid.zip - Simplify your life](https://www.dropbox.com/s/7zmmh4dr8x9s9we/QRdecoderAndroid.zip?dl=0)]([https://Project](https://Project) example)

---

<div class="post-metadata">

**Author:** ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)\
**Post date:** [December 8, 2022, 8:53am UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/14 "2022-12-08T08:53:48Z")

</div>

Hola, ahora mismo estoy trabajando en el port completo de la libreria zxing4processing 2.0.  
En esta version la libreria pretende ofrecer todo lo que ofrecia antes mas todas las funcionalidades portadas al sistema operativo Android para nuestro querido Processing 4.x.x.

En cuanto la pueda tener lista la publicare, es una simple actualizacion de la que ya existe que funciona super bien, la libreria no es mia originalmente, yo solo voy a actualizarla para ser compatible con Android 😉

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [December 8, 2022, 1:13pm UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/15 "2022-12-08T13:13:38Z")

</div>

@erkosone

Thanks for sharing the source code.  
Thank you sincerely.

Interpretation works really well. (decodeQRPImage)  
However, (encodeQRPImage) does not work.

```auto
PImage img;
PImage qr_make;
PImage qr_make_copy;
String msg = "zxing4processing library";
void setup() {
   size(displayWidth,displayHeight);
   img = loadImage("000.jpg");
   println("DECODED TEXT(1):", decodeQRPImage(img));    
   img = loadImage("001.png");
   println("DECODED TEXT(2):", decodeQRPImage(img));  
    
   qr_make = encodeQRPImage(msg,800,800);
   qr_make_copy = qr_make.get(0,0,800,800);    
    
}
void draw(){
  
 background(150); imageMode(CENTER);
 
 if(qr_make_copy != null){
   println(" qr_make_copy not null");
   println(" qr_make_copy width : "+str(qr_make_copy.width));
   println(" qr_make_copy height : "+str(qr_make_copy.height));   
   image(qr_make, round(width/2), round(0));
   image(qr_make_copy, round(width/2), round(height/2));
   
 }else{
   println(" qr_make_copy null");
 }
 noLoop();
 
}

```

```auto
DECODED TEXT(1): This is an example of the decodeImage() method
(zxing4processing library)
DECODED TEXT(2): goldstarit
 qr_make_copy not null
 qr_make_copy width : 800
 qr_make_copy height : 800

```

The image created by qr exists in size. but not marked I don’t know why.

---

<div class="post-metadata">

**Author:** ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)\
**Post date:** [December 12, 2022, 3:14am UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/16 "2022-12-12T03:14:59Z")

</div>

Hola, aqui tienes la libreria portada al completo a Android, puedes hacer correr cualquier ejemplo de la libreria original desde Android con processing sin ningun problema 😉

Aqui la libreria original para Desktop: [CAGE Web Design | zxing4processing - Processing Library - CAGE Web Design](http://cagewebdev.com/zxing4processing-processing-library/)  
Aqui la libreria portada por mi para Android: [ZXING4P Ported to Android mode P4 ;)](https://discourse.processing.org/t/zxing4p-ported-to-android-mode-p4/40060)

Puedes cojer cualquier ejemplo de la original y hacerlo funcionar en Android 😉

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [December 13, 2022, 6:24pm UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/17 "2022-12-13T18:24:54Z")

</div>

@erkosone

I solved the problem.  
There is a color problem.I fixed it by editing the above.  
It might be useful for reference.

```auto
public PImage generateQRCode(String content, int widths, int heights) {
        PImage pImage = new PImage(widths, heights);

        QRCodeWriter encoder = new QRCodeWriter();

        try {
            BitMatrix bitMatrix = encoder.encode(content, BarcodeFormat.QR_CODE, widths, heights);

            // COPY THE BYTEMATRIX TO THE PIMAGE
            for (int i=0; i<widths; i++){
                for (int j=0; j<heights; j++) {
                    color black = color(0);
                    int colorValue = 0; // BLACK
                    if (!bitMatrix.get(j, i)) {colorValue = 16777215; black = color(255); } // WHITE
                    // ADD THE PIXEL TO THE IMAGE
                    // System.out.println(colorValue); 
                    pImage.set(i, j, black);
                } // for(int j=0; j<height; j++)
            }
        }
        catch ( Exception e ) {
            System.out.println("Error generating QRCode image (PImage generateQRCode) " + e);
        } // try

        return pImage;
    }

```

1. before modification

> pImage.set(i, j, colorValue);

1. After modification

> pImage.set(i, j, black);

It works fine. Thanks to this, it is possible to recognize and create QR codes.  
thank you.

---

<div class="post-metadata">

**Author:** ![SantosCuccia](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@SantosCuccia](https://discourse.processing.org/u/SantosCuccia)\
**Post date:** [July 3, 2023, 7:31am UTC](https://discourse.processing.org/t/qr-code-recognition-is-required-inandroid-is-there-no-workaround/28129/18 "2023-07-03T07:31:26Z")

</div>

Your question is something I haven’t been familiar with, I have learned new knowledge.
