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 Board Package. The example highlights on video the QR code markers and prints on the serial monitor the coordinates of the markers found.
Hardware Required
Omnivision OV5647 camera
microHDMI to HDMI cable or adaptor
Monitor with HDMI input
Circuit
There is no circuit for this example.
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.
- start recognition algorithmvoid begin()
- stops recognitionvoid end()
- change video modevoid setMode(uint8_t mode);
- set recognition thresholdvoid setThr(uint8_t thr);
- perform qr code recognitionint readQRCode(void);
- structure containing detected pointssQrDet qr;
1#include "VidorGraphics.h"2#include "VidorCamera.h"3
4VidorCamera vcam;5
6#define MAXDIM 107
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 line28
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 camera42
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 recognition56
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 screen71
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
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.