QR Code Recognition

The QR library allows you to recognize QR code markers and data.

This example shows the flexibility and power of the FPGA architecture. A QR code recognition set of APIs is included in the VidorGraphics library and the corresponding IP is in the bitstream that is loaded in the FPGA together with the sketch for the SAMD core. The example highlights on video the QR code markers and prints on the serial monitor the coordinates of the markers found.

Hardware Required

Circuit

There is no circuit for this example.

The circuit for this tutorial.
The circuit for this tutorial.

Code

Include the VidorCamera library, which is part of VidorGraphics.

#include "VidorGraphics.h"
#include "VidorCamera.h"

You have a number of functions available to manage the recognition of a QR Code. VidorQR is part of the VidorCam library; the functions are accessible with cam.qrrec.

  • void begin()
    - start recognition algorithm

  • void end()
    - stops recognition

  • void setMode(uint8_t mode);
    - change video mode

  • void setThr(uint8_t thr);
    - set recognition thresold

  • int readQRCode(void);
    - perform qr code recognition

  • sQrDet qr;
    - structure containing detected points

1#include "VidorGraphics.h"
2#include "VidorCamera.h"
3
4VidorCamera vcam;
5
6#define MAXDIM 10
7
8static uint16_t x[QR_PT_DET_NUM], y[QR_PT_DET_NUM];
9
10struct qrPtn {
11
12 uint16_t x[QR_PT_DET_NUM];
13
14 uint16_t y[QR_PT_DET_NUM];
15};
16
17static qrPtn qrBufferPtn[MAXDIM];
18
19uint16_t count = 0, last;
20
21void setup() {
22
23 Serial.begin(9600);
24
25 // wait for the serial monitor to open,
26
27 // if you are powering the board from a USB charger remove the next line
28
29 while (!Serial);
30
31 if (!FPGA.begin()) {
32
33 Serial.println("Initialization failed!");
34
35 while (1) {}
36
37 }
38
39 /**
40
41 begin() enable the I2C communication and initialize the display for the camera
42
43 */
44
45 if (!vcam.begin()) {
46
47 Serial.println("Camera begin failed");
48
49 while (1) {}
50
51 }
52
53 /**
54
55 qrrec.begin(); enable the QR code recognition
56
57 */
58
59 vcam.qrrec.begin();
60
61 delay(4000);
62
63 Serial.println("Power ON");
64}
65
66void loop() {
67
68 /**
69
70 qrrec.readQRCode(); get, if available, the coordinates of the QR code in the screen
71
72 */
73
74 vcam.qrrec.readQRCode();
75
76 for (int i = 0; i < QR_PT_DET_NUM; i++) {
77
78 if (vcam.qrrec.qr.pt[i].valid) {
79
80 x[i] = (vcam.qrrec.qr.pt[i].xs + vcam.qrrec.qr.pt[i].xe) / 2;
81
82 y[i] = (vcam.qrrec.qr.pt[i].ys + vcam.qrrec.qr.pt[i].ye) / 2;
83
84 vcam.vgfx.Cross(x[i], y[i], 65535);
85
86 }
87
88 }
89
90 last = count % MAXDIM;
91
92 for (int i = 0; i < QR_PT_DET_NUM; i++) {
93
94 vcam.vgfx.Cross(qrBufferPtn[last].x[i], qrBufferPtn[last].y[i], 0, 0);
95
96 qrBufferPtn[last].x[i] = x[i];
97
98 qrBufferPtn[last].y[i] = y[i];
99
100 }
101
102 count++;
103}

Last revision 2018/07/22 by SM

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.