Skip to content

Add TryHarder and MinLineCount hints for python wrapper #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions wrappers/python/zxing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::ostream& operator<<(std::ostream& os, const Position& points) {
}

auto read_barcodes_impl(py::object _image, const BarcodeFormats& formats, bool try_rotate, bool try_downscale, TextMode text_mode,
Binarizer binarizer, bool is_pure, EanAddOnSymbol ean_add_on_symbol, uint8_t max_number_of_symbols = 0xff)
Binarizer binarizer, bool is_pure, EanAddOnSymbol ean_add_on_symbol, bool try_harder, uint8_t min_line_count, uint8_t max_number_of_symbols = 0xff)
{
const auto hints = DecodeHints()
.setFormats(formats)
Expand All @@ -46,6 +46,8 @@ auto read_barcodes_impl(py::object _image, const BarcodeFormats& formats, bool t
.setTextMode(text_mode)
.setBinarizer(binarizer)
.setIsPure(is_pure)
.setTryHarder(try_harder)
.setMinLineCount(min_line_count)
.setMaxNumberOfSymbols(max_number_of_symbols)
.setEanAddOnSymbol(ean_add_on_symbol);
const auto _type = std::string(py::str(py::type::of(_image)));
Expand Down Expand Up @@ -89,16 +91,16 @@ auto read_barcodes_impl(py::object _image, const BarcodeFormats& formats, bool t
}

std::optional<Result> read_barcode(py::object _image, const BarcodeFormats& formats, bool try_rotate, bool try_downscale,
TextMode text_mode, Binarizer binarizer, bool is_pure, EanAddOnSymbol ean_add_on_symbol)
TextMode text_mode, Binarizer binarizer, bool is_pure, EanAddOnSymbol ean_add_on_symbol, bool try_harder, uint8_t min_line_count)
{
auto res = read_barcodes_impl(_image, formats, try_rotate, try_downscale, text_mode, binarizer, is_pure, ean_add_on_symbol, 1);
auto res = read_barcodes_impl(_image, formats, try_rotate, try_downscale, text_mode, binarizer, is_pure, ean_add_on_symbol, try_harder, min_line_count, 1);
return res.empty() ? std::nullopt : std::optional(res.front());
}

Results read_barcodes(py::object _image, const BarcodeFormats& formats, bool try_rotate, bool try_downscale,
TextMode text_mode, Binarizer binarizer, bool is_pure, EanAddOnSymbol ean_add_on_symbol)
TextMode text_mode, Binarizer binarizer, bool is_pure, EanAddOnSymbol ean_add_on_symbol, bool try_harder, uint8_t min_line_count)
{
return read_barcodes_impl(_image, formats, try_rotate, try_downscale, text_mode, binarizer, is_pure, ean_add_on_symbol);
return read_barcodes_impl(_image, formats, try_rotate, try_downscale, text_mode, binarizer, is_pure, ean_add_on_symbol, try_harder, min_line_count);
}

Image write_barcode(BarcodeFormat format, std::string text, int width, int height, int quiet_zone, int ec_level)
Expand Down Expand Up @@ -254,6 +256,8 @@ PYBIND11_MODULE(zxingcpp, m)
py::arg("binarizer") = Binarizer::LocalAverage,
py::arg("is_pure") = false,
py::arg("ean_add_on_symbol") = EanAddOnSymbol::Ignore,
py::arg("try_harder") = true,
py::arg("min_line_count") = 1,
"Read (decode) a barcode from a numpy BGR or grayscale image array or from a PIL image.\n\n"
":type image: numpy.ndarray|PIL.Image.Image\n"
":param image: The image object to decode. The image can be either:\n"
Expand All @@ -279,6 +283,10 @@ PYBIND11_MODULE(zxingcpp, m)
":type ean_add_on_symbol: zxing.EanAddOnSymbol\n"
":param ean_add_on_symbol: Specify whether to Ignore, Read or Require EAN-2/5 add-on symbols while scanning \n"
" EAN/UPC codes. Default is ``Ignore``.\n"
":type try_harder: bool\n"
":param try_harder: if ``True`` (the default), accuracy over performance.\n"
":type min_line_count: uint8_t\n"
":param min_line_count: Specify the minimum lines count to find.\n"
":rtype: zxing.Result\n"
":return: a zxing result containing decoded symbol if found, None otherwise"
);
Expand All @@ -291,6 +299,8 @@ PYBIND11_MODULE(zxingcpp, m)
py::arg("binarizer") = Binarizer::LocalAverage,
py::arg("is_pure") = false,
py::arg("ean_add_on_symbol") = EanAddOnSymbol::Ignore,
py::arg("try_harder") = true,
py::arg("min_line_count") = 1,
"Read (decode) multiple barcodes from a numpy BGR or grayscale image array or from a PIL image.\n\n"
":type image: numpy.ndarray|PIL.Image.Image\n"
":param image: The image object to decode. The image can be either:\n"
Expand All @@ -316,6 +326,10 @@ PYBIND11_MODULE(zxingcpp, m)
":type ean_add_on_symbol: zxing.EanAddOnSymbol\n"
":param ean_add_on_symbol: Specify whether to Ignore, Read or Require EAN-2/5 add-on symbols while scanning \n"
" EAN/UPC codes. Default is ``Ignore``.\n"
":type try_harder: bool\n"
":param try_harder: if ``True`` (the default), accuracy over performance.\n"
":type min_line_count: uint8_t\n"
":param min_line_count: Specify the minimum lines count to find.\n"
":rtype: zxing.Result\n"
":return: a list of zxing results containing decoded symbols, the list is empty if none is found"
);
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy