Extracting text from QR Codes

OpenMV related project discussion.
kaz
Posts: 2
Joined: Tue Feb 13, 2018 7:39 am

Extracting text from QR Codes

Postby kaz » Tue Feb 13, 2018 8:30 am

Hello there,

Can anyone help me with my simple project? I'm very new on the OpenMV M7. I just need to move a mini servo depending on the text read on the QR Code.

I've used the sample QR Code and the text on the QR is printed on the "payload". How can i extract the payload and use it as a variable to move the servo by a certain degrees?

Code: Select all

import sensor, image, time
from pyb import Servo

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
    for code in img.find_qrcodes():
        img.draw_rectangle(code.rect(), color = (255, 0, 0))
        print(code)
    if (code == "LEFT"): 
    	s1 = pyb.Servo(1)
        s1.angle(45)
I'm pretty sure that the last if statement doesn't work. How do I proceed with this? Your help is greatly appreciated.
User avatar
kwagyeman
Posts: 1397
Joined: Sun May 24, 2015 2:10 pm

Re: Extracting text from QR Codes

Postby kwagyeman » Tue Feb 13, 2018 12:39 pm

Do:

Code: Select all

codes = img.find_qrcodes()
for code in codes:
        img.draw_rectangle(code.rect(), color = (255, 0, 0))
        print(code)
if codes:
    if code[0].payload == "LEFT":
        s1 = pyb.Servo(1)
        s1.angle(45)
This extracts the text for the first QR code seen.

The find QR codes method returns a list of objects, so, I put the list in a variable above, then look at the first object in the list and get the payload of it. I check to make sure the list is not empty first however.
Nyamekye,
kaz
Posts: 2
Joined: Tue Feb 13, 2018 7:39 am

Re: Extracting text from QR Codes

Postby kaz » Wed Feb 14, 2018 7:11 am

kwagyeman wrote:
Tue Feb 13, 2018 12:39 pm
Do:

Code: Select all

codes = img.find_qrcodes()
for code in codes:
        img.draw_rectangle(code.rect(), color = (255, 0, 0))
        print(code)
if codes:
    if code[0].payload == "LEFT":
        s1 = pyb.Servo(1)
        s1.angle(45)
This extracts the text for the first QR code seen.

The find QR codes method returns a list of objects, so, I put the list in a variable above, then look at the first object in the list and get the payload of it. I check to make sure the list is not empty first however.
Thanks for the help but I've come up into an error while trying the code you provided me. The error that appeared says "AttributeError: 'int' object has no attribute 'payload'.

Can you help me again? Here's the full code, and while it displays the error it highlights the line of the code: if code[0].payload == "LEFT":

Code: Select all

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    img.lens_corr(1.8)
    print(clock.fps())
    codes = img.find_qrcodes()
    for code in codes:
            img.draw_rectangle(code.rect(), color = (255, 0, 0))
            print(code)
    if codes:
        if code[0].payload == "LEFT":
            s1 = pyb.Servo(1)
            s1.angle(45)
User avatar
kwagyeman
Posts: 1397
Joined: Sun May 24, 2015 2:10 pm

Re: Extracting text from QR Codes

Postby kwagyeman » Wed Feb 14, 2018 11:59 am

Sorry, I meant .payload().

The parens are important.
Nyamekye,

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests