From 74ae86f25ceab5869113d069d871314f88c1bbe2 Mon Sep 17 00:00:00 2001 From: sz Date: Sat, 17 Feb 2024 21:05:41 -0600 Subject: [PATCH] Update to v0.6 samples, fix tests --- samples | 2 +- tests/test_cimb_translator.py | 8 ++++---- tests/test_cimbar.py | 28 ++++++++++++++++++++++------ tests/test_fountain.py | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/samples b/samples index 1e86f11..f10b63a 160000 --- a/samples +++ b/samples @@ -1 +1 @@ -Subproject commit 1e86f113f2be91c07ba36aa8f4f16bedf6f092d3 +Subproject commit f10b63a1a601198ad9515a426b116d52b6312376 diff --git a/tests/test_cimb_translator.py b/tests/test_cimb_translator.py index 90ed20f..aeb3d2a 100644 --- a/tests/test_cimb_translator.py +++ b/tests/test_cimb_translator.py @@ -29,8 +29,8 @@ def test_decode_dark(self): self.assertEqual(decoded, 5) self.assertEqual(error, 0) - color = cimb.decode_color(img) - self.assertEqual(color, 0 << 4) + color = cimb.decode_color(img, 0) + self.assertEqual(color, 1) img2 = Image.open(path.join(CIMBAR_ROOT, 'tests', 'sample', '25.png')) img2 = img2.convert('RGB') @@ -38,5 +38,5 @@ def test_decode_dark(self): self.assertEqual(decoded, 5) self.assertEqual(error, 0) - color = cimb.decode_color(img2) - self.assertEqual(color, 1 << 4) + color = cimb.decode_color(img2, 0) + self.assertEqual(color, 2) diff --git a/tests/test_cimbar.py b/tests/test_cimbar.py index f834a72..afd4303 100644 --- a/tests/test_cimbar.py +++ b/tests/test_cimbar.py @@ -2,13 +2,14 @@ from os import path from tempfile import TemporaryDirectory from unittest import TestCase +from unittest.mock import patch import cv2 import numpy from cimbar.cimbar import encode, decode, bits_per_op from cimbar.encode.rss import reed_solomon_stream -from cimbar.grader import evaluate as evaluate_grader +from cimbar.grader import evaluate_split, evaluate_interleaved CIMBAR_ROOT = path.abspath(path.join(path.dirname(path.realpath(__file__)), '..')) @@ -78,7 +79,7 @@ def validate_output(self, out_path): self.assertEqual(contents, self._src_data()[:7500]) def validate_grader(self, out_path, target): - num_bits = evaluate_grader(self.decode_clean, out_path, bits_per_op(), True) + num_bits = evaluate_split(self.decode_clean, out_path, bits_per_op(), 2) self.assertLess(num_bits, target) def test_decode_simple(self): @@ -112,7 +113,8 @@ def test_decode_perspective_rotate(self): decode([skewed_image], out_no_ecc, dark=True, ecc=0, force_preprocess=True) self.validate_grader(out_no_ecc, 4000) - def test_decode_sample(self): + @patch('cimbar.cimbar.use_split_mode', lambda: False) + def test_decode_sample_mode4c(self): clean_image = 'samples/6bit/4color_ecc30_0.png' warped_image = 'samples/6bit/4_30_802.jpg' @@ -122,7 +124,21 @@ def test_decode_sample(self): warped_bits = self._temp_path('outfile_warped.txt') decode([warped_image], warped_bits, dark=True, ecc=0, force_preprocess=True, auto_dewarp=False) - num_bits = evaluate_grader(clean_bits, warped_bits, bits_per_op(), True) + num_bits = evaluate_interleaved(clean_bits, warped_bits, bits_per_op()) + self.assertLess(num_bits, 350) + + + def test_decode_sample_modeb(self): + clean_image = 'samples/b/tr_0.png' + warped_image = 'samples/b/ex2434.jpg' + + clean_bits = self._temp_path('outfile_clean.txt') + decode([clean_image], clean_bits, dark=True, ecc=0, auto_dewarp=False) + + warped_bits = self._temp_path('outfile_warped.txt') + decode([warped_image], warped_bits, dark=True, ecc=0, force_preprocess=True, auto_dewarp=False) + + num_bits = evaluate_split(clean_bits, warped_bits, bits_per_op(), 2) self.assertLess(num_bits, 350) @@ -145,10 +161,10 @@ def test_roundtrip(self): encode(self.src_file, dst_image, dark=True, fountain=True) out_path = path.join(self.temp_dir.name, 'out.txt') - decode([dst_image], out_path, dark=True, deskew=False, auto_dewarp=False, fountain=True) + decode([dst_image], out_path, dark=True, deskew=False, auto_dewarp=False, fountain=True, color_correct=3) with open(out_path, 'rb') as f: contents = f.read() with open(self.src_file, 'rb') as f: expected = f.read() - self.assertEquals(contents, expected) + self.assertEqual(contents, expected) diff --git a/tests/test_fountain.py b/tests/test_fountain.py index 777e6b7..d20875f 100644 --- a/tests/test_fountain.py +++ b/tests/test_fountain.py @@ -47,7 +47,7 @@ def test_encode(self): data = b'0123456789' * 100 inbuff = BytesIO(data) - fes = fountain_encoder_stream(inbuff, 400) + fes = fountain_encoder_stream(inbuff, 400, encode_id=0) r = fes.read(400) self.assertEqual(b'\x00\x00\x03\xe8\x00\x00' + data[:394], r)