From d7e839b8c5b24e2d8eb62fd74e5a7e6371c2c483 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 21 Mar 2020 00:51:34 +0000 Subject: [PATCH] objdetect(QR): avoid bug with empty input --- modules/objdetect/src/qrcode.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/objdetect/src/qrcode.cpp b/modules/objdetect/src/qrcode.cpp index 4990dfd388..12d89919f9 100644 --- a/modules/objdetect/src/qrcode.cpp +++ b/modules/objdetect/src/qrcode.cpp @@ -122,9 +122,16 @@ void QRDetect::init(const Mat& src, double eps_vertical_, double eps_horizontal_ eps_vertical = eps_vertical_; eps_horizontal = eps_horizontal_; - adaptiveThreshold(barcode, bin_barcode, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 83, 2); - adaptiveThreshold(resized_barcode, resized_bin_barcode, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 83, 2); + if (!barcode.empty()) + adaptiveThreshold(barcode, bin_barcode, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 83, 2); + else + bin_barcode.release(); + + if (!resized_barcode.empty()) + adaptiveThreshold(resized_barcode, resized_bin_barcode, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 83, 2); + else + resized_bin_barcode.release(); } vector QRDetect::searchHorizontalLines()