Page 34
Sample program for decoding a QR code
This sample program is a demo that uses QR scanning Channel 1 for detecting and decoding a QR code
when one is present in the camera field of view.
From the
Motors and Sensors .. Camera
screen,
aim your camera at this code and verify it is being seen on Channel 1.
Now compile and run the sample program to find out what the QR data is.
Code
// Assume channel 1 is for identifying QR codes
// If a QR code is found, it is translated
int
main() {
int
i, lngth;
camera_open(LOW_RES);
// activate camera
camera_update();
// get most recent camera image and process it
while
(side_button()==
0
) {
if
(get_object_count(
1
) >
0
) {
// there is a QR code in view
display_printf(0,1,
"QR code: "
);
lngth = get_object_data_length(
1
,
0
);
// print QR code letter by letter until end of data
for
(i=
0
; i < lngth; i++) {
display_printf(9+i,1,
"%c"
, get_object_data(
1
,
0
)[i]);
}
}
else
{
display_printf(0,1,
"No QR code detected "
);
}
msleep(
200
);
// don't rush print statement update
camera_update();
// get new image data before repeating
}
}
Содержание KIPR Link
Страница 1: ...KIPR Link Manual Version BB2014 1 1...