QR code detector
QR codes, like AruCo markers, are another type of specifically designed object, used to store information and describe 3D space. You can find QR codes almost everywhere, from food packages to museums and robotized factories.
In this recipe, we will understand how to detect QR codes and remove perspective distortions to get a canonical view of the codes. This task may sound easy to complete, but it requires a lot of OpenCV functionality. Let's find out how to do it.
Getting ready
Before you proceed with this recipe, you will need to install the OpenCV 3.x Python API package.
How to do it...
- Import the modules we need:
import cv2 import numpy as np
- Implement a function which finds the intersection point of two lines:
def intersect(l1, l2): delta = np.array([l1[1] - l1[0], l2[1] - l2[0]]).astype(np.float32) delta = 1 / delta delta[:, 0] *= -1 b = np.matmul(delta, np.array([l1[0], l2[0]]).transpose()) b = np.diagonal(b).astype(np.float32) res = cv2.solve(delta...