Skip to content

Commit 0265bb8

Browse files
committed
python: export new Result::position() and Result::orientation()
1 parent 0cb6535 commit 0265bb8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

wrappers/python/test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def test_write_read_cycle(self):
2222
self.assertTrue(res.valid)
2323
self.assertEqual(res.format, format)
2424
self.assertEqual(res.text, text)
25+
self.assertEqual(res.orientation, 0)
26+
self.assertEqual(res.position.topLeft.x, 4)
2527

2628
@unittest.skipIf(not has_numpy, "need numpy for read/write tests")
2729
def test_failed_read(self):

wrappers/python/zxing.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,20 @@ PYBIND11_MODULE(zxing, m)
8989
.value("FORMAT_COUNT", BarcodeFormat::FORMAT_COUNT)
9090
.value("NONE", BarcodeFormat::NONE)
9191
.export_values();
92-
py::class_<ResultPoint>(m, "ResultPoint")
93-
.def_property_readonly("x", &ResultPoint::x)
94-
.def_property_readonly("y", &ResultPoint::y);
92+
py::class_<PointI>(m, "Point")
93+
.def_readonly("x", &PointI::x)
94+
.def_readonly("y", &PointI::y);
95+
py::class_<Position>(m, "Position")
96+
.def_property_readonly("topLeft", &Position::topLeft)
97+
.def_property_readonly("topRight", &Position::topRight)
98+
.def_property_readonly("bottomLeft", &Position::bottomLeft)
99+
.def_property_readonly("bottomRight", &Position::bottomRight);
95100
py::class_<Result>(m, "Result")
96101
.def_property_readonly("valid", &Result::isValid)
97102
.def_property_readonly("text", &Result::text)
98103
.def_property_readonly("format", &Result::format)
99-
.def_property_readonly("points", &Result::resultPoints);
104+
.def_property_readonly("position", &Result::position)
105+
.def_property_readonly("orientation", &Result::orientation);
100106
m.def("barcode_format_from_str", &BarcodeFormatFromString, "Convert string to BarcodeFormat", py::arg("str"));
101107
m.def("barcode_formats_from_str", &barcode_formats_from_str, "Convert string to BarcodeFormats", py::arg("str"));
102108
m.def("read_barcode", &read_barcode, "Read (decode) a barcode from a numpy BGR or grayscale image array",

0 commit comments

Comments
 (0)