Detect QR codes in videos using Python

Free Python Code - Aug 20 '23 - - Dev Community

Hi πŸ™‚πŸ–

In this post, i will show you how to Detect QR codes in videos using Python

step 1

You need any video that contains aΒ QR code.

step 2

import libraries


from pyzbar.pyzbar import decode
from PIL import Image

import moviepy.editor as mp

Enter fullscreen mode Exit fullscreen mode

step 2

Write Qrcode Detector



from pyzbar.pyzbar import decode
from PIL import Image

import moviepy.editor as mp


def decode_image(image_array):
    result = decode(Image.fromarray(image_array))
    return result

def get_frames():
    video = mp.VideoFileClip('test.mp4')
    for i, frame in enumerate(video.iter_frames()):
        result = decode_image(frame)
        if result:
            print(f' Qrcode code detected in frame : {i} πŸ™‚')
            print(f'Qrcode date : {str(result[0][0])}')



get_frames()

Enter fullscreen mode Exit fullscreen mode

Result :

 Qrcode code detected in frame : 149 πŸ™‚
 Qrcode data : b'123'
 Qrcode code detected in frame : 150 πŸ™‚
 Qrcode data : b'123'
 Qrcode code detected in frame : 151 πŸ™‚
 Qrcode data : b'123'
Enter fullscreen mode Exit fullscreen mode

Now we're done πŸ€—

Don't forget to like and follow πŸ™‚

Support me on PayPal πŸ€—
https://www.paypal.com/paypalme/amr396

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .