Python Forum
QR code data missing in some of my QR codes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QR code data missing in some of my QR codes
#1
Does this indicate a computer memory problem?

I read a csv file with student names and number in to a dictionary: numsnames

The dictionary has 162 items. key is student number, value is name.

I want to make a QR code for each student from the dictionary:

for key in numsnames.keys():
    filename = f'/home/pedro/winter2020/20BE/QRcodes_20BE/{key}QR.png'
    data = key + ':' + numsnames[key]
    # instantiate QRCode object
    qr = qrcode.QRCode(version=1, box_size=10, border=4)
    # add data to the QR code
    qr.add_data(data)
    # compile the data into a QR code array
    qr.make()
    # transfer the array into an actual image
    img = qr.make_image(fill_color="black", back_color="white")
    # save it to a file
    img.save(filename)
To check, I print the data from the QR code:

QRfiles = os.listdir(savepathQRcodes)
QRfiles.sort()
for f in QRfiles:
    img = cv2.imread(savepathQRcodes + file)
    detector = cv2.QRCodeDetector()
    data, bbox, straight_qrcode = detector.detectAndDecode(img)
    #text = data.split(':')
    #print('number, name: ', text[0], text[1])
    print(data)
What I get has bits missing:

Quote:pedro@pedro-512ssd:~/myPython$ ./qrCodes_for_studentsV1.py
numsnames is 162 long.

1825010141:陆遥
2025010101:白雪妮
2025010102:曹颖
2025010103:陈妍朵
2025010104:戴金珂
2025010105:段赵元
2025010106:段卓含

2025010108:范玉虹
2025010109:高萌婧
2025010110:高飒飒
2025010111:郭其平
2025010112:侯文美
2025010113:胡蝶

2025010115:胡沁恬

In all there are 20 names/numbers missing, or 20 QR codes without data.

Is this a computer memory problem??
Reply
#2
If I understand correctly, you get QR code images (files) for all students. First thing I would do is to check the missing QR code images with some other tool - e.g. qr reader on a phone and see if it is problem with the creation or reading of the generated qr codes.

Ideally you would provide minimal reproducible example, incl. some sample data that demonstrate the problem, so that we can try for ourselves and try to help
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thanks!

Yes, all the QR codes are there, for every student!

For example, 2025010107, which does not show any data when I run the program to check the data.

BUT: following your advice, I scanned 2025010107QR.png with my phone, and, lo and behold, there is the data!!

I'll sleep on this one, maybe tomorrow I will figure out what's wrong!!

As long as the data can be read, I can proceed with my Python OMR marking program!!

As for try yourself:

you could: take the number 2025010107 and any name, make a QR code, then read the data, see if it works.

On my computer I tried making the single QR code for this student, but I still got back nothing for data, bbox and straight_qrcode.

However, as I said, reading the code with my phone, I immediately see the data!

That's what makes me think I have a memory "leak", for want of a better word.
Reply
#4
(Jan-14-2021, 11:03 AM)Pedroski55 Wrote: As for try yourself:

you could: take the number 2025010107 and any name, make a QR code, then read the data, see if it works.
Yes, I understand I can try with my own dummy data. My idea was to try to reproduce your problem, with a given set of data and compare - do I also have problem with some/same qr code images
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
EDIT: I just tried again with the 19BE classes. This time, 10 QR codes cannot be read with:

img1 = cv2.imread(savepathQRcodes + QRfiles[0])
detector = cv2.QRCodeDetector()
data, bbox, straight_qrcode = detector.detectAndDecode(img1)
They show nothing for data, bbox, straight_qrcode

End of edit

Today I tried again.

I still have 20 QR codes which will not show any data in Idle!

Strangely, they are not the same ones, as far as I can tell. For instance, 2025010107 can now be read in my "check the data" loop.

Reading the data into the dictionary, I explicitly set the student number to a string, in case it was a number, in the vain hope that that was the problem.

Also, I set the name as the key this time and the student number as value.

numsnames = {}

with open(pathToCSV, mode ='r') as csvfile:    
        # reading the CSV file 
        thisCSV = csv.reader(csvfile)  
        # displaying the contents of the CSV file
        # this only works 1 time on the csv.reader file
        for line in thisCSV:
            if not line[0] == '学号': # line[0] is column headers
                # now use name as key, number as value
                numsnames[line[1]] = str(line[0])
            print(line[1])
            print(line[0])
I can read the missing data with my phone, but in Idle I get zero for 20 of my 162 QR codes.

I'll try and get the original data with pandas csvreader, see if that makes a difference!

If you wish, you can to try with original data, this is from the csv (I populate this each week with classwork, homework and attendance scores):

Quote:学号,姓名,CW,HW,Total Score,Attendance
2025010101,白雪妮,0,0,0,0
2025010102,曹颖,0,0,0,0
2025010103,陈妍朵,0,0,0,0
2025010104,戴金珂,0,0,0,0
2025010105,段赵元,0,0,0,0
2025010106,段卓含,0,0,0,0
2025010107,范佳佳,0,0,0,0
2025010108,范玉虹,0,0,0,0
2025010109,高萌婧,0,0,0,0
2025010110,高飒飒,0,0,0,0
Reply
#6
Maybe there is a clue to this misbehaviour here:

I made this function to make the QR codes. When I set border to 1 only 3 QR codes from 121 19BE students cannot be read in Idle.

def makeQRcode(file, key):
    # key is name, numsnames[key] is student number
    data = key + ':' + numsnames[key]
    # instantiate QRCode object    
    qr = qrcode.QRCode(version=2, box_size=10, border=1)
    # add data to the QR code
    qr.add_data(data)
    # compile the data into a QR code array
    qr.make()
    # transfer the array into an actual image
    img = qr.make_image(fill_color="black", back_color="white")
    # save it to a file
    img.save(file)
Reply
#7
If anyone else has this problem:

decode with pyzbar

pyzbar decodes ALL my qr codes correctly, with the proviso that:

some of the Chinese names are not interpreted correctly and appear as Traditional Chinese or strange characters

This does not really present a problem, as I really only need the student number, which pyzbar reads correctly in all instances.
nilamo likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Missing parts of Code Felipe1991_GVT 3 304 Mar-22-2024, 05:58 PM
Last Post: deanhystad
  How to read rainfall time series and insert missing data points MadsM 4 2,185 Jan-06-2022, 10:39 AM
Last Post: amdi40
  txt-file: read and append missing data sufi 1 3,212 Dec-07-2019, 08:12 AM
Last Post: Gribouillis
  First Byte of a string is missing while receiving data over TCP Socket shahrukh1987 3 4,247 Nov-20-2019, 10:34 AM
Last Post: shahrukh1987
  Unable to do the proper split using re.sub incase of missing data. Karz 1 1,868 Nov-17-2019, 05:58 PM
Last Post: buran
  I am trying to make a Colour Wars game, "Winning code" missing Ondrejoda 0 2,283 Feb-18-2018, 11:06 AM
Last Post: Ondrejoda

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020