Challenge - 5 Problems
QR Code Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of QR code reading snippet
What will be the output of this Python code snippet that reads a QR code image using OpenCV and pyzbar on a Raspberry Pi?
Raspberry Pi
import cv2 from pyzbar.pyzbar import decode img = cv2.imread('qrcode.png') detected = decode(img) for obj in detected: print(obj.data.decode('utf-8'))
Attempts:
2 left
💡 Hint
Check what decode() returns and how obj.data is processed.
✗ Incorrect
The decode function returns a list of detected QR code objects. Each object's data attribute contains the QR code content in bytes, which is decoded to a string with utf-8.
🧠 Conceptual
intermediate1:00remaining
Understanding QR code detection libraries
Which library is commonly used on Raspberry Pi to decode QR codes from images in Python?
Attempts:
2 left
💡 Hint
It is a wrapper around the ZBar library.
✗ Incorrect
pyzbar is a Python wrapper for the ZBar library, which can decode barcodes and QR codes from images.
🔧 Debug
advanced2:00remaining
Identify the error in QR code reading code
What error will this code produce when run on a Raspberry Pi with OpenCV and pyzbar installed?
import cv2
from pyzbar.pyzbar import decode
img = cv2.imread('qrcode.png')
result = decode(img)
print(result.data.decode('utf-8'))
Attempts:
2 left
💡 Hint
Check the type of the object returned by decode().
✗ Incorrect
decode() returns a list of detected QR code objects. Accessing .data directly on the list causes AttributeError.
📝 Syntax
advanced2:30remaining
Correct syntax for reading QR code from camera
Which code snippet correctly reads a frame from the Raspberry Pi camera using OpenCV and decodes a QR code?
Attempts:
2 left
💡 Hint
Check the return value of cap.read() and how to handle decode results.
✗ Incorrect
cap.read() returns a tuple (ret, frame). decode returns a list, so you must iterate to access .data. Option C correctly does both.
🚀 Application
expert1:30remaining
Number of QR codes detected in an image
Given this code snippet running on Raspberry Pi, how many QR codes will be detected and printed if the image contains three distinct QR codes?
import cv2
from pyzbar.pyzbar import decode
img = cv2.imread('multi_qr.png')
detected = decode(img)
print(len(detected))
Attempts:
2 left
💡 Hint
decode() returns a list of all detected QR codes in the image.
✗ Incorrect
The decode function detects all QR codes in the image and returns them as a list. The length of this list equals the number of QR codes detected.
