mirror of
https://github.com/opencv/opencv.git
synced 2024-12-12 23:49:36 +08:00
acc089ca64
QR-Code detector : multiple detection * change in qr-codes detection * change in qr-codes detection * change in test * change in test * add multiple detection * multiple detection * multiple detect * add parallel implementation * add functional for performance tests * change in test * add perftest * returned implementation for 1 qr-code, added support for vector<Mat> and vector<vector<Point2f>> in MultipleDetectAndDecode * deleted all lambda expressions * changing in triangle sort * fixed warnings * fixed errors * add java and python tests * change in java tests * change in java and python tests * change in perf test * change in qrcode.cpp * add spaces * change in qrcode.cpp * change in qrcode.cpp * change in qrcode.cpp * change in java tests * change in java tests * solved problems * solved problems * change in java and python tests * change in python tests * change in python tests * change in python tests * change in methods name * deleted sample qrcode_multi, change in qrcode.cpp * change in perf tests * change in objdetect.hpp * deleted code duplication in sample qrcode.cpp * returned spaces * added spaces * deleted draw function * change in qrcode.cpp * change in qrcode.cpp * deleted all draw functions * objdetect(QR): extractVerticalLines * objdetect(QR): whitespaces * objdetect(QR): simplify operations, avoid duplicated code * change in interface, additional checks in java and python tests, added new key in sample for saving original image from camera * fix warnings and errors in python test * fix * write in file with space key * solved error with empty mat check in python test * correct path to test image * deleted spaces * solved error with check empty mat in python tests * added check of empty vector of points * samples: rework qrcode.cpp * objdetect(QR): fix API, input parameters must be first * objdetect(QR): test/fix points layout
53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
#!/usr/bin/env python
|
|
'''
|
|
===============================================================================
|
|
QR code detect and decode pipeline.
|
|
===============================================================================
|
|
'''
|
|
import os
|
|
import numpy as np
|
|
import cv2 as cv
|
|
|
|
from tests_common import NewOpenCVTests
|
|
|
|
class qrcode_detector_test(NewOpenCVTests):
|
|
|
|
def test_detect(self):
|
|
img = cv.imread(os.path.join(self.extraTestDataPath, 'cv/qrcode/link_ocv.jpg'))
|
|
self.assertFalse(img is None)
|
|
detector = cv.QRCodeDetector()
|
|
retval, points = detector.detect(img)
|
|
self.assertTrue(retval)
|
|
self.assertEqual(points.shape, (1, 4, 2))
|
|
|
|
def test_detect_and_decode(self):
|
|
img = cv.imread(os.path.join(self.extraTestDataPath, 'cv/qrcode/link_ocv.jpg'))
|
|
self.assertFalse(img is None)
|
|
detector = cv.QRCodeDetector()
|
|
retval, points, straight_qrcode = detector.detectAndDecode(img)
|
|
self.assertEqual(retval, "https://opencv.org/")
|
|
self.assertEqual(points.shape, (1, 4, 2))
|
|
|
|
def test_detect_multi(self):
|
|
img = cv.imread(os.path.join(self.extraTestDataPath, 'cv/qrcode/multiple/6_qrcodes.png'))
|
|
self.assertFalse(img is None)
|
|
detector = cv.QRCodeDetector()
|
|
retval, points = detector.detectMulti(img)
|
|
self.assertTrue(retval)
|
|
self.assertEqual(points.shape, (6, 4, 2))
|
|
|
|
def test_detect_and_decode_multi(self):
|
|
img = cv.imread(os.path.join(self.extraTestDataPath, 'cv/qrcode/multiple/6_qrcodes.png'))
|
|
self.assertFalse(img is None)
|
|
detector = cv.QRCodeDetector()
|
|
retval, decoded_data, points, straight_qrcode = detector.detectAndDecodeMulti(img)
|
|
self.assertTrue(retval)
|
|
self.assertEqual(len(decoded_data), 6)
|
|
self.assertEqual(decoded_data[0], "TWO STEPS FORWARD")
|
|
self.assertEqual(decoded_data[1], "EXTRA")
|
|
self.assertEqual(decoded_data[2], "SKIP")
|
|
self.assertEqual(decoded_data[3], "STEP FORWARD")
|
|
self.assertEqual(decoded_data[4], "STEP BACK")
|
|
self.assertEqual(decoded_data[5], "QUESTION")
|
|
self.assertEqual(points.shape, (6, 4, 2))
|