Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV real-time tracking only QrCode

Hello everyone, I'm a newbie in this fantastic world of the computer vision.

A part of my project is like a "in-out people counter" but only detecting QRCodes. For that, I started by using the pyzbar library, in order to detect and decode the QRCode. I'm passing frames getting from a webcam and for each of them decoding with pyzbar, then drawing a rectangle around it and finally show with cv2. By doing that, each time a frame is passed, the decode function detect the qrcode as new one (obviously).

What I want to do is to track only and exclusively the QRCode, by ignoring everything else in the environment, identifying and tracking it so that it can only be decoded once as long as it is visible from the camera. The webcam works like a scanner. At the end what I would like to achieve as a result is:

  • When a qrcode appears at the top of the webcam images, it is identified (once);
  • when the qrcode crosses the middle line, a counter is increased; (I saw a tutorial that uses frame subtraction)
  • when the qrcode comes out of the bottom of the images, the program is ready to detect a new qrcode.

The idea is that there will only be one qrcode at a time in the image.

def decodeAndDraw(im):
cv2_im = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
image = Image.fromarray(cv2_im)

draw = ImageDraw.Draw(image)
for barcode in decode(image):
    rect = barcode.rect
    draw.rectangle(
        (
            (rect.left, rect.top),
            (rect.left + rect.width, rect.top + rect.height)
        ), 
        outline='#0080ff'
    )

  draw.polygon(barcode.polygon, outline='#e945ff')


image_data = np.asarray(image) 
return image_data

Can you point me in the right direction? Many thanks!