- Scan the photo viewfinder with OpenCV's QR detectors (aruco, then plain), off the preview thread, not while recording or in the gallery - A card shows the code's text: Open for web links, Join for Wi-Fi codes (NetworkManager over D-Bus), Copy; nothing happens before a tap - QR pill turns scanning off Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2f404ced5c
commit
e2ba41acca
4 files changed
+386
-1
No files matched your search
@@ -332,5 +332,38 @@ class TestCameraHelpers(unittest.TestCase):
|
||||
self.assertAlmostEqual(pts_ms[4], 145.0, delta=5.0)
|
||||
|
||||
|
||||
class QRTests(unittest.TestCase):
|
||||
def test_reporter_reports_once_until_out_of_view(self):
|
||||
r = cam_mod.QRReporter()
|
||||
self.assertFalse(r.update("", 0.0))
|
||||
self.assertTrue(r.update("a", 1.0))
|
||||
self.assertFalse(r.update("a", 2.0))
|
||||
self.assertFalse(r.update("a", 4.5))
|
||||
self.assertTrue(r.update("b", 4.6))
|
||||
self.assertTrue(r.update("b", 9.0))
|
||||
|
||||
def test_line_is_one_ascii_line(self):
|
||||
line = cam_mod.qr_line("a b\nframe 1 1 4\u202e%")
|
||||
self.assertNotIn("\n", line)
|
||||
self.assertTrue(line.isascii())
|
||||
self.assertEqual(line.split(" "), ["qr", "a%20b%0Aframe%201%201%204%E2%80%AE%25"])
|
||||
|
||||
@unittest.skipUnless(HAS_CV2_NUMPY and hasattr(cv2, "QRCodeEncoder"), "needs OpenCV")
|
||||
def test_scanner_reads_codes_in_a_viewfinder_frame(self):
|
||||
text = "https://example.org/chandra"
|
||||
code = cv2.QRCodeEncoder.create().encode(text)
|
||||
code = cv2.copyMakeBorder(code, 4, 4, 4, 4, cv2.BORDER_CONSTANT, value=255)
|
||||
for px in (500, 200): # the small one needs the finer view of the middle
|
||||
frame = np.full((1600, 1200, 3), 110, np.uint8)
|
||||
q = cv2.cvtColor(cv2.resize(code, (px, px), interpolation=cv2.INTER_NEAREST), cv2.COLOR_GRAY2BGR)
|
||||
y, x = (1600 - px) // 2, (1200 - px) // 2
|
||||
frame[y:y + px, x:x + px] = q
|
||||
sc = cam_mod.QRScanner(cv2)
|
||||
self.assertIn(text, [sc.scan(frame), sc.scan(frame)])
|
||||
sc = cam_mod.QRScanner(cv2)
|
||||
blank = np.full((1600, 1200, 3), 110, np.uint8)
|
||||
self.assertEqual([sc.scan(blank), sc.scan(blank)], ["", ""])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user