Skip to content

Commit

Permalink
Update to v0.6 samples, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sz3 committed Feb 18, 2024
1 parent e27511d commit 74ae86f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion samples
8 changes: 4 additions & 4 deletions tests/test_cimb_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ 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')
decoded, error = cimb.decode_symbol(img2)
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)
28 changes: 22 additions & 6 deletions tests/test_cimbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)), '..'))
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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'

Expand All @@ -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)


Expand All @@ -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)
2 changes: 1 addition & 1 deletion tests/test_fountain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 74ae86f

Please sign in to comment.