diff --git a/modules/objdetect/code_chande.py b/modules/objdetect/code_chande.py index cc3fbf7c69..c77a3a2520 100644 --- a/modules/objdetect/code_chande.py +++ b/modules/objdetect/code_chande.py @@ -1,43 +1,46 @@ import os -import re -def update_include_paths(base_dir): - for root, dirs, files in os.walk(base_dir): +# 要添加的内容 +header = """// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +""" + +def add_header_to_file(file_path, header): + """在文件顶部添加指定的头部内容""" + try: + with open(file_path, 'r+', encoding='utf-8') as file: + content = file.read() + # 重置文件指针到文件开头 + file.seek(0, 0) + # 写入头部和原内容 + file.write(header + content) + print(f"Header added to: {file_path}") + except Exception as e: + print(f"Failed to process {file_path}: {e}") + +def process_directory(directory, extensions): + """处理指定目录中的所有文件""" + for root, _, files in os.walk(directory): for file in files: - if file.endswith(".hpp") or file.endswith(".cpp"): # 只处理C++文件 + if any(file.endswith(ext) for ext in extensions): file_path = os.path.join(root, file) - with open(file_path, "r") as f: - lines = f.readlines() + add_header_to_file(file_path, header) - updated_lines = [] - modified = False +def main(): + directory = input("Enter the directory path to process: ").strip() + if os.path.exists(directory): + extensions = ['.cpp', '.hpp', '.h', '.c'] # 指定需要处理的文件类型 + process_directory(directory, extensions) + else: + print("The directory does not exist.") - for line in lines: - # 匹配 #include "..." - match = re.match(r'#include\s+"(.+)"', line) - if match: - included_file = match.group(1) - included_file_path = os.path.join(base_dir, included_file) - - # 检查目标文件是否存在 - if os.path.exists(included_file_path): - # 计算相对路径 - relative_path = os.path.relpath(included_file_path, root) - new_include = f'#include "{relative_path}"\n' - updated_lines.append(new_include) - modified = True - else: - updated_lines.append(line) - else: - updated_lines.append(line) - - # 如果有修改,写回文件 - if modified: - with open(file_path, "w") as f: - f.writelines(updated_lines) - print(f"Updated includes in: {file_path}") - -# 使用方法 if __name__ == "__main__": - base_directory = "./src" # 修改为你的代码根目录 - update_include_paths(base_directory) \ No newline at end of file + main() \ No newline at end of file diff --git a/modules/objdetect/include/opencv2/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect.hpp index d0ec9869e4..0bbf21bf3f 100644 --- a/modules/objdetect/include/opencv2/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect.hpp @@ -863,7 +863,7 @@ public: }; enum DECODER_READER{ - DECODER_ONED_BARCODE = 1,// barcode, which includes UPC_A, UPC_E, EAN_8, EAN_13, CODE_39, CODE_93, CODE_128, ITF, CODABAR + // DECODER_ONED_BARCODE = 1,// barcode, which includes UPC_A, UPC_E, EAN_8, EAN_13, CODE_39, CODE_93, CODE_128, ITF, CODABAR DECODER_QRCODE = 2,// QRCODE DECODER_PDF417 = 3,// PDF417 DECODER_DATAMATRIX = 4,// DATAMATRIX @@ -871,10 +871,10 @@ enum DECODER_READER{ typedef std::vector vector_DECODER_READER; -class CV_EXPORTS_W_SIMPLE CodeDetector : public GraphicalCodeDetector +class CV_EXPORTS_W_SIMPLE CodeDetectorWeChat : public GraphicalCodeDetector { public: - CV_WRAP CodeDetector(const std::string& detection_model_path_ = "", + CV_WRAP CodeDetectorWeChat(const std::string& detection_model_path_ = "", const std::string& super_resolution_model_path_ = "", const std::vector& readers = std::vector(), const float detector_iou_thres = 0.6, diff --git a/modules/objdetect/src/binarzermgr.cpp b/modules/objdetect/src/binarzermgr.cpp index 1cffb51948..bfd6703a0b 100644 --- a/modules/objdetect/src/binarzermgr.cpp +++ b/modules/objdetect/src/binarzermgr.cpp @@ -1,3 +1,10 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. + #include "binarzermgr.hpp" #include "qbarsource.hpp" @@ -45,18 +52,18 @@ zxing::Ref BinarizerMgr::Binarize(zxing::Ref source) return binarizer; } -void BinarizerMgr::SwitchBinarizer() +void BinarizerMgr::switchBinarizer() { m_iNowRotateIndex = (m_iNowRotateIndex+1) % m_vecRotateBinarizer.size(); } -int BinarizerMgr::GetCurBinarizer() +int BinarizerMgr::getCurBinarizer() { if (m_iNextOnceBinarizer != -1) return m_iNextOnceBinarizer; return m_vecRotateBinarizer[m_iNowRotateIndex]; } -void BinarizerMgr::SetNextOnceBinarizer(int iBinarizerIndex) +void BinarizerMgr::setNextOnceBinarizer(int iBinarizerIndex) { m_iNextOnceBinarizer = iBinarizerIndex; } diff --git a/modules/objdetect/src/binarzermgr.hpp b/modules/objdetect/src/binarzermgr.hpp index 7a82ac8496..71d13d4a30 100644 --- a/modules/objdetect/src/binarzermgr.hpp +++ b/modules/objdetect/src/binarzermgr.hpp @@ -1,4 +1,13 @@ -#pragma once +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. + +#ifndef __OPENCV_BINARZERMGR_HPP__ +#define __OPENCV_BINARZERMGR_HPP__ + #include "zxing/zxing.hpp" #include "zxing/common/counted.hpp" #include "zxing/binarizer.hpp" @@ -28,15 +37,16 @@ public: zxing::Ref Binarize(zxing::Ref source); - void SwitchBinarizer(); + void switchBinarizer(); - int GetCurBinarizer(); + int getCurBinarizer(); - void SetNextOnceBinarizer(int iBinarizerIndex); + void setNextOnceBinarizer(int iBinarizerIndex); private: int m_iNowRotateIndex; int m_iNextOnceBinarizer; std::vector m_vecRotateBinarizer; }; -} // namesapce cv \ No newline at end of file +} // namesapce cv +#endif // __OPENCV_BINARZERMGR_HPP__ \ No newline at end of file diff --git a/modules/objdetect/src/detector/qbar_detector.cpp b/modules/objdetect/src/detector/qbar_detector.cpp index 7b8d3b19df..b9d83b48b3 100644 --- a/modules/objdetect/src/detector/qbar_detector.cpp +++ b/modules/objdetect/src/detector/qbar_detector.cpp @@ -1,9 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. + #include "qbar_detector.hpp" #include #define CLIP(x, x1, x2) (std::fmax)(x1, (std::fmin)(x, x2)) namespace cv { - int QBarDetector::Init(const std::string &det_path) + int QBarDetector::init(const std::string &det_path) { try { @@ -23,7 +30,7 @@ namespace cv { return 0; } - int QBarDetector::Detect(const Mat &image,std::vector &bboxes) + int QBarDetector::detect(const Mat &image,std::vector &bboxes) { Mat input_blob; int ret = this->pre_process_det(image,input_blob); diff --git a/modules/objdetect/src/detector/qbar_detector.hpp b/modules/objdetect/src/detector/qbar_detector.hpp index b19dbf9a9b..77d4e994c5 100644 --- a/modules/objdetect/src/detector/qbar_detector.hpp +++ b/modules/objdetect/src/detector/qbar_detector.hpp @@ -1,3 +1,10 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. + #pragma once #include #include @@ -22,7 +29,7 @@ namespace cv { float prob; int x, y, width, height; - void PrintInfo() + void printInfo() { printf("class %d, prob %.2f, x %d, y %d, width %d, height %d\n", class_id, prob, x, y, width, height); } @@ -78,8 +85,8 @@ namespace cv { public: QBarDetector(){}; ~QBarDetector(){}; - int Init(const std::string &config_path); - int Detect(const Mat &image,std::vector &bboxes); + int init(const std::string &config_path); + int detect(const Mat &image,std::vector &bboxes); void setReferenceSize(int reference_size) {this->reference_size = reference_size;} void setScoreThres(float score_thres) {this->score_thres = score_thres;} void setIouThres(float iou_thres) {this->iou_thres = iou_thres;} diff --git a/modules/objdetect/src/qbardecoder.cpp b/modules/objdetect/src/qbardecoder.cpp index 2077a40afb..2084b3f1b9 100644 --- a/modules/objdetect/src/qbardecoder.cpp +++ b/modules/objdetect/src/qbardecoder.cpp @@ -1,3 +1,10 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. + #include "opencv2/core.hpp" #include "qbardecoder.hpp" #include @@ -57,12 +64,12 @@ int gettimeofday(struct timeval *tp, void *tzp) #endif namespace cv { -void QBarDecoder::Detect(Mat srcImage, std::vector &bboxes) { +void QBarDecoder::detect(Mat srcImage, std::vector &bboxes) { if(_init_detector_model_) - detector_->Detect(srcImage, bboxes); + detector_->detect(srcImage, bboxes); } -QBAR_RESULT QBarDecoder::Decode(Mat& srcCvImage) +QBAR_RESULT QBarDecoder::decode(Mat& srcCvImage) { if (srcCvImage.data == nullptr || (srcCvImage.rows < 1) || (srcCvImage.cols < 1)) { @@ -76,7 +83,7 @@ QBAR_RESULT QBarDecoder::Decode(Mat& srcCvImage) } DecodeHints decodeHints; - AddFormatsToDecodeHints(decodeHints); + addFormatsToDecodeHints(decodeHints); decodeHints.setTryHarder(1); decodeHints.setPureBarcode(true); decodeHints.qbar_points.resize(4); @@ -100,40 +107,40 @@ QBAR_RESULT QBarDecoder::Decode(Mat& srcCvImage) for (int tb = 0; tb < tryBinarizeTime; tb++) { - err_handler.Reset(); + err_handler.reset(); if (source == NULL || height * width > source->getMaxSize()) { source = QBarSource::create(img.data, width, height, comps, pixelStep, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { - std::cout << "continue by errmsg " << err_handler.ErrMsg() << std::endl; + std::cout << "continue by errmsg " << err_handler.errMsg() << std::endl; continue; } } else { source->reset(img.data, width, height, comps, pixelStep, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { - std::cout << "continue by errmsg " << err_handler.ErrMsg() << std::endl; + std::cout << "continue by errmsg " << err_handler.errMsg() << std::endl; continue; } } - int ret = Decode(source, result, decodeHints); + int ret = decode(source, result, decodeHints); if (ret == 0) { - return ProcessResult(result); + return processResult(result); } - binarizer_mgr_.SwitchBinarizer(); + binarizer_mgr_.switchBinarizer(); } return QBAR_RESULT::MakeInvalid(); } -int QBarDecoder::Decode(Ref source, Ref &result, DecodeHints& decodeHints) +int QBarDecoder::decode(Ref source, Ref &result, DecodeHints& decodeHints) { int res = -1; std::string cell_result; @@ -149,19 +156,19 @@ int QBarDecoder::Decode(Ref source, Ref &result, Decode } catch (std::exception &e) { - std::cout << "Decode exception: " << e.what() << std::endl; + std::cout << "decode exception: " << e.what() << std::endl; return -1; } if (res == 0) { - result->setBinaryMethod(static_cast(binarizer_mgr_.GetCurBinarizer())); + result->setBinaryMethod(static_cast(binarizer_mgr_.getCurBinarizer())); } return res; } -QBAR_RESULT QBarDecoder::ProcessResult(zxing::Result *zx_result) +QBAR_RESULT QBarDecoder::processResult(zxing::Result *zx_result) { QBAR_RESULT result; @@ -263,7 +270,7 @@ public: void operator()(const cv::Range& range) const CV_OVERRIDE { QBarDecoder local_decoder; - local_decoder.SetReaders(decoder->readers_); + local_decoder.setReaders(decoder->readers_); for (int i = range.start; i < range.end; ++i) { const DetectInfo& detect_info = detect_results[i]; @@ -279,7 +286,7 @@ public: std::lock_guard lock(decoder->sr_mutex); scaled_img = decoder->sr_->ProcessImageScale(crop_image, cur_scale, decoder->_init_sr_model_); } - result = local_decoder.Decode(scaled_img); + result = local_decoder.decode(scaled_img); if (result.typeID != 0) { std::vector points_qr; @@ -311,7 +318,7 @@ private: std::vector& results; }; -std::vector QBarDecoder::Decode(Mat srcImage, std::vector& detect_results) { +std::vector QBarDecoder::decode(Mat srcImage, std::vector& detect_results) { std::vector results(detect_results.size()); ParallelDecode parallelDecode(this, srcImage, detect_results, results); @@ -390,7 +397,7 @@ void QBarDecoder::nms(std::vector& results, float NMS_THRESH) { results = final_results; } -void QBarDecoder::AddFormatsToDecodeHints(zxing::DecodeHints &hints) { +void QBarDecoder::addFormatsToDecodeHints(zxing::DecodeHints &hints) { if (readers_.count(QBAR_READER::ONED_BARCODE)) { hints.addFormat(BarcodeFormat::CODE_25); @@ -419,9 +426,9 @@ void QBarDecoder::AddFormatsToDecodeHints(zxing::DecodeHints &hints) { } } -int QBarDecoder::InitAIModel(QBAR_ML_MODE &ml_mode){ +int QBarDecoder::initAIModel(QBAR_ML_MODE &ml_mode){ detector_ = std::shared_ptr(new QBarDetector()); - int ret = detector_->Init(ml_mode.detection_model_path_); + int ret = detector_->init(ml_mode.detection_model_path_); if(ret) { return ret; @@ -429,7 +436,7 @@ int QBarDecoder::InitAIModel(QBAR_ML_MODE &ml_mode){ _init_detector_model_ = true; sr_ = std::shared_ptr(new SuperScale()); - ret = sr_->Init(ml_mode.super_resolution_model_path_); + ret = sr_->init(ml_mode.super_resolution_model_path_); if(ret) { return ret; diff --git a/modules/objdetect/src/qbardecoder.hpp b/modules/objdetect/src/qbardecoder.hpp index 18d741c84b..8f4a216b14 100644 --- a/modules/objdetect/src/qbardecoder.hpp +++ b/modules/objdetect/src/qbardecoder.hpp @@ -1,5 +1,12 @@ -#ifndef QBARDECODER_H -#define QBARDECODER_H +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. + +#ifndef __OPENCV_QBARDECODER_HPP__ +#define __OPENCV_QBARDECODER_HPP__ #include #include @@ -45,7 +52,7 @@ public: QBarDecoder() = default; ~QBarDecoder() = default; - void SetReaders(const std::unordered_set &readers) { readers_ = readers; } + void setReaders(const std::unordered_set &readers) { readers_ = readers; } void setDetectorReferenceSize(int reference_size) { if (_init_detector_model_) { detector_->setReferenceSize(reference_size); @@ -65,16 +72,16 @@ public: this->iou_thres = iou_thres; } - void Detect(Mat srcImage, std::vector &bboxes); - QBAR_RESULT Decode(Mat& srcImage); - std::vector Decode(Mat srcImage, std::vector &_detect_results_); + void detect(Mat srcImage, std::vector &bboxes); + QBAR_RESULT decode(Mat& srcImage); + std::vector decode(Mat srcImage, std::vector &_detect_results_); - int InitAIModel(QBAR_ML_MODE &ml_mode); + int initAIModel(QBAR_ML_MODE &ml_mode); private: - int Decode(zxing::Ref source, zxing::Ref &result, zxing::DecodeHints& decodeHints); - QBAR_RESULT ProcessResult(zxing::Result *zx_result); - void AddFormatsToDecodeHints(zxing::DecodeHints &hints); + int decode(zxing::Ref source, zxing::Ref &result, zxing::DecodeHints& decodeHints); + QBAR_RESULT processResult(zxing::Result *zx_result); + void addFormatsToDecodeHints(zxing::DecodeHints &hints); void nms(std::vector& results, float NMS_THRESH); Mat cropObj(const Mat& img, const DetectInfo& bbox, Align& aligner); @@ -96,4 +103,4 @@ private: std::mutex sr_mutex; }; } // namespace cv -#endif +#endif // __OPENCV_QBARDECODER_HPP__ diff --git a/modules/objdetect/src/qbarsource.cpp b/modules/objdetect/src/qbarsource.cpp index 5b0d39c42b..a15fc264ab 100644 --- a/modules/objdetect/src/qbarsource.cpp +++ b/modules/objdetect/src/qbarsource.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * Copyright 2010-2011 ZXing authors * @@ -102,7 +112,7 @@ QBarSource::QBarSource(unsigned char* pixels, int width, int height, int left_, // Make gray luminances first makeGray(err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; if (needReverseHorizontal) { @@ -288,7 +298,7 @@ void QBarSource::makeGrayRow(int y, ErrorHandler & err_handler) for (int x = 0; x < dataWidth; x++) { luminances[offsetGRAY + x] = convertPixel(pixelRow + (x * _pixelStep), err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } } @@ -307,7 +317,7 @@ void QBarSource::makeGray(ErrorHandler & err_handler) { makeGrayRow(y, err_handler); } - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; arrayCopy(luminances, 0, &_matrix[0], 0, area); } @@ -325,7 +335,7 @@ void QBarSource::makeGrayReset(ErrorHandler & err_handler){ { makeGrayRow(y, err_handler); } - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; arrayCopy(luminances, 0, &_matrix[0], 0, area); } diff --git a/modules/objdetect/src/qbarsource.hpp b/modules/objdetect/src/qbarsource.hpp index ce600db8fd..5883931f95 100644 --- a/modules/objdetect/src/qbarsource.hpp +++ b/modules/objdetect/src/qbarsource.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * Copyright 2010-2011 ZXing authors * @@ -14,7 +24,9 @@ * limitations under the License. */ -#pragma once +#ifndef __OPENCV_QBARSOURCE_HPP__ +#define __OPENCV_QBARSOURCE_HPP__ + #include "zxing/luminance_source.hpp" #include "zxing/luminance_source.hpp" #include "zxing/common/byte_matrix.hpp" @@ -86,4 +98,5 @@ public: return maxDataHeight*maxDataWidth; } }; -} // namespace cv \ No newline at end of file +} // namespace cv +#endif // __OPENCV_QBARSOURCE_HPP__ \ No newline at end of file diff --git a/modules/objdetect/src/qbarstruct.hpp b/modules/objdetect/src/qbarstruct.hpp index 3374c9e799..e57bebe874 100644 --- a/modules/objdetect/src/qbarstruct.hpp +++ b/modules/objdetect/src/qbarstruct.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2008 ZXing authors All rights reserved. @@ -15,8 +25,8 @@ * limitations under the License. */ -#ifndef QBAR_AI_QBAR_QBARSTRUCT_H_ -#define QBAR_AI_QBAR_QBARSTRUCT_H_ +#ifndef __OPENCV_QBARSTRUCT_HPP__ +#define __OPENCV_QBARSTRUCT_HPP__ #include #include @@ -382,4 +392,4 @@ struct QBarDrawParam { } }; } // namespace cv -#endif // QBAR_AI_QBAR_QBARSTRUCT_H_ \ No newline at end of file +#endif // __OPENCV_QBARSTRUCT_HPP__ \ No newline at end of file diff --git a/modules/objdetect/src/qrcode.cpp b/modules/objdetect/src/qrcode.cpp index 222b7af439..6b747719a5 100644 --- a/modules/objdetect/src/qrcode.cpp +++ b/modules/objdetect/src/qrcode.cpp @@ -4,6 +4,9 @@ // // Copyright (C) 2018, Intel Corporation, all rights reserved. // Third party copyrights are property of their respective owners. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. #include "precomp.hpp" #include "opencv2/objdetect.hpp" @@ -4706,139 +4709,181 @@ void QRCodeDetectorAruco::setArucoParameters(const aruco::DetectorParameters& pa std::dynamic_pointer_cast(p)->arucoDetector.setDetectorParameters(params); } -struct PimplCode : public ImplContour { +struct PimplWeChat : public GraphicalCodeDetector::Impl { std::shared_ptr qbarDecode_; - PimplCode() { + PimplWeChat() { qbarDecode_ = make_shared(); } - bool detectMulti(InputArray in, OutputArray points) const override { - Mat gray; - if (!checkQRInputImage(in, gray)) { - points.release(); - return false; - } - - std::vector _detect_results; - - qbarDecode_->Detect(gray, _detect_results); - - vector result; - for (size_t i = 0; i < _detect_results.size(); i++) { - result.push_back(Point2f(_detect_results[i].x , _detect_results[i].y)); - result.push_back(Point2f(_detect_results[i].x + _detect_results[i].width, _detect_results[i].y)); - result.push_back(Point2f(_detect_results[i].x , _detect_results[i].y + _detect_results[i].height)); - result.push_back(Point2f(_detect_results[i].x + _detect_results[i].width, _detect_results[i].y + _detect_results[i].height)); - } - - if (result.size() >= 4) { - updatePointsResult(points, result); - return true; - } - - return false; - } - - bool decodeMulti( - InputArray img, - InputArray points, - CV_OUT std::vector& decoded_info, - OutputArrayOfArrays straight_qrcode - ) const override { - Mat gray; - if (!checkQRInputImage(img, gray)) - return false; - - CV_Assert(points.size().width > 0); - CV_Assert((points.size().width % 4) == 0); - - std::vector bboxes; - Mat qr_points = points.getMat(); - qr_points = qr_points.reshape(2, 1); - for (int i = 0; i < qr_points.size().width; i += 4) - { - std::vector tempMat = qr_points.colRange(i, i + 4); - - DetectInfo bbox; - bbox.x = tempMat[0].x; - bbox.y = tempMat[0].y; - bbox.width = tempMat[3].x - tempMat[0].x; - bbox.height = tempMat[3].y - tempMat[0].y; - bboxes.push_back(bbox); - } - if (bboxes.size() == 0) { - DetectInfo bbox; - bbox.x = 0; - bbox.y = 0; - bbox.width = gray.cols; - bbox.height = gray.rows; - - bboxes.push_back(bbox); - } - - std::vector results; - results = qbarDecode_->Decode(gray, bboxes); - - decoded_info.clear(); - for (size_t i = 0; i < results.size(); i++) { - if(results[i].typeID != 0) - decoded_info.push_back(results[i].data); - else - decoded_info.push_back(""); - } - - if (!decoded_info.empty()) - return true; - else - return false; - } - - bool detectAndDecodeMulti( - InputArray img, - CV_OUT std::vector& decoded_info, - OutputArray points_, - OutputArrayOfArrays straight_qrcode - ) const override { - decoded_info.clear(); - points_.clear(); - - Mat gray; - if (!checkQRInputImage(img, gray)) - return false; - - bool ok = detectMulti(gray, points_); - - if(!ok) { - return false; - } - - return decodeMulti(gray, points_, decoded_info, straight_qrcode); - } + bool detect(InputArray img, OutputArray points) const CV_OVERRIDE; + string decode(InputArray img, InputArray points, OutputArray straight_qrcode) const CV_OVERRIDE; + string detectAndDecode(InputArray img, OutputArray points, OutputArray straight_qrcode) const CV_OVERRIDE; + bool detectMulti(InputArray img, OutputArray points) const CV_OVERRIDE; + bool decodeMulti(InputArray img, InputArray points, vector& decoded_info, OutputArrayOfArrays straight_qrcode) const CV_OVERRIDE; + bool detectAndDecodeMulti(InputArray img, vector& decoded_info, OutputArray points, OutputArrayOfArrays straight_qrcode) const CV_OVERRIDE; }; -CodeDetector::CodeDetector(const std::string& detection_model_path_, +bool PimplWeChat::detect(InputArray img, OutputArray points) const { + vector corners, result; + bool flag = detectMulti(img, corners); + CV_Assert((int)corners.size() % 4 == 0); + + Point2f imageCenter(((float)img.cols())/2.f, ((float)img.rows())/2.f); + size_t minQrId = 0ull; + float minDist = std::numeric_limits::max(); + for (size_t i = 0ull; i < corners.size(); i += 4ull) { + Point2f qrCenter((corners[i] + corners[i+1ull] + corners[i+2ull] + corners[i+3ull]) / 4.f); + float dist = sqrt(normL2Sqr(qrCenter - imageCenter)); + if (dist < minDist) { + minQrId = i; + minDist = dist; + } + } + if (flag) { + result = {corners[minQrId], corners[minQrId+1ull], corners[minQrId+2ull], corners[minQrId+3ull]}; + updatePointsResult(points, result); + } + return flag; +} + +string PimplWeChat::decode(InputArray img, InputArray points, OutputArray straight_qrcode) const { + CV_UNUSED(straight_qrcode); + vector decoded_info; + if (!decodeMulti(img, points, decoded_info, straight_qrcode)) + return string(); + if (decoded_info.size() < 1) + return string(); + + return decoded_info[0]; +} + +string PimplWeChat::detectAndDecode(InputArray img, OutputArray points, OutputArray straight_qrcode) const { + CV_UNUSED(straight_qrcode); + + if (!detect(img, points)) + return string(); + + return decode(img, points, straight_qrcode); +} + +bool PimplWeChat::detectMulti(InputArray in, OutputArray points) const { + Mat gray; + if (!checkQRInputImage(in, gray)) { + points.release(); + return false; + } + + std::vector _detect_results; + + qbarDecode_->detect(gray, _detect_results); + + vector result; + for (size_t i = 0; i < _detect_results.size(); i++) { + result.push_back(Point2f(_detect_results[i].x , _detect_results[i].y)); + result.push_back(Point2f(_detect_results[i].x + _detect_results[i].width, _detect_results[i].y)); + result.push_back(Point2f(_detect_results[i].x , _detect_results[i].y + _detect_results[i].height)); + result.push_back(Point2f(_detect_results[i].x + _detect_results[i].width, _detect_results[i].y + _detect_results[i].height)); + } + + if (result.size() >= 4) { + updatePointsResult(points, result); + return true; + } + + return false; +} + +bool PimplWeChat::decodeMulti( + InputArray img, + InputArray points, + CV_OUT std::vector& decoded_info, + OutputArrayOfArrays straight_qrcode +) const { + CV_UNUSED(straight_qrcode); + + Mat gray; + if (!checkQRInputImage(img, gray)) + return false; + + CV_Assert(points.size().width > 0); + CV_Assert((points.size().width % 4) == 0); + + std::vector bboxes; + Mat qr_points = points.getMat(); + qr_points = qr_points.reshape(2, 1); + for (int i = 0; i < qr_points.size().width; i += 4) + { + std::vector tempMat = qr_points.colRange(i, i + 4); + + DetectInfo bbox; + bbox.x = tempMat[0].x; + bbox.y = tempMat[0].y; + bbox.width = tempMat[3].x - tempMat[0].x; + bbox.height = tempMat[3].y - tempMat[0].y; + bboxes.push_back(bbox); + } + if (bboxes.size() == 0) { + DetectInfo bbox; + bbox.x = 0; + bbox.y = 0; + bbox.width = gray.cols; + bbox.height = gray.rows; + + bboxes.push_back(bbox); + } + + std::vector results; + results = qbarDecode_->decode(gray, bboxes); + + decoded_info.clear(); + for (size_t i = 0; i < results.size(); i++) { + if(results[i].typeID != 0) + decoded_info.push_back(results[i].data); + else + decoded_info.push_back(""); + } + + if (!decoded_info.empty()) + return true; + else + return false; +} + +bool PimplWeChat::detectAndDecodeMulti( + InputArray img, + CV_OUT std::vector& decoded_info, + OutputArray points_, + OutputArrayOfArrays straight_qrcode +) const { + CV_UNUSED(straight_qrcode); + + if(!detectMulti(img, points_)) + return false; + + return decodeMulti(img, points_, decoded_info, straight_qrcode); +} + +CodeDetectorWeChat::CodeDetectorWeChat(const std::string& detection_model_path_, const std::string& super_resolution_model_path_, const std::vector& readers, const float detector_iou_thres, const float decoder_iou_thres, const float score_thres, const int reference_size) { - p = makePtr(); + p = makePtr(); QBAR_MODE mode; mode.useAI = true; mode.qbar_ml_mode.detection_model_path_ = detection_model_path_; mode.qbar_ml_mode.super_resolution_model_path_ = super_resolution_model_path_; - int ret = std::dynamic_pointer_cast(p)->qbarDecode_->InitAIModel(mode.qbar_ml_mode); + int ret = std::dynamic_pointer_cast(p)->qbarDecode_->initAIModel(mode.qbar_ml_mode); - if (ret) { - return; - } + CV_Assert(ret == 0); if (readers.empty()) { - std::dynamic_pointer_cast(p)->qbarDecode_->SetReaders({ONED_BARCODE, QRCODE, PDF417, DATAMATRIX}); + std::dynamic_pointer_cast(p)->qbarDecode_->setReaders({ONED_BARCODE, QRCODE, PDF417, DATAMATRIX}); } else { unordered_set readers_; @@ -4846,26 +4891,26 @@ CodeDetector::CodeDetector(const std::string& detection_model_path_, readers_.insert(static_cast(reader)); } - std::dynamic_pointer_cast(p)->qbarDecode_->SetReaders(readers_); + std::dynamic_pointer_cast(p)->qbarDecode_->setReaders(readers_); } - std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorReferenceSize(reference_size); - std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorScoreThres(score_thres); - std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorIouThres(detector_iou_thres); - std::dynamic_pointer_cast(p)->qbarDecode_->setDecoderIouThres(decoder_iou_thres); + std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorReferenceSize(reference_size); + std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorScoreThres(score_thres); + std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorIouThres(detector_iou_thres); + std::dynamic_pointer_cast(p)->qbarDecode_->setDecoderIouThres(decoder_iou_thres); } -void CodeDetector::setDetectorReferenceSize(int reference_size) { - std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorReferenceSize(reference_size); +void CodeDetectorWeChat::setDetectorReferenceSize(int reference_size) { + std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorReferenceSize(reference_size); } -void CodeDetector::setDetectorScoreThres(float score_thres) { - std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorScoreThres(score_thres); +void CodeDetectorWeChat::setDetectorScoreThres(float score_thres) { + std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorScoreThres(score_thres); } -void CodeDetector::setDetectorIouThres(float iou_thres) { - std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorIouThres(iou_thres); +void CodeDetectorWeChat::setDetectorIouThres(float iou_thres) { + std::dynamic_pointer_cast(p)->qbarDecode_->setDetectorIouThres(iou_thres); } -void CodeDetector::setDecoderIouThres(float iou_thres) { - std::dynamic_pointer_cast(p)->qbarDecode_->setDecoderIouThres(iou_thres); +void CodeDetectorWeChat::setDecoderIouThres(float iou_thres) { + std::dynamic_pointer_cast(p)->qbarDecode_->setDecoderIouThres(iou_thres); } } // namespace diff --git a/modules/objdetect/src/sr_scale/super_scale.cpp b/modules/objdetect/src/sr_scale/super_scale.cpp index 76a21611a5..80f9d3cfe6 100644 --- a/modules/objdetect/src/sr_scale/super_scale.cpp +++ b/modules/objdetect/src/sr_scale/super_scale.cpp @@ -10,7 +10,7 @@ #define CLIP(x, x1, x2) max(x1, min(x, x2)) namespace cv { -int SuperScale::Init(const std::string &sr_path) { +int SuperScale::init(const std::string &sr_path) { try { dnn::Net network = dnn::readNetFromONNX(sr_path); diff --git a/modules/objdetect/src/sr_scale/super_scale.hpp b/modules/objdetect/src/sr_scale/super_scale.hpp index 7d0e0d3388..0dbd15049a 100644 --- a/modules/objdetect/src/sr_scale/super_scale.hpp +++ b/modules/objdetect/src/sr_scale/super_scale.hpp @@ -18,7 +18,7 @@ class SuperScale { public: SuperScale(){}; ~SuperScale(){}; - int Init(const std::string &config_path); + int init(const std::string &config_path); Mat ProcessImageScale(const Mat &src, float scale, const bool &use_sr, int sr_max_size = 160); private: diff --git a/modules/objdetect/src/zxing/barcode_format.cpp b/modules/objdetect/src/zxing/barcode_format.cpp index 1a5fbfe37c..20329523c9 100644 --- a/modules/objdetect/src/zxing/barcode_format.cpp +++ b/modules/objdetect/src/zxing/barcode_format.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Created by Christian Brunschen on 13/05/2008. diff --git a/modules/objdetect/src/zxing/barcode_format.hpp b/modules/objdetect/src/zxing/barcode_format.hpp index 8dd14f21d4..33d5dff066 100644 --- a/modules/objdetect/src/zxing/barcode_format.hpp +++ b/modules/objdetect/src/zxing/barcode_format.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __BARCODE_FORMAT_H__ -#define __BARCODE_FORMAT_H__ +#ifndef __ZXING_BARCODE_FORMAT_HPP__ +#define __ZXING_BARCODE_FORMAT_HPP__ /* * BarcodeFormat.hpp @@ -57,4 +67,4 @@ public: } // namespace zxing -#endif // __BARCODE_FORMAT_H__ +#endif // __ZXING_BARCODE_FORMAT_HPP__ diff --git a/modules/objdetect/src/zxing/binarizer.cpp b/modules/objdetect/src/zxing/binarizer.cpp index 1e3f785a8d..6f49393c5d 100644 --- a/modules/objdetect/src/zxing/binarizer.cpp +++ b/modules/objdetect/src/zxing/binarizer.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Binarizer.cpp @@ -195,7 +205,7 @@ Ref Binarizer::getBlackRow(int y, Ref row, ErrorHandler & er if (!matrix_) { matrix_ = getBlackMatrix(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } matrix_->getRow(y, row); diff --git a/modules/objdetect/src/zxing/binarizer.hpp b/modules/objdetect/src/zxing/binarizer.hpp index 69168fea82..2d81d2cd88 100644 --- a/modules/objdetect/src/zxing/binarizer.hpp +++ b/modules/objdetect/src/zxing/binarizer.hpp @@ -1,5 +1,15 @@ -#ifndef BINARIZER_H_ -#define BINARIZER_H_ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_BINARIZER_HPP__ +#define __ZXING_BINARIZER_HPP__ /* * Binarizer.hpp @@ -114,4 +124,4 @@ public: }; } // namespace zxing -#endif /* BINARIZER_H_ */ +#endif // __ZXING_BINARIZER_HPP__ diff --git a/modules/objdetect/src/zxing/binary_bitmap.cpp b/modules/objdetect/src/zxing/binary_bitmap.cpp index cf1eb23b2f..f21cc2afff 100644 --- a/modules/objdetect/src/zxing/binary_bitmap.cpp +++ b/modules/objdetect/src/zxing/binary_bitmap.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2010 ZXing authors All rights reserved. @@ -35,19 +45,19 @@ BinaryBitmap::~BinaryBitmap() { Ref BinaryBitmap::getBlackRow(int y, Ref row, ErrorHandler & err_handler) { Ref bitary = binarizer_->getBlackRow(y, row, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return bitary; } Ref BinaryBitmap::getBlackMatrix(ErrorHandler & err_handler) { Ref bitmtx = binarizer_->getBlackMatrix(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return bitmtx; } Ref BinaryBitmap::getInvertedMatrix(ErrorHandler & err_handler) { Ref bitmtx = binarizer_->getInvertedMatrix(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return bitmtx; } diff --git a/modules/objdetect/src/zxing/binary_bitmap.hpp b/modules/objdetect/src/zxing/binary_bitmap.hpp index ff8fca7b19..4e3a781578 100644 --- a/modules/objdetect/src/zxing/binary_bitmap.hpp +++ b/modules/objdetect/src/zxing/binary_bitmap.hpp @@ -1,5 +1,15 @@ -#ifndef __BINARYBITMAP_H__ -#define __BINARYBITMAP_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_BINARY_BITMAP_HPP__ +#define __ZXING_BINARY_BITMAP_HPP__ /* * BinaryBitmap.hpp @@ -59,4 +69,4 @@ public: } // namespace zxing -#endif /* BINARYBITMAP_H_ */ +#endif // __ZXING_BINARY_BITMAP_HPP__ diff --git a/modules/objdetect/src/zxing/checksum_exception.cpp b/modules/objdetect/src/zxing/checksum_exception.cpp index 31f0b90732..84055d7723 100644 --- a/modules/objdetect/src/zxing/checksum_exception.cpp +++ b/modules/objdetect/src/zxing/checksum_exception.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * ChecksumException.cpp diff --git a/modules/objdetect/src/zxing/checksum_exception.hpp b/modules/objdetect/src/zxing/checksum_exception.hpp index b15d82a1b3..4997ff1c8f 100644 --- a/modules/objdetect/src/zxing/checksum_exception.hpp +++ b/modules/objdetect/src/zxing/checksum_exception.hpp @@ -1,7 +1,17 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __CHECKSUM_EXCEPTION_H__ -#define __CHECKSUM_EXCEPTION_H__ +#ifndef __ZXING_CHECKSUM_EXCEPTION_HPP__ +#define __ZXING_CHECKSUM_EXCEPTION_HPP__ /* * Copyright 20011 ZXing authors @@ -31,4 +41,4 @@ public: }; } // namespace zxing -#endif // __CHECKSUM_EXCEPTION_H__ +#endif // __ZXING_CHECKSUM_EXCEPTION_HPP__ diff --git a/modules/objdetect/src/zxing/common/array.hpp b/modules/objdetect/src/zxing/common/array.hpp index 1a50e7c432..7ef9059f62 100644 --- a/modules/objdetect/src/zxing/common/array.hpp +++ b/modules/objdetect/src/zxing/common/array.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __ARRAY_H__ -#define __ARRAY_H__ +#ifndef __ZXING_COMMON_ARRAY_HPP__ +#define __ZXING_COMMON_ARRAY_HPP__ /* * Array.hpp @@ -193,4 +203,4 @@ public: } // namespace zxing -#endif // __ARRAY_H__ +#endif // __ZXING_COMMON_ARRAY_HPP__ diff --git a/modules/objdetect/src/zxing/common/bit_array.cpp b/modules/objdetect/src/zxing/common/bit_array.cpp index 5d28d820de..7c891b2712 100644 --- a/modules/objdetect/src/zxing/common/bit_array.cpp +++ b/modules/objdetect/src/zxing/common/bit_array.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2010 ZXing authors. All rights reserved. @@ -101,7 +111,7 @@ void BitArray::initAllNextSets() int* nextSetArray = nextSets->data(); int* nextUnsetArray = nextUnSets->data(); - // Init the last one + // init the last one if (rowBits[size-1]) { nextSetArray[size-1] = size-1; diff --git a/modules/objdetect/src/zxing/common/bit_array.hpp b/modules/objdetect/src/zxing/common/bit_array.hpp index ea4c65d90f..7f7b3d9bad 100644 --- a/modules/objdetect/src/zxing/common/bit_array.hpp +++ b/modules/objdetect/src/zxing/common/bit_array.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __BIT_ARRAY_H__ -#define __BIT_ARRAY_H__ +#ifndef __ZXING_COMMON_BIT_ARRAY_HPP__ +#define __ZXING_COMMON_BIT_ARRAY_HPP__ /* * Copyright 2010 ZXing authors. All rights reserved. @@ -60,7 +70,7 @@ public: return (bool*)bits->data(); } - // Init for next sets and unsets to speed up + // init for next sets and unsets to speed up // By Valiantliu void initAllNextSets(); void initAllNextSetsFromCounters(std::vector counters); @@ -100,4 +110,4 @@ std::ostream& operator << (std::ostream&, BitArray const&); } // namespace zxing -#endif // __BIT_ARRAY_H__ +#endif // __ZXING_COMMON_BIT_ARRAY_HPP__ diff --git a/modules/objdetect/src/zxing/common/bit_array_io.cpp b/modules/objdetect/src/zxing/common/bit_array_io.cpp index 806d853006..08dd7a44db 100644 --- a/modules/objdetect/src/zxing/common/bit_array_io.cpp +++ b/modules/objdetect/src/zxing/common/bit_array_io.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2010 ZXing authors. All rights reserved. diff --git a/modules/objdetect/src/zxing/common/bit_matrix.cpp b/modules/objdetect/src/zxing/common/bit_matrix.cpp index d6ff4d2be6..16f74d4d8d 100644 --- a/modules/objdetect/src/zxing/common/bit_matrix.cpp +++ b/modules/objdetect/src/zxing/common/bit_matrix.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2010 ZXing authors. All rights reserved. @@ -59,7 +69,7 @@ void BitMatrix::init(int width_, int height_, ErrorHandler & err_handler) void BitMatrix::init(int width_, int height_, bool* bitsPtr, ErrorHandler & err_handler) { init(width_, height_, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; memcpy(bits->data(), bitsPtr, width_ * height_ * sizeof(bool)); } diff --git a/modules/objdetect/src/zxing/common/bit_matrix.hpp b/modules/objdetect/src/zxing/common/bit_matrix.hpp index debb7f274a..6f4513d2a0 100644 --- a/modules/objdetect/src/zxing/common/bit_matrix.hpp +++ b/modules/objdetect/src/zxing/common/bit_matrix.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __BIT_MATRIX_H__ -#define __BIT_MATRIX_H__ +#ifndef __ZXING_COMMON_BIT_MATRIX_HPP__ +#define __ZXING_COMMON_BIT_MATRIX_HPP__ /* * BitMatrix.hpp @@ -143,4 +153,4 @@ private: } // namespace zxing -#endif // QBAR_AI_QBAR_ZXING_COMMON_BITMATRIX_H_ +#endif // __ZXING_COMMON_BIT_MATRIX_HPP__ diff --git a/modules/objdetect/src/zxing/common/bit_source.cpp b/modules/objdetect/src/zxing/common/bit_source.cpp index 53b37f46a8..61762f7094 100644 --- a/modules/objdetect/src/zxing/common/bit_source.cpp +++ b/modules/objdetect/src/zxing/common/bit_source.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * BitSource.cpp diff --git a/modules/objdetect/src/zxing/common/bit_source.hpp b/modules/objdetect/src/zxing/common/bit_source.hpp index 198626c30c..a9ec78edc9 100644 --- a/modules/objdetect/src/zxing/common/bit_source.hpp +++ b/modules/objdetect/src/zxing/common/bit_source.hpp @@ -1,5 +1,15 @@ -#ifndef __BIT_SOURCE_H__ -#define __BIT_SOURCE_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_BIT_SOURCE_HPP__ +#define __ZXING_COMMON_BIT_SOURCE_HPP__ /* * BitSource.hpp @@ -73,4 +83,4 @@ public: } -#endif // __BIT_SOURCE_H__ +#endif // __ZXING_COMMON_BIT_SOURCE_HPP__ diff --git a/modules/objdetect/src/zxing/common/byte_matix.hpp b/modules/objdetect/src/zxing/common/byte_matix.hpp deleted file mode 100644 index c2a46772ee..0000000000 --- a/modules/objdetect/src/zxing/common/byte_matix.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef __BYTE_MATRIX_H__ -#define __BYTE_MATRIX_H__ - -#include "counted.hpp" -#include "bit_array.hpp" -#include "array.hpp" -#include - -namespace zxing { - - class ByteMatix : public Counted { - public: - ByteMatix(int dimension); - ByteMatix(int width, int height); - ByteMatix(int width, int height, ArrayRef source); - ~ByteMatix(); - - char get(int x, int y) const { - int offset =row_offsets[y] + x; - return bytes[offset] & 0xFF; - } - - void set(int x, int y, char char_value){ - int offset=row_offsets[y]+x; - bytes[offset]=char_value& 0xFF; - } - - ArrayRef getRow(int y, ArrayRef row); - - int getWidth() const { return width; } - int getHeight() const {return height;} - - private: - int width; - int height; - ArrayRef bytes; - ArrayRef row_offsets; - - private: - inline void init(int, int); - ByteMatix(const ByteMatix&); - ByteMatix& operator =(const ByteMatix&); - }; - -} - -#endif - diff --git a/modules/objdetect/src/zxing/common/byte_matrix.cpp b/modules/objdetect/src/zxing/common/byte_matrix.cpp index c74c466cba..ee813380cc 100644 --- a/modules/objdetect/src/zxing/common/byte_matrix.cpp +++ b/modules/objdetect/src/zxing/common/byte_matrix.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + #include "byte_matrix.hpp" #include "illegal_argument_exception.hpp" diff --git a/modules/objdetect/src/zxing/common/byte_matrix.hpp b/modules/objdetect/src/zxing/common/byte_matrix.hpp index f6fb0cc7cf..26d29a8a96 100644 --- a/modules/objdetect/src/zxing/common/byte_matrix.hpp +++ b/modules/objdetect/src/zxing/common/byte_matrix.hpp @@ -1,5 +1,15 @@ -#ifndef __BYTE_MATRIX_H__ -#define __BYTE_MATRIX_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_BYTE_MATRIX_HPP__ +#define __ZXING_COMMON_BYTE_MATRIX_HPP__ #include "counted.hpp" #include "bit_array.hpp" @@ -47,5 +57,5 @@ private: } -#endif +#endif // __ZXING_COMMON_BYTE_MATRIX_HPP__ diff --git a/modules/objdetect/src/zxing/common/character.hpp b/modules/objdetect/src/zxing/common/character.hpp index 23142a3d8d..8656c168bc 100644 --- a/modules/objdetect/src/zxing/common/character.hpp +++ b/modules/objdetect/src/zxing/common/character.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // Character.hpp // ZXing @@ -5,14 +15,13 @@ // Created by skylook on 9/28/14. // Copyright (c) 2014 Valiantliu. All rights reserved. // +#ifndef __ZXING_COMMON_CHARACTER_HPP__ +#define __ZXING_COMMON_CHARACTER_HPP__ #include #include #include -#ifndef ZXing_Character_h -#define ZXing_Character_h - namespace zxing { @@ -58,4 +67,4 @@ namespace zxing }; } -#endif +#endif // __ZXING_COMMON_CHARACTER_HPP__ diff --git a/modules/objdetect/src/zxing/common/character_set_eci.cpp b/modules/objdetect/src/zxing/common/character_set_eci.cpp index 5559c8b3a3..aefa85beea 100644 --- a/modules/objdetect/src/zxing/common/character_set_eci.cpp +++ b/modules/objdetect/src/zxing/common/character_set_eci.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2008-2011 ZXing authors diff --git a/modules/objdetect/src/zxing/common/character_set_eci.hpp b/modules/objdetect/src/zxing/common/character_set_eci.hpp index ea658b16da..34dfdce52c 100644 --- a/modules/objdetect/src/zxing/common/character_set_eci.hpp +++ b/modules/objdetect/src/zxing/common/character_set_eci.hpp @@ -1,7 +1,17 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __CHARACTERSET_ECI__ -#define __CHARACTERSET_ECI__ +#ifndef __ZXING_COMMON_CHARACTER_SET_ECI_HPP__ +#define __ZXING_COMMON_CHARACTER_SET_ECI_HPP__ /* * Copyright 2008-2011 ZXing authors @@ -50,4 +60,4 @@ public: } // namespace common } // namespace zxing -#endif // QBAR_AI_QBAR_ZXING_COMMON_CHARACTERSETECI_H_ +#endif // __ZXING_COMMON_CHARACTER_SET_ECI_HPP__ diff --git a/modules/objdetect/src/zxing/common/compress.cpp b/modules/objdetect/src/zxing/common/compress.cpp index 2ce013bb36..b9e35c0b49 100644 --- a/modules/objdetect/src/zxing/common/compress.cpp +++ b/modules/objdetect/src/zxing/common/compress.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + #include "compress.hpp" #include @@ -22,7 +32,7 @@ CompressTools::~CompressTools() { } -bool CompressTools::CanBeCompress(const std::string &sText) +bool CompressTools::canBeCompress(const std::string &sText) { for (size_t i = 0; i < sText.size(); ++i) { @@ -32,7 +42,7 @@ bool CompressTools::CanBeCompress(const std::string &sText) return true; } -bool CompressTools::CanBeRevert(const std::string &sText) +bool CompressTools::canBeRevert(const std::string &sText) { for (size_t i = 0; i < sText.size(); ++i) { @@ -65,7 +75,7 @@ int CompressTools::SetMap(int iBase, const std::string &sKey) return 0; } -int CompressTools::Encode(int iBase, const std::string &sBefore, std::string &sAfter) +int CompressTools::encode(int iBase, const std::string &sBefore, std::string &sAfter) { if (!m_bSetFlag[iBase]) return 1; @@ -110,7 +120,7 @@ int CompressTools::Encode(int iBase, const std::string &sBefore, std::string &sA return 0; } -int CompressTools::Decode(int iBase, const std::string &sBefore, std::string &sAfter) +int CompressTools::decode(int iBase, const std::string &sBefore, std::string &sAfter) { if (!m_bSetFlag[iBase]) return 1; @@ -160,17 +170,17 @@ int CompressTools::Decode(int iBase, const std::string &sBefore, std::string &sA return 0; } -std::string CompressTools::Compress(const std::string &sText) +std::string CompressTools::compress(const std::string &sText) { std::string sCode; - int iRet = Encode(BEFORE_BASE, sText, sCode); + int iRet = encode(BEFORE_BASE, sText, sCode); if (iRet) { printf("compress.encode err! ret = %d\n", iRet); return ""; } std::string sNewText; - iRet = Decode(AFTER_BASE, sCode, sNewText); + iRet = decode(AFTER_BASE, sCode, sNewText); if (iRet) { printf("compress.decode err! ret = %d\n", iRet); @@ -179,17 +189,17 @@ std::string CompressTools::Compress(const std::string &sText) return sNewText; } -std::string CompressTools::Revert(const std::string &sCode) +std::string CompressTools::revert(const std::string &sCode) { std::string sText; - int iRet = Encode(AFTER_BASE, sCode, sText); + int iRet = encode(AFTER_BASE, sCode, sText); if (iRet) { printf("revert.encode err! ret = %d\n", iRet); return ""; } std::string sNewCode; - iRet = Decode(BEFORE_BASE, sText, sNewCode); + iRet = decode(BEFORE_BASE, sText, sNewCode); if (iRet) { printf("revert.decode err! ret = %d\n", iRet); diff --git a/modules/objdetect/src/zxing/common/compress.hpp b/modules/objdetect/src/zxing/common/compress.hpp index e9356dac26..a312ec5e3a 100644 --- a/modules/objdetect/src/zxing/common/compress.hpp +++ b/modules/objdetect/src/zxing/common/compress.hpp @@ -1,8 +1,19 @@ -#pragma once +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_COMPRESS_HPP__ +#define __ZXING_COMMON_COMPRESS_HPP__ + #include #include - namespace zxing { #define COMPRESS_BASE 256 @@ -14,17 +25,17 @@ public: ~CompressTools(); - std::string Compress(const std::string &sText); + std::string compress(const std::string &sText); - std::string Revert(const std::string &sCode); + std::string revert(const std::string &sCode); - bool CanBeCompress(const std::string &sText); + bool canBeCompress(const std::string &sText); - bool CanBeRevert(const std::string &sText); + bool canBeRevert(const std::string &sText); private: - int Encode(int iBase, const std::string &sBefore, std::string &sAfter); - int Decode(int iBase, const std::string &sBefore, std::string &sAfter); + int encode(int iBase, const std::string &sBefore, std::string &sAfter); + int decode(int iBase, const std::string &sBefore, std::string &sAfter); std::map m_tIntToChar[COMPRESS_BASE]; std::map m_tCharToInt[COMPRESS_BASE]; bool m_bSetFlag[COMPRESS_BASE]; @@ -32,3 +43,5 @@ private: int SetMap(int iBase, const std::string &sKey); }; } // namespace zxing + +#endif // __ZXING_COMMON_COMPRESS_HPP__ \ No newline at end of file diff --git a/modules/objdetect/src/zxing/common/counted.hpp b/modules/objdetect/src/zxing/common/counted.hpp index fff13e0c6b..4136c05df8 100644 --- a/modules/objdetect/src/zxing/common/counted.hpp +++ b/modules/objdetect/src/zxing/common/counted.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __COUNTED_H__ -#define __COUNTED_H__ +#ifndef __ZXING_COMMON_COUNTED_HPP__ +#define __ZXING_COMMON_COUNTED_HPP__ /* * Copyright 2010 ZXing authors All rights reserved. @@ -145,4 +155,4 @@ public: } -#endif // __COUNTED_H__ +#endif // __ZXING_COMMON_COUNTED_HPP__ diff --git a/modules/objdetect/src/zxing/common/debug_tools.hpp b/modules/objdetect/src/zxing/common/debug_tools.hpp index b36f7103c1..69622a9b7a 100644 --- a/modules/objdetect/src/zxing/common/debug_tools.hpp +++ b/modules/objdetect/src/zxing/common/debug_tools.hpp @@ -1,9 +1,21 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * @Author: ArlenCai * @Date: 2022-02-24 17:56:31 * @LastEditTime: 2022-02-28 11:48:22 */ -#pragma once +#ifndef __ZXING_COMMON_DEBUG_TOOLS_HPP__ +#define __ZXING_COMMON_DEBUG_TOOLS_HPP__ + #include static const std::string base64_chars = @@ -97,4 +109,5 @@ inline std::string base64_decode(std::string const& encoded_string) { } return ret; -} \ No newline at end of file +} +#endif // __ZXING_COMMON_DEBUG_TOOLS_HPP__ \ No newline at end of file diff --git a/modules/objdetect/src/zxing/common/decoder_result.cpp b/modules/objdetect/src/zxing/common/decoder_result.cpp index 1d4676241e..7c7db8f051 100644 --- a/modules/objdetect/src/zxing/common/decoder_result.cpp +++ b/modules/objdetect/src/zxing/common/decoder_result.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * DecoderResult.cpp diff --git a/modules/objdetect/src/zxing/common/decoder_result.hpp b/modules/objdetect/src/zxing/common/decoder_result.hpp index 7f96e3e276..6a816fd236 100644 --- a/modules/objdetect/src/zxing/common/decoder_result.hpp +++ b/modules/objdetect/src/zxing/common/decoder_result.hpp @@ -1,5 +1,15 @@ -#ifndef __DECODER_RESULT_H__ -#define __DECODER_RESULT_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_DECODER_RESULT_HPP__ +#define __ZXING_COMMON_DECODER_RESULT_HPP__ /* * DecoderResult.hpp @@ -116,4 +126,4 @@ public: } // namespace zxing -#endif // __DECODER_RESULT_H__ +#endif // __ZXING_COMMON_DECODER_RESULT_HPP__ diff --git a/modules/objdetect/src/zxing/common/detector/java_math.hpp b/modules/objdetect/src/zxing/common/detector/java_math.hpp index cf42fa4b8d..0e20b456d6 100644 --- a/modules/objdetect/src/zxing/common/detector/java_math.hpp +++ b/modules/objdetect/src/zxing/common/detector/java_math.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __ZXING_COMMON_DETECTOR_MATH_H__ -#define __ZXING_COMMON_DETECTOR_MATH_H__ +#ifndef __ZXING_COMMON_DETECTOR_JAVA_MATH_HPP__ +#define __ZXING_COMMON_DETECTOR_JAVA_MATH_HPP__ /* * Copyright 2012 ZXing authors All rights reserved. * @@ -40,4 +50,4 @@ class Math { } } -#endif +#endif // __ZXING_COMMON_DETECTOR_JAVA_MATH_HPP__ diff --git a/modules/objdetect/src/zxing/common/detector/math_utils.hpp b/modules/objdetect/src/zxing/common/detector/math_utils.hpp index 89a18b51b6..1327c27aff 100644 --- a/modules/objdetect/src/zxing/common/detector/math_utils.hpp +++ b/modules/objdetect/src/zxing/common/detector/math_utils.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __ZXING_COMMON_DETECTOR_MATHUTILS_H__ -#define __ZXING_COMMON_DETECTOR_MATHUTILS_H__ +#ifndef __ZXING_COMMON_DETECTOR_MATH_UTILS_HPP__ +#define __ZXING_COMMON_DETECTOR_MATH_UTILS_HPP__ /* * Copyright 2012 ZXing authors All rights reserved. * @@ -44,107 +54,106 @@ class MathUtils { * Ends up being a bit faster than {@link Math#round(float)}. This merely rounds its * argument to the nearest int, where x.5 rounds up to x+1. */ - static inline int round(double value) { - // return (int) (d + 0.5f); +static inline int round(double value) { +// return (int) (d + 0.5f); #if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ && defined __SSE2__ && !defined __APPLE__ && !defined __GXX_WEAK__) - __m128d t = _mm_set_sd(value); - return _mm_cvtsd_si32(t); + __m128d t = _mm_set_sd(value); + return _mm_cvtsd_si32(t); #elif defined _MSC_VER && defined _M_IX86 - int t; - __asm - { - fld value; - fistp t; - } - return t; + int t; + __asm + { + fld value; + fistp t; + } + return t; #elif defined _MSC_VER && defined _M_ARM && defined HAVE_TEGRA_OPTIMIZATION - TEGRA_ROUND(value); + TEGRA_ROUND(value); #elif defined HAVE_LRINT || defined CV_ICC || defined __GNUC__ # ifdef HAVE_TEGRA_OPTIMIZATION - TEGRA_ROUND(value); + TEGRA_ROUND(value); # else - return (int)lrint(value); + return (int)lrint(value); # endif #else - double intpart, fractpart; - fractpart = modf(value, &intpart); - if ((fabs(fractpart) != 0.5) || ((((int)intpart) % 2) != 0)) - return (int)(value + (value >= 0 ? 0.5 : -0.5)); - else - return (int)intpart; + double intpart, fractpart; + fractpart = modf(value, &intpart); + if ((fabs(fractpart) != 0.5) || ((((int)intpart) % 2) != 0)) + return (int)(value + (value >= 0 ? 0.5 : -0.5)); + else + return (int)intpart; #endif - } +} - static inline float distance(float aX, float aY, float bX, float bY) { +static inline float distance(float aX, float aY, float bX, float bY) { float xDiff = aX - bX; float yDiff = aY - bY; return sqrt(float(xDiff * xDiff + yDiff * yDiff)); - } +} - static inline float distance_4_int(int aX, int aY, int bX, int bY) { - return sqrt(float((aX-bX)*(aX-bX)+(aY-bY)*(aY-bY))); - } +static inline float distance_4_int(int aX, int aY, int bX, int bY) { + return sqrt(float((aX-bX)*(aX-bX)+(aY-bY)*(aY-bY))); +} - static inline void getRangeValues(int& minValue, int& maxValue, int min, int max) { - int finalMinValue, finalMaxValue; +static inline void getRangeValues(int& minValue, int& maxValue, int min, int max) { + int finalMinValue, finalMaxValue; - if (minValue < maxValue) - { - finalMinValue = minValue; - finalMaxValue = maxValue; - } - else - { - finalMinValue = maxValue; - finalMaxValue = minValue; - } + if (minValue < maxValue) + { + finalMinValue = minValue; + finalMaxValue = maxValue; + } + else + { + finalMinValue = maxValue; + finalMaxValue = minValue; + } - finalMinValue = finalMinValue > min ? finalMinValue : min; - finalMaxValue = finalMaxValue < max ? finalMaxValue : max; + finalMinValue = finalMinValue > min ? finalMinValue : min; + finalMaxValue = finalMaxValue < max ? finalMaxValue : max; - minValue = finalMinValue; - maxValue = finalMaxValue; - } + minValue = finalMinValue; + maxValue = finalMaxValue; +} - static inline bool isInRange(float x, float y, float width, float height) - { - if ((x >= 0.0 && x <= (width - 1.0)) && (y >= 0.0 && y <= (height - 1.0))) - { - return true; - } - else - { - return false; - } - } +static inline bool isInRange(float x, float y, float width, float height) +{ + if ((x >= 0.0 && x <= (width - 1.0)) && (y >= 0.0 && y <= (height - 1.0))) + { + return true; + } + else + { + return false; + } +} - static inline float distance(int aX, int aY, int bX, int bY) { - int xDiff = aX - bX; - int yDiff = aY - bY; - return sqrt(float(xDiff * xDiff + yDiff * yDiff)); - } - - static inline float VecCross(float* v1, float* v2) - { - return v1[0] * v2[1] - v1[1] * v2[0]; - } +static inline float distance(int aX, int aY, int bX, int bY) { + int xDiff = aX - bX; + int yDiff = aY - bY; + return sqrt(float(xDiff * xDiff + yDiff * yDiff)); +} +static inline float vecCross(float* v1, float* v2) +{ + return v1[0] * v2[1] - v1[1] * v2[0]; +} - static inline void Stddev(std::vector & resultSet, float & avg, float & stddev) - { - double sum = std::accumulate(resultSet.begin(), resultSet.end(), 0.0); - avg = sum / resultSet.size(); - - double accum = 0.0; - for (size_t i = 0; i < resultSet.size(); i++) - { - accum += (resultSet[i] - avg)*(resultSet[i] - avg); - } - - stddev = sqrt(accum / (resultSet.size())); - } +static inline void stddev(std::vector & resultSet, float & avg, float & stddev) +{ + double sum = std::accumulate(resultSet.begin(), resultSet.end(), 0.0); + avg = sum / resultSet.size(); + + double accum = 0.0; + for (size_t i = 0; i < resultSet.size(); i++) + { + accum += (resultSet[i] - avg)*(resultSet[i] - avg); + } + + stddev = sqrt(accum / (resultSet.size())); +} }; @@ -152,4 +161,4 @@ class MathUtils { } } -#endif +#endif // __ZXING_COMMON_DETECTOR_MATH_UTILS_HPP__ diff --git a/modules/objdetect/src/zxing/common/detector/monochrome_rectangle_detector.cpp b/modules/objdetect/src/zxing/common/detector/monochrome_rectangle_detector.cpp index 8def0b265c..19a9addd6d 100644 --- a/modules/objdetect/src/zxing/common/detector/monochrome_rectangle_detector.cpp +++ b/modules/objdetect/src/zxing/common/detector/monochrome_rectangle_detector.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * MonochromeRectangleDetector.cpp @@ -55,14 +65,14 @@ vector > MonochromeRectangleDetector::detect(ErrorHandler & err right = static_cast(pointC->getX()) + 1; Ref pointD(findCornerFromCenter(halfWidth, 0, left, right, halfHeight, deltaY, top, bottom, halfWidth >> 1, err_handler)); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); bottom = static_cast(pointD->getY()) + 1; // Go try to find point A again with better information -- might have been off at first. pointA.reset(findCornerFromCenter(halfWidth, 0, left, right, halfHeight, -deltaY, top, bottom, halfWidth >> 2, err_handler)); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); vector > corners(4); corners[0].reset(pointA); diff --git a/modules/objdetect/src/zxing/common/detector/monochrome_rectangle_detector.hpp b/modules/objdetect/src/zxing/common/detector/monochrome_rectangle_detector.hpp index 1a720b0085..8e6e27df16 100644 --- a/modules/objdetect/src/zxing/common/detector/monochrome_rectangle_detector.hpp +++ b/modules/objdetect/src/zxing/common/detector/monochrome_rectangle_detector.hpp @@ -1,7 +1,17 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __MONOCHROMERECTANGLEDETECTOR_H__ -#define __MONOCHROMERECTANGLEDETECTOR_H__ +#ifndef __ZXING_COMMON_DETECTOR_MONOCHROME_RECTANGLE_DETECTOR_HPP__ +#define __ZXING_COMMON_DETECTOR_MONOCHROME_RECTANGLE_DETECTOR_HPP__ /* * MonochromeRectangleDetector.hpp @@ -60,4 +70,4 @@ private: } // namespace zxing -#endif // __MONOCHROMERECTANGLEDETECTOR_H__ +#endif // __ZXING_COMMON_DETECTOR_MONOCHROME_RECTANGLE_DETECTOR_HPP__ diff --git a/modules/objdetect/src/zxing/common/detector/white_rectangle_detector.cpp b/modules/objdetect/src/zxing/common/detector/white_rectangle_detector.cpp index d7c725987b..d1603bfac6 100644 --- a/modules/objdetect/src/zxing/common/detector/white_rectangle_detector.cpp +++ b/modules/objdetect/src/zxing/common/detector/white_rectangle_detector.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * WhiteRectangleDetector.cpp diff --git a/modules/objdetect/src/zxing/common/detector/white_rectangle_detector.hpp b/modules/objdetect/src/zxing/common/detector/white_rectangle_detector.hpp index cfe2ab7d50..d388b8ec32 100644 --- a/modules/objdetect/src/zxing/common/detector/white_rectangle_detector.hpp +++ b/modules/objdetect/src/zxing/common/detector/white_rectangle_detector.hpp @@ -1,5 +1,15 @@ -#ifndef __WHITERECTANGLEDETECTOR_H__ -#define __WHITERECTANGLEDETECTOR_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_DETECTOR_WHITER_ECTANGLE_DETECTOR_HPP__ +#define __ZXING_COMMON_DETECTOR_WHITER_ECTANGLE_DETECTOR_HPP__ /* * WhiteRectangleDetector.hpp @@ -57,4 +67,4 @@ private: }; } // namespace zxing -#endif +#endif // __ZXING_COMMON_DETECTOR_WHITER_ECTANGLE_DETECTOR_HPP__ diff --git a/modules/objdetect/src/zxing/common/detector_result.cpp b/modules/objdetect/src/zxing/common/detector_result.cpp index 9cd99e5c72..60096414a7 100644 --- a/modules/objdetect/src/zxing/common/detector_result.cpp +++ b/modules/objdetect/src/zxing/common/detector_result.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * DetectorResult.cpp diff --git a/modules/objdetect/src/zxing/common/detector_result.hpp b/modules/objdetect/src/zxing/common/detector_result.hpp index cd1fd7cd39..f5dd3dca25 100644 --- a/modules/objdetect/src/zxing/common/detector_result.hpp +++ b/modules/objdetect/src/zxing/common/detector_result.hpp @@ -1,5 +1,15 @@ -#ifndef __DETECTOR_RESULT_H__ -#define __DETECTOR_RESULT_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_DETECTOR_RESULT_HPP__ +#define __ZXING_COMMON_DETECTOR_RESULT_HPP__ /* * DetectorResult.hpp diff --git a/modules/objdetect/src/zxing/common/fast_window_binarizer.cpp b/modules/objdetect/src/zxing/common/fast_window_binarizer.cpp index dcc72b5acd..57efdae698 100644 --- a/modules/objdetect/src/zxing/common/fast_window_binarizer.cpp +++ b/modules/objdetect/src/zxing/common/fast_window_binarizer.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * FastWindowBinarizer.cpp @@ -84,7 +94,7 @@ Ref FastWindowBinarizer::getBlackMatrix(ErrorHandler & err_handler) { if (!matrix0_) { binarizeImage1(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } return Binarizer::getBlackMatrix(err_handler); @@ -102,7 +112,7 @@ Ref FastWindowBinarizer::getBlackRow(int y, Ref row, ErrorHa if (!matrix0_) { binarizeImage1(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } // Call parent getBlackMatrix to get current matrix return Binarizer::getBlackRow(y, row, err_handler); @@ -199,7 +209,7 @@ int FastWindowBinarizer::binarizeImage1(ErrorHandler &err_handler){ int width = source.getWidth(); int height = source.getHeight(); Ref matrix(new BitMatrix(width, height, err_handler)); - if (err_handler.ErrCode()) return -1; + if (err_handler.errCode()) return -1; ArrayRef localLuminances = source.getMatrix(); @@ -207,7 +217,7 @@ int FastWindowBinarizer::binarizeImage1(ErrorHandler &err_handler){ unsigned char* dst = matrix->getPtr(); fastWindow(src, dst, width, height, err_handler); - if (err_handler.ErrCode()) return -1; + if (err_handler.errCode()) return -1; matrix0_ = matrix; return 0; @@ -283,7 +293,7 @@ int FastWindowBinarizer::binarizeImage0(ErrorHandler &err_handler) cumulative(_blockTotals, _totals, aw, ah); Ref newMatrix(new BitMatrix(width, height, err_handler)); - if (err_handler.ErrCode()) return -1; + if (err_handler.errCode()) return -1; unsigned char* newimg = newMatrix->getPtr(); for (int by = 0; by < ah; by++) diff --git a/modules/objdetect/src/zxing/common/fast_window_binarizer.hpp b/modules/objdetect/src/zxing/common/fast_window_binarizer.hpp index 062249e960..1d3343c4c2 100644 --- a/modules/objdetect/src/zxing/common/fast_window_binarizer.hpp +++ b/modules/objdetect/src/zxing/common/fast_window_binarizer.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __FASTWINDOWBINARIZER_H__ -#define __FASTWINDOWBINARIZER_H__ +#ifndef __ZXING_COMMON_FAST_WINDOW_BINARIZER_HPP__ +#define __ZXING_COMMON_FAST_WINDOW_BINARIZER_HPP__ /* * FastWindowBinarizer.hpp * zxing diff --git a/modules/objdetect/src/zxing/common/global_histogram_binarizer.cpp b/modules/objdetect/src/zxing/common/global_histogram_binarizer.cpp index a751d3395b..a86bda501d 100644 --- a/modules/objdetect/src/zxing/common/global_histogram_binarizer.cpp +++ b/modules/objdetect/src/zxing/common/global_histogram_binarizer.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * GlobalHistogramBinarizer.cpp @@ -63,7 +73,7 @@ Ref GlobalHistogramBinarizer::getBlackRow(int y, Ref row, Er if (!matrix0_) { binarizeImage0(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } // Call parent getBlackMatrix to get current matrix return Binarizer::getBlackRow(y, row, err_handler); @@ -72,7 +82,7 @@ Ref GlobalHistogramBinarizer::getBlackRow(int y, Ref row, Er // Does not sharpen the data, as this call is intended to only be used by 2D readers. Ref GlobalHistogramBinarizer::getBlackMatrix(ErrorHandler &err_handler) { binarizeImage0(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); // First call binarize image in child class to get matrix0_ and binCache // Call parent getBlackMatrix to get current matrix return Binarizer::getBlackMatrix(err_handler); @@ -320,7 +330,7 @@ int GlobalHistogramBinarizer::binarizeImage0(ErrorHandler & err_handler){ int width = source.getWidth(); int height = source.getHeight(); Ref matrix(new BitMatrix(width, height, err_handler)); - if (err_handler.ErrCode()) return -1; + if (err_handler.errCode()) return -1; // Quickly calculates the histogram by sampling four rows from the image. // This proved to be more robust on the blackbox tests than sampling a @@ -332,7 +342,7 @@ int GlobalHistogramBinarizer::binarizeImage0(ErrorHandler & err_handler){ for (int y = 1; y < 5; y++) { int row = height * y / 5; ArrayRef localLuminances = source.getRow(row, luminances, err_handler); - if (err_handler.ErrCode()) return -1; + if (err_handler.errCode()) return -1; int right = (width << 2) / 5; for (int x = width / 5; x < right; x++) { int pixel = localLuminances[x] & 0xff; @@ -348,7 +358,7 @@ int GlobalHistogramBinarizer::binarizeImage0(ErrorHandler & err_handler){ int right = (width << 2) / 5; for (; row localLuminances = source.getRow(row, luminances, err_handler); - if (err_handler.ErrCode()) return -1; + if (err_handler.errCode()) return -1; for (int x = width / 5; x < right; x+=2) { int pixel = localLuminances[x] & 0xff; localBuckets[pixel >> LUMINANCE_SHIFT]++; @@ -358,7 +368,7 @@ int GlobalHistogramBinarizer::binarizeImage0(ErrorHandler & err_handler){ else { ArrayRef localLuminances = source.getRow(row, luminances, err_handler); - if (err_handler.ErrCode()) return -1; + if (err_handler.errCode()) return -1; int right = (width << 2) / 5; for (int x = width / 5; x < right; x++) { int pixel = localLuminances[x] & 0xff; @@ -369,7 +379,7 @@ int GlobalHistogramBinarizer::binarizeImage0(ErrorHandler & err_handler){ #endif int blackPoint = estimateBlackPoint(localBuckets, err_handler); - if (err_handler.ErrCode()) return -1; + if (err_handler.errCode()) return -1; ArrayRef localLuminances = source.getMatrix(); for (int y = 0; y < height; y++) { diff --git a/modules/objdetect/src/zxing/common/global_histogram_binarizer.hpp b/modules/objdetect/src/zxing/common/global_histogram_binarizer.hpp index e1703d9c92..28c93b9d95 100644 --- a/modules/objdetect/src/zxing/common/global_histogram_binarizer.hpp +++ b/modules/objdetect/src/zxing/common/global_histogram_binarizer.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __GLOBALHISTOGRAMBINARIZER_H__ -#define __GLOBALHISTOGRAMBINARIZER_H__ +#ifndef __ZXING_COMMON_GLOBAL_HISTOGRAM_BINARIZER_HPP__ +#define __ZXING_COMMON_GLOBAL_HISTOGRAM_BINARIZER_HPP__ /* * GlobalHistogramBinarizer.hpp * zxing @@ -54,4 +64,4 @@ private: } // namespace zxing -#endif /* GLOBALHISTOGRAMBINARIZER_H_ */ +#endif // __ZXING_COMMON_GLOBAL_HISTOGRAM_BINARIZER_HPP__ diff --git a/modules/objdetect/src/zxing/common/greyscale_luminance_source.cpp b/modules/objdetect/src/zxing/common/greyscale_luminance_source.cpp index 2212882596..4b0f6fba0e 100644 --- a/modules/objdetect/src/zxing/common/greyscale_luminance_source.cpp +++ b/modules/objdetect/src/zxing/common/greyscale_luminance_source.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * GreyscaleLuminanceSource.cpp @@ -90,7 +100,7 @@ Ref GreyscaleLuminanceSource::rotateCounterClockwise(ErrorHandl new GreyscaleRotatedLuminanceSource(greyData_, dataWidth_, dataHeight_, top_, left_, getHeight(), getWidth(), err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return result; } diff --git a/modules/objdetect/src/zxing/common/greyscale_luminance_source.hpp b/modules/objdetect/src/zxing/common/greyscale_luminance_source.hpp index 4c5f225eec..998106783f 100644 --- a/modules/objdetect/src/zxing/common/greyscale_luminance_source.hpp +++ b/modules/objdetect/src/zxing/common/greyscale_luminance_source.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __GREYSCALE_LUMINANCE_SOURCE__ -#define __GREYSCALE_LUMINANCE_SOURCE__ +#ifndef __ZXING_COMMON_GLOBAL_GREYSCALE_LUMINANCE_SOURCE_HPP__ +#define __ZXING_COMMON_GLOBAL_GREYSCALE_LUMINANCE_SOURCE_HPP__ /* * GreyscaleLuminanceSource.hpp * zxing @@ -54,4 +64,4 @@ public: } // namespace zxing -#endif +#endif // __ZXING_COMMON_GLOBAL_GREYSCALE_LUMINANCE_SOURCE_HPP__ diff --git a/modules/objdetect/src/zxing/common/greyscale_rotated_luminance_source.cpp b/modules/objdetect/src/zxing/common/greyscale_rotated_luminance_source.cpp index c52c6b7e11..fc279dec29 100644 --- a/modules/objdetect/src/zxing/common/greyscale_rotated_luminance_source.cpp +++ b/modules/objdetect/src/zxing/common/greyscale_rotated_luminance_source.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * GreyscaleRotatedLuminanceSource.cpp diff --git a/modules/objdetect/src/zxing/common/greyscale_rotated_luminance_source.hpp b/modules/objdetect/src/zxing/common/greyscale_rotated_luminance_source.hpp index 9da6644857..2195c9c144 100644 --- a/modules/objdetect/src/zxing/common/greyscale_rotated_luminance_source.hpp +++ b/modules/objdetect/src/zxing/common/greyscale_rotated_luminance_source.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __GREYSCALE_ROTATED_LUMINANCE_SOURCE__ -#define __GREYSCALE_ROTATED_LUMINANCE_SOURCE__ +#ifndef __ZXING_COMMON_GLOBAL_GREYSCALE_ROTATED_LUMINANCE_SOURCE_HPP__ +#define __ZXING_COMMON_GLOBAL_GREYSCALE_ROTATED_LUMINANCE_SOURCE_HPP__ /* * GreyscaleRotatedLuminanceSource.hpp * zxing @@ -45,4 +55,4 @@ public: } // namespace zxing -#endif +#endif // __ZXING_COMMON_GLOBAL_GREYSCALE_ROTATED_LUMINANCE_SOURCE_HPP__ diff --git a/modules/objdetect/src/zxing/common/grid_sampler.cpp b/modules/objdetect/src/zxing/common/grid_sampler.cpp index 7661ccd8d0..43c345c8c4 100644 --- a/modules/objdetect/src/zxing/common/grid_sampler.cpp +++ b/modules/objdetect/src/zxing/common/grid_sampler.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * GridSampler.cpp * zxing @@ -51,7 +61,7 @@ Ref GridSampler::sampleGrid(Ref image, int dimension, Re // Quick check to see if points transformed to something inside the image; // sufficient to check the endpoings outlier += checkAndNudgePoints(image->getWidth(), image->getHeight(), points, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); if (outlier >= maxOutlier) { @@ -72,7 +82,7 @@ Ref GridSampler::sampleGrid(Ref image, int dimension, Re Ref GridSampler::sampleGrid(Ref image, int dimension, Ref transform, ErrorHandler &err_handler) { Ref bits(new BitMatrix(dimension, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); std::vector points(dimension << 1, (const float)0.0f); @@ -91,7 +101,7 @@ Ref GridSampler::sampleGrid(Ref image, int dimension, Ref< // Quick check to see if points transformed to something inside the image; // sufficient to check the endpoings outlier += checkAndNudgePoints(image->getWidth(), image->getHeight(), points, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); if (outlier >= maxOutlier) { @@ -159,7 +169,7 @@ Ref GridSampler::sampleGrid(Ref image, int dimension, Ref< Ref GridSampler::sampleGrid(Ref image, int dimension, cv::Mat& transform, ErrorHandler &err_handler) { Ref bits(new BitMatrix(dimension, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); std::vector points(dimension); @@ -177,7 +187,7 @@ Ref GridSampler::sampleGrid(Ref image, int dimension, cv:: // Quick check to see if points transformed to something inside the image; // sufficient to check the endpoings outlier += checkAndNudgePoints(image->getWidth(), image->getHeight(), points, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); if (outlier >= maxOutlier) { @@ -249,7 +259,7 @@ Ref GridSampler::sampleGrid(Ref image, int dimension, { Ref bits(new BitMatrix(dimension, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); std::vector points(dimension); @@ -270,7 +280,7 @@ Ref GridSampler::sampleGrid(Ref image, int dimension, // Quick check to see if points transformed to something inside the image; // sufficient to check the endpoings outlier += checkAndNudgePoints(image->getWidth(), image->getHeight(), points, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); if (outlier >= maxOutlier) { @@ -337,7 +347,7 @@ Ref GridSampler::sampleGrid(Ref image, int dimension, Ref GridSampler::sampleGrid(Ref image, int dimensionX, int dimensionY, Ref transform, ErrorHandler &err_handler) { Ref bits(new BitMatrix(dimensionX, dimensionY, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); std::vector points(dimensionX << 1, (const float)0.0f); for (int y = 0; y < dimensionY; y++) { @@ -350,7 +360,7 @@ Ref GridSampler::sampleGrid(Ref image, int dimensionX, int } transform->transformPoints(points); checkAndNudgePoints(image->getWidth(), image->getHeight(), points, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); for (int x = 0; x < max; x += 2) { if (image->get(static_cast(points[x]), static_cast(points[x + 1]))) @@ -370,7 +380,7 @@ Ref GridSampler::sampleGrid(Ref image, int dimension, floa p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY)); Ref rst = sampleGrid(image, dimension, transform, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return rst; } @@ -382,7 +392,7 @@ Ref GridSampler::sampleGrid(Ref image, int dimensionX, int p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY)); Ref rst = sampleGrid(image, dimensionX, dimensionY, transform, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return rst; } diff --git a/modules/objdetect/src/zxing/common/grid_sampler.hpp b/modules/objdetect/src/zxing/common/grid_sampler.hpp index 340f23b301..b998048d84 100644 --- a/modules/objdetect/src/zxing/common/grid_sampler.hpp +++ b/modules/objdetect/src/zxing/common/grid_sampler.hpp @@ -1,5 +1,15 @@ -#ifndef __GRID_SAMPLER_H__ -#define __GRID_SAMPLER_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_GRID_SAMPLER_HPP__ +#define __ZXING_COMMON_GRID_SAMPLER_HPP__ /* * GridSampler.hpp @@ -57,4 +67,4 @@ public: }; } // namespace zxing -#endif // __GRID_SAMPLER_H__ +#endif // __ZXING_COMMON_GRID_SAMPLER_HPP__ diff --git a/modules/objdetect/src/zxing/common/hybrid_binarizer.cpp b/modules/objdetect/src/zxing/common/hybrid_binarizer.cpp index 8b4e0b7b56..e13924d95c 100644 --- a/modules/objdetect/src/zxing/common/hybrid_binarizer.cpp +++ b/modules/objdetect/src/zxing/common/hybrid_binarizer.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * HybridBinarizer.cpp @@ -73,7 +83,7 @@ HybridBinarizer::createBinarizer(Ref source) { return Ref (new GlobalHistogramBinarizer(source)); } -/* Init integral +/* init integral */ int HybridBinarizer::initBlockIntegral() { @@ -134,7 +144,7 @@ Ref HybridBinarizer::getBlackMatrix(ErrorHandler &err_handler) if (!matrix0_) { binarizeByBlock(0, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } // First call binarize image in child class to get matrix0_ and binCache @@ -154,7 +164,7 @@ Ref HybridBinarizer::getBlackRow(int y, Ref row, ErrorHandle if (!matrix0_) { binarizeByBlock(0, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } // Call parent getBlackMatrix to get current matrix @@ -247,7 +257,7 @@ void HybridBinarizer::calculateThresholdForBlock(Ref& luminances, int average = sum / blockArea; thresholdBlock(luminances, xoffset, yoffset, average, width, matrix, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } } } @@ -321,7 +331,7 @@ void HybridBinarizer::calculateThresholdForBlock(Ref& luminances, int average = sum / 25; #ifndef USE_SET_INT thresholdBlock(luminances, xoffset, yoffset, average, width, matrix, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; #else // handle 4 blacks one time int k = x % setIntCircle; @@ -370,7 +380,7 @@ void HybridBinarizer::calculateThresholdForBlock(Ref& luminances, } int average = sum / blockArea; thresholdBlock(luminances, xoffset, yoffset, average, width, matrix, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } } #endif @@ -425,7 +435,7 @@ void HybridBinarizer::thresholdBlock(Ref& luminances, int rowStep = rowSize - BLOCK_SIZE; unsigned char* pTemp = luminances->getByteRow(yoffset, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; bool* bpTemp = matrix->getRowBoolPtr(yoffset); pTemp += xoffset; @@ -458,7 +468,7 @@ void HybridBinarizer::thresholdIrregularBlock(Ref& luminances, for (int y = 0; y < blockHeight; y++) { unsigned char* pTemp = luminances->getByteRow(yoffset+y, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; pTemp = pTemp + xoffset; for (int x = 0; x < blockWidth; x++){ // comparison needs to be <= so that black == 0 pixels are black even if the threshold is 0. @@ -749,10 +759,10 @@ int HybridBinarizer::binarizeByBlock(int blockLevel, ErrorHandler & err_handler) if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) { Ref newMatrix (new BitMatrix(width, height, err_handler)); - if (err_handler.ErrCode()) return -1; + if (err_handler.errCode()) return -1; calculateThresholdForBlock(grayByte_, subWidth_, subHeight_, width, height, BLOCK_SIZE_POWER, newMatrix, err_handler); - if (err_handler.ErrCode()) return -1; + if (err_handler.errCode()) return -1; matrix0_ = newMatrix; } @@ -760,7 +770,7 @@ int HybridBinarizer::binarizeByBlock(int blockLevel, ErrorHandler & err_handler) { // If the image is too small, fall back to the global histogram approach. matrix0_ = GlobalHistogramBinarizer::getBlackMatrix(err_handler); - if (err_handler.ErrCode()) return 1; + if (err_handler.errCode()) return 1; } return 1; diff --git a/modules/objdetect/src/zxing/common/hybrid_binarizer.hpp b/modules/objdetect/src/zxing/common/hybrid_binarizer.hpp index abda28182c..f64c006d76 100644 --- a/modules/objdetect/src/zxing/common/hybrid_binarizer.hpp +++ b/modules/objdetect/src/zxing/common/hybrid_binarizer.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __HYBRIDBINARIZER_H__ -#define __HYBRIDBINARIZER_H__ +#ifndef __ZXING_COMMON_HYBRID_BINARIZER_HPP__ +#define __ZXING_COMMON_HYBRID_BINARIZER_HPP__ /* * HybridBinarizer.hpp * zxing @@ -139,4 +149,4 @@ private: } // namespace zxing -#endif +#endif // __ZXING_COMMON_HYBRID_BINARIZER_HPP__ diff --git a/modules/objdetect/src/zxing/common/illegal_argument_exception.cpp b/modules/objdetect/src/zxing/common/illegal_argument_exception.cpp index c9408834c3..2759c6011d 100644 --- a/modules/objdetect/src/zxing/common/illegal_argument_exception.cpp +++ b/modules/objdetect/src/zxing/common/illegal_argument_exception.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * IllegalArgumentException.cpp * zxing diff --git a/modules/objdetect/src/zxing/common/illegal_argument_exception.hpp b/modules/objdetect/src/zxing/common/illegal_argument_exception.hpp index 0a96f5d423..4c7c937538 100644 --- a/modules/objdetect/src/zxing/common/illegal_argument_exception.hpp +++ b/modules/objdetect/src/zxing/common/illegal_argument_exception.hpp @@ -1,5 +1,15 @@ -#ifndef __ILLEGAL_ARGUMENT_EXCEPTION_H__ -#define __ILLEGAL_ARGUMENT_EXCEPTION_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_ILLEGAL_ARGUMENT_EXCEPTION_HPP__ +#define __ZXING_COMMON_ILLEGAL_ARGUMENT_EXCEPTION_HPP__ /* * IllegalArgumentException.hpp @@ -34,4 +44,4 @@ public: } // namespace zxing -#endif // __ILLEGAL_ARGUMENT_EXCEPTION_H__ +#endif // __ZXING_COMMON_ILLEGAL_ARGUMENT_EXCEPTION_HPP__ diff --git a/modules/objdetect/src/zxing/common/image_cut.cpp b/modules/objdetect/src/zxing/common/image_cut.cpp index dae7eb69d6..1ceaa2a833 100644 --- a/modules/objdetect/src/zxing/common/image_cut.cpp +++ b/modules/objdetect/src/zxing/common/image_cut.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + #include "image_cut.hpp" #include @@ -15,7 +25,7 @@ ImageCut::~ImageCut() } -int ImageCut::Cut(uint8_t * poImageData, int iWidth, int iHeight, int iTopLeftX, int iTopLeftY, int iBottomRightX, int iBottomRightY, ImageCutResult & result) +int ImageCut::cut(uint8_t * poImageData, int iWidth, int iHeight, int iTopLeftX, int iTopLeftY, int iBottomRightX, int iBottomRightY, ImageCutResult & result) { if (iTopLeftX < 0 || iTopLeftX > iBottomRightX || iBottomRightX >= iWidth) return -1; if (iTopLeftY < 0 || iTopLeftY > iBottomRightY || iBottomRightY >= iHeight) return -1; @@ -39,7 +49,7 @@ int ImageCut::Cut(uint8_t * poImageData, int iWidth, int iHeight, int iTopLeftX, return 0; } -int ImageCut::Cut( Ref matrix, float fRatio, ImageCutResult & result) +int ImageCut::cut( Ref matrix, float fRatio, ImageCutResult & result) { int iWidth = matrix->getWidth(); int iHeight = matrix->getHeight(); diff --git a/modules/objdetect/src/zxing/common/image_cut.hpp b/modules/objdetect/src/zxing/common/image_cut.hpp index 3ae111adaa..e71767c467 100644 --- a/modules/objdetect/src/zxing/common/image_cut.hpp +++ b/modules/objdetect/src/zxing/common/image_cut.hpp @@ -1,4 +1,16 @@ -#pragma once +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_IMAGE_CUT_HPP__ +#define __ZXING_COMMON_IMAGE_CUT_HPP__ + #include #include #include "counted.hpp" @@ -20,8 +32,9 @@ public: ImageCut(); ~ImageCut(); - static int Cut(uint8_t * poImageData, int iWidth, int iHeight, int iTopLeftX, int iTopLeftY, int iBottomRightX, int iBottomRightY, ImageCutResult & result); - static int Cut( Ref matrix , float fRatio, ImageCutResult & result); + static int cut(uint8_t * poImageData, int iWidth, int iHeight, int iTopLeftX, int iTopLeftY, int iBottomRightX, int iBottomRightY, ImageCutResult & result); + static int cut( Ref matrix , float fRatio, ImageCutResult & result); }; } // namespace zxing +#endif // __ZXING_COMMON_IMAGE_CUT_HPP__ \ No newline at end of file diff --git a/modules/objdetect/src/zxing/common/integer.hpp b/modules/objdetect/src/zxing/common/integer.hpp index da47b58ad1..c543edf588 100644 --- a/modules/objdetect/src/zxing/common/integer.hpp +++ b/modules/objdetect/src/zxing/common/integer.hpp @@ -1,9 +1,18 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_INTEGER_HPP__ +#define __ZXING_COMMON_INTEGER_HPP__ + #include -#ifndef ZXing_Integer_h -#define ZXing_Integer_h - - namespace zxing { @@ -28,4 +37,4 @@ public: } -#endif +#endif // __ZXING_COMMON_INTEGER_HPP__ diff --git a/modules/objdetect/src/zxing/common/kmeans.cpp b/modules/objdetect/src/zxing/common/kmeans.cpp index f82b85251f..05517409b6 100644 --- a/modules/objdetect/src/zxing/common/kmeans.cpp +++ b/modules/objdetect/src/zxing/common/kmeans.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + #include "kmeans.hpp" #include "util/inireader.hpp" @@ -12,8 +22,8 @@ namespace zxing double cal_distance(std::vector a, std::vector b) { - float KMEANS_COUNT_FACTOR = GetIniParser()->GetReal("FP_SELECT", "KMEANS_COUNT_FACTOR", 0.0); - float KMEANS_MS_FACTOR = GetIniParser()->GetReal("FP_SELECT", "KMEANS_MS_FACTOR", 1.0); + float KMEANS_COUNT_FACTOR = GetIniParser()->getReal("FP_SELECT", "KMEANS_COUNT_FACTOR", 0.0); + float KMEANS_MS_FACTOR = GetIniParser()->getReal("FP_SELECT", "KMEANS_MS_FACTOR", 1.0); uint da = a.size(); uint db = b.size(); diff --git a/modules/objdetect/src/zxing/common/kmeans.hpp b/modules/objdetect/src/zxing/common/kmeans.hpp index fc2fd855af..51ebaee91e 100644 --- a/modules/objdetect/src/zxing/common/kmeans.hpp +++ b/modules/objdetect/src/zxing/common/kmeans.hpp @@ -1,4 +1,15 @@ -#pragma once +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_KMEANS_HPP__ +#define __ZXING_COMMON_KMEANS_HPP__ #include @@ -17,3 +28,4 @@ double cal_distance(std::vector a, std::vector b); std::vector k_means(std::vector > trainX, uint k, uint maxepoches, uint minchanged); } // namespace zxing +#endif // __ZXING_COMMON_KMEANS_HPP__ \ No newline at end of file diff --git a/modules/objdetect/src/zxing/common/new_grid_sampler.cpp b/modules/objdetect/src/zxing/common/new_grid_sampler.cpp index 18c6c613d9..525e804c43 100644 --- a/modules/objdetect/src/zxing/common/new_grid_sampler.cpp +++ b/modules/objdetect/src/zxing/common/new_grid_sampler.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + #include "new_grid_sampler.hpp" #include "perspective_transform.hpp" #include "../reader_exception.hpp" @@ -33,7 +43,7 @@ Ref NewGridSampler::sampleGrid(Ref image, int dimension, // Quick check to see if points transformed to something inside the image; // sufficient to check the endpoings outlier += checkAndNudgePoints(image->getWidth(), image->getHeight(), points, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); if (outlier >= maxOutlier) { @@ -53,7 +63,7 @@ Ref NewGridSampler::sampleGrid(Ref image, int dimension, // Samples an image for a rectangular matrix of bits of the given dimension. Ref NewGridSampler::sampleGrid(Ref image, int dimension, Ref transform, float fInitialMS, ErrorHandler & err_handler) { Ref bits(new BitMatrix(dimension, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); std::vector points(dimension << 1, (const float)0.0f); @@ -83,20 +93,20 @@ Ref NewGridSampler::sampleGrid(Ref image, int dimension, R if (vcCornerPoints[i] < 0 || vcCornerPoints[i] >= iWidth) { float outLen = vcCornerPoints[i] < 0 ? (-vcCornerPoints[i]) : (vcCornerPoints[i] - iWidth + 1); - if (outLen / fInitialMS > GetIniParser()->GetReal("NEW_GRID_SAMPLER", "OUT_OF_BOUNDS", 9)) + if (outLen / fInitialMS > GetIniParser()->getReal("NEW_GRID_SAMPLER", "OUT_OF_BOUNDS", 9)) { err_handler = ReaderErrorHandler("width out of bounds."); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } } if (vcCornerPoints[i+1] < 0 || vcCornerPoints[i+1] >= iHeight) { float outLen = vcCornerPoints[i+1] < 0 ? (-vcCornerPoints[i+1]) : (vcCornerPoints[i+1] - iHeight + 1); // printf("f\n", outLen / fInitialMS); - if (outLen / fInitialMS > GetIniParser()->GetReal("NEW_GRID_SAMPLER", "OUT_OF_BOUNDS", 9)) + if (outLen / fInitialMS > GetIniParser()->getReal("NEW_GRID_SAMPLER", "OUT_OF_BOUNDS", 9)) { err_handler = ReaderErrorHandler("height out of bounds."); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } } } @@ -129,14 +139,14 @@ Ref NewGridSampler::sampleGrid(Ref image, int dimension, R float fLenAvg = (fLenAB + fLenAD + fLenCB + fLenCD) / 4; float fAreaSqua = fLenAvg * fLenAvg; if (fAreaSqua > 1e-8 - && fAreaQua / fAreaSqua > GetIniParser()->GetReal("NEW_GRID_SAMPLER", "SHAPE_MIN_RATIO", 0.95) - && fAreaQua / fAreaSqua < GetIniParser()->GetReal("NEW_GRID_SAMPLER", "SHAPE_MAX_RATIO", 1.05)) + && fAreaQua / fAreaSqua > GetIniParser()->getReal("NEW_GRID_SAMPLER", "SHAPE_MIN_RATIO", 0.95) + && fAreaQua / fAreaSqua < GetIniParser()->getReal("NEW_GRID_SAMPLER", "SHAPE_MAX_RATIO", 1.05)) { } else { err_handler = ReaderErrorHandler("shape not valid"); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } } @@ -151,14 +161,14 @@ Ref NewGridSampler::sampleGrid(Ref image, int dimension, R // Quick check to see if points transformed to something inside the image; // sufficient to check the endpoings outlier += checkAndNudgePoints(image->getWidth(), image->getHeight(), points, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); if (outlier >= maxOutlier) { std::ostringstream s; s << "Over 30% points out of bounds."; err_handler = ReaderErrorHandler(s.str().c_str()); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } for (int x = 0; x < max; x += 2) { @@ -182,7 +192,7 @@ int NewGridSampler::checkAndNudgePoints(int width, int height, std::vectorgetCoefficients()[0] = 0; one = Ref(new GenericGFPoly(*this, ArrayRef(new Array(1)), err_handler)); one->getCoefficients()[0] = 1; - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } Ref GenericGF::getZero() { @@ -78,7 +88,7 @@ Ref GenericGF::buildMonomial(int degree, int coefficient, ErrorHa coefficients[0] = coefficient; Ref gfpoly(new GenericGFPoly(*this, coefficients, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return gfpoly; } diff --git a/modules/objdetect/src/zxing/common/reedsolomon/generic_gf.hpp b/modules/objdetect/src/zxing/common/reedsolomon/generic_gf.hpp index d06fdf3b3b..f42e0eb8de 100644 --- a/modules/objdetect/src/zxing/common/reedsolomon/generic_gf.hpp +++ b/modules/objdetect/src/zxing/common/reedsolomon/generic_gf.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * GenericGF.hpp @@ -19,8 +29,8 @@ * limitations under the License. */ -#ifndef GENERICGF_H -#define GENERICGF_H +#ifndef __ZXING_COMMON_REEDSOLOMON_GENERIC_GF_HPP__ +#define __ZXING_COMMON_REEDSOLOMON_GENERIC_GF_HPP__ #include #include "../counted.hpp" @@ -66,5 +76,5 @@ public: }; } // namespace zxing -#endif // gENERICGF_H +#endif // __ZXING_COMMON_REEDSOLOMON_GENERIC_GF_HPP__ diff --git a/modules/objdetect/src/zxing/common/reedsolomon/generic_gfpoly.cpp b/modules/objdetect/src/zxing/common/reedsolomon/generic_gfpoly.cpp index 75d6ebe9cb..b978755f78 100644 --- a/modules/objdetect/src/zxing/common/reedsolomon/generic_gfpoly.cpp +++ b/modules/objdetect/src/zxing/common/reedsolomon/generic_gfpoly.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * GenericGFPoly.cpp @@ -144,7 +154,7 @@ Ref GenericGFPoly::addOrSubtract(Ref other, } Ref gfpoly(new GenericGFPoly(field_, sumDiff, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return gfpoly; } @@ -176,7 +186,7 @@ Ref GenericGFPoly::multiply(Ref other, Erro } Ref gfpoly(new GenericGFPoly(field_, product, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return gfpoly; } @@ -196,7 +206,7 @@ Ref GenericGFPoly::multiply(int scalar, ErrorHandler & err_handle } Ref gfpoly(new GenericGFPoly(field_, product, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return gfpoly; } @@ -215,7 +225,7 @@ Ref GenericGFPoly::multiplyByMonomial(int degree, int coefficient } Ref gfpoly(new GenericGFPoly(field_, product, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return gfpoly; } @@ -236,19 +246,19 @@ std::vector > GenericGFPoly::divide(Ref other, int denominatorLeadingTerm = other->getCoefficient(other->getDegree()); int inverseDenominatorLeadingTerm = field_.inverse(denominatorLeadingTerm, err_handler); - if (err_handler.ErrCode()) return std::vector >(); + if (err_handler.errCode()) return std::vector >(); while (remainder->getDegree() >= other->getDegree() && !remainder->isZero()) { int degreeDifference = remainder->getDegree() - other->getDegree(); int scale = field_.multiply(remainder->getCoefficient(remainder->getDegree()), inverseDenominatorLeadingTerm); Ref term = other->multiplyByMonomial(degreeDifference, scale, err_handler); - if (err_handler.ErrCode()) return std::vector >(); + if (err_handler.errCode()) return std::vector >(); Ref iterationQuotiont = field_.buildMonomial(degreeDifference, scale, err_handler); - if (err_handler.ErrCode()) return std::vector >(); + if (err_handler.errCode()) return std::vector >(); quotient = quotient->addOrSubtract(iterationQuotiont, err_handler); remainder = remainder->addOrSubtract(term, err_handler); - if (err_handler.ErrCode()) return std::vector >(); + if (err_handler.errCode()) return std::vector >(); } std::vector > returnValue(2); diff --git a/modules/objdetect/src/zxing/common/reedsolomon/generic_gfpoly.hpp b/modules/objdetect/src/zxing/common/reedsolomon/generic_gfpoly.hpp index b2ff5fafee..9119a52f32 100644 --- a/modules/objdetect/src/zxing/common/reedsolomon/generic_gfpoly.hpp +++ b/modules/objdetect/src/zxing/common/reedsolomon/generic_gfpoly.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * GenericGFPoly.hpp @@ -19,8 +29,8 @@ * limitations under the License. */ -#ifndef GENERICGFPOLY_H -#define GENERICGFPOLY_H +#ifndef __ZXING_COMMON_REEDSOLOMON_GENERIC_GFPOLY_HPP_ +#define __ZXING_COMMON_REEDSOLOMON_GENERIC_GFPOLY_HPP_ #include #include "../array.hpp" @@ -52,4 +62,4 @@ public: } // namespace zxing -#endif // gENERICGFPOLY_H +#endif // __ZXING_COMMON_REEDSOLOMON_GENERIC_GFPOLY_HPP_ diff --git a/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_decoder.cpp b/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_decoder.cpp index fad8d05821..e2b2e8c11b 100644 --- a/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_decoder.cpp +++ b/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_decoder.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Created by Christian Brunschen on 05/05/2008. @@ -42,7 +52,7 @@ ReedSolomonDecoder::~ReedSolomonDecoder() { void ReedSolomonDecoder::decode(ArrayRef received, int twoS, ErrorHandler & err_handler) { Ref poly(new GenericGFPoly(*field, received, err_handler)); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; ArrayRef syndromeCoefficients(twoS); bool noError = true; for (int i = 0; i < twoS; i++) { @@ -59,25 +69,25 @@ void ReedSolomonDecoder::decode(ArrayRef received, int twoS, ErrorHandler & } Ref syndrome(new GenericGFPoly(*field, syndromeCoefficients, err_handler)); Ref monomial = field->buildMonomial(twoS, 1, err_handler); - if (!monomial || err_handler.ErrCode()) + if (!monomial || err_handler.errCode()) { err_handler = ErrorHandler("buildMonomial was zero"); return; } vector > sigmaOmega = runEuclideanAlgorithm(monomial, syndrome, twoS, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; Ref sigma = sigmaOmega[0]; Ref omega = sigmaOmega[1]; ArrayRef errorLocations = findErrorLocations(sigma, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; ArrayRef errorMagitudes = findErrorMagnitudes(omega, errorLocations, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; for (int i = 0; i < errorLocations->size(); i++) { int position = received->size() - 1 - field->log(errorLocations[i], err_handler); - if (position < 0 || err_handler.ErrCode()) { + if (position < 0 || err_handler.errCode()) { err_handler = ErrorHandler("Bad error location"); return; } @@ -121,19 +131,19 @@ vector > ReedSolomonDecoder::runEuclideanAlgorithm(Ref q = field->getZero(); int denominatorLeadingTerm = rLast->getCoefficient(rLast->getDegree()); int dltInverse = field->inverse(denominatorLeadingTerm, err_handler); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); while (r->getDegree() >= rLast->getDegree() && !r->isZero()) { int degreeDiff = r->getDegree() - rLast->getDegree(); int scale = field->multiply(r->getCoefficient(r->getDegree()), dltInverse); q = q->addOrSubtract(field->buildMonomial(degreeDiff, scale, err_handler), err_handler); r = r->addOrSubtract(rLast->multiplyByMonomial(degreeDiff, scale, err_handler), err_handler); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); } Ref tmp = q->multiply(tLast, err_handler); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); t = tmp->addOrSubtract(tLastLast, err_handler); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); if (r->getDegree() >= rLast->getDegree()) { @@ -152,7 +162,7 @@ vector > ReedSolomonDecoder::runEuclideanAlgorithm(Refinverse(sigmaTildeAtZero, err_handler); Ref sigma(t->multiply(inverse, err_handler)); Ref omega(r->multiply(inverse, err_handler)); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); result[0] = sigma; result[1] = omega; @@ -177,7 +187,7 @@ ArrayRef ReedSolomonDecoder::findErrorLocations(Ref errorLoc e++; } } - if (e != numErrors || err_handler.ErrCode()) + if (e != numErrors || err_handler.errCode()) { err_handler = ErrorHandler("Error locator degree does not match number of root"); return ArrayRef(); @@ -205,6 +215,6 @@ ArrayRef ReedSolomonDecoder::findErrorMagnitudes(Ref errorEv result[i] = field->multiply(result[i], xiInverse); } } - if (err_handler.ErrCode()) return ArrayRef(); + if (err_handler.errCode()) return ArrayRef(); return result; } diff --git a/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_decoder.hpp b/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_decoder.hpp index 9e5258b2f8..8744e4b2cc 100644 --- a/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_decoder.hpp +++ b/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_decoder.hpp @@ -1,5 +1,15 @@ -#ifndef __REED_SOLOMON_DECODER_H__ -#define __REED_SOLOMON_DECODER_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_REEDSOLOMON_REED_SOLOMON_DECODER_HPP__ +#define __ZXING_REEDSOLOMON_REED_SOLOMON_DECODER_HPP__ /* * ReedSolomonDecoder.hpp @@ -47,4 +57,4 @@ private: }; } // namespace zxing -#endif // __REED_SOLOMON_DECODER_H__ +#endif // __ZXING_REEDSOLOMON_REED_SOLOMON_DECODER_HPP__ diff --git a/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_exception.cpp b/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_exception.cpp index 8c87c51460..04e8efd34e 100644 --- a/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_exception.cpp +++ b/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_exception.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * ReedSolomonException.cpp * zxing diff --git a/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_exception.hpp b/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_exception.hpp index 5276c6a78e..db0aaf3513 100644 --- a/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_exception.hpp +++ b/modules/objdetect/src/zxing/common/reedsolomon/reed_solomon_exception.hpp @@ -1,5 +1,15 @@ -#ifndef __REED_SOLOMON_EXCEPTION_H__ -#define __REED_SOLOMON_EXCEPTION_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_REEDSOLOMON_REED_SOLOMON_EXCEPTION_HPP__ +#define __ZXING_REEDSOLOMON_REED_SOLOMON_EXCEPTION_HPP__ /* * ReedSolomonException.hpp @@ -30,4 +40,4 @@ public: }; } // namespace zxing -#endif // __REED_SOLOMON_EXCEPTION_H__ +#endif // __ZXING_REEDSOLOMON_REED_SOLOMON_EXCEPTION_HPP__ diff --git a/modules/objdetect/src/zxing/common/simple_adaptive_binarizer.cpp b/modules/objdetect/src/zxing/common/simple_adaptive_binarizer.cpp index c613f7262b..97f27dbcd9 100644 --- a/modules/objdetect/src/zxing/common/simple_adaptive_binarizer.cpp +++ b/modules/objdetect/src/zxing/common/simple_adaptive_binarizer.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * SimpleAdaptiveBinarizer.cpp @@ -45,7 +55,7 @@ Ref SimpleAdaptiveBinarizer::getBlackRow(int y, Ref row, Err // First call binarize image in child class to get matrix0_ and binCache if (!matrix0_) { binarizeImage0(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } // Call parent getBlackMatrix to get current matrix return Binarizer::getBlackRow(y, row, err_handler); @@ -56,7 +66,7 @@ Ref SimpleAdaptiveBinarizer::getBlackMatrix(ErrorHandler &err_handler // First call binarize image in child class to get matrix0_ and binCache if (!matrix0_) { binarizeImage0(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } // First call binarize image in child class to get matrix0_ and binCache @@ -69,7 +79,7 @@ int SimpleAdaptiveBinarizer::binarizeImage0(ErrorHandler &err_handler){ int width = source.getWidth(); int height = source.getHeight(); Ref matrix(new BitMatrix(width, height, err_handler)); - if (err_handler.ErrCode()) return -1; + if (err_handler.errCode()) return -1; ArrayRef localLuminances = source.getMatrix(); diff --git a/modules/objdetect/src/zxing/common/simple_adaptive_binarizer.hpp b/modules/objdetect/src/zxing/common/simple_adaptive_binarizer.hpp index 9c53a04244..6e4cda7d46 100644 --- a/modules/objdetect/src/zxing/common/simple_adaptive_binarizer.hpp +++ b/modules/objdetect/src/zxing/common/simple_adaptive_binarizer.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __SIMPLEADAPTIVEBINARIZER_H__ -#define __SIMPLEADAPTIVEBINARIZER_H__ +#ifndef __ZXING_COMMON_SIMPLE_ADAPTIVE_BINARIZER_HPP__ +#define __ZXING_COMMON_SIMPLE_ADAPTIVE_BINARIZER_HPP__ /* * SimpleAdaptiveBinarizer.hpp * zxing @@ -53,4 +63,4 @@ private: } // namespace zxing -#endif // QBAR_AI_QBAR_ZXING_COMMON_SIMPLEADAPTIVEBINARIZER_H_ +#endif // __ZXING_COMMON_SIMPLE_ADAPTIVE_BINARIZER_HPP__ diff --git a/modules/objdetect/src/zxing/common/str.cpp b/modules/objdetect/src/zxing/common/str.cpp index 3e0b2c6080..c809744d1d 100644 --- a/modules/objdetect/src/zxing/common/str.cpp +++ b/modules/objdetect/src/zxing/common/str.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * String.cpp diff --git a/modules/objdetect/src/zxing/common/str.hpp b/modules/objdetect/src/zxing/common/str.hpp index 7c402f4ec6..3b8404bfef 100644 --- a/modules/objdetect/src/zxing/common/str.hpp +++ b/modules/objdetect/src/zxing/common/str.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __STR_H__ -#define __STR_H__ +#ifndef __ZXING_COMMON_STR_HPP__ +#define __ZXING_COMMON_STR_HPP__ @@ -76,4 +86,4 @@ public: } // namespace zxing -#endif // QBAR_AI_QBAR_ZXING_COMMON_STR_H_ +#endif // __ZXING_COMMON_STR_HPP__ diff --git a/modules/objdetect/src/zxing/common/string_utils.cpp b/modules/objdetect/src/zxing/common/string_utils.cpp index a154c6742f..9996bfea5f 100644 --- a/modules/objdetect/src/zxing/common/string_utils.cpp +++ b/modules/objdetect/src/zxing/common/string_utils.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* diff --git a/modules/objdetect/src/zxing/common/string_utils.hpp b/modules/objdetect/src/zxing/common/string_utils.hpp index 05c79d22d6..383ce8c6e9 100644 --- a/modules/objdetect/src/zxing/common/string_utils.hpp +++ b/modules/objdetect/src/zxing/common/string_utils.hpp @@ -1,7 +1,17 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __STRING_UTILS__ -#define __STRING_UTILS__ +#ifndef __ZXING_COMMON_STRING_UTILS_HPP__ +#define __ZXING_COMMON_STRING_UTILS_HPP__ /* * Copyright (C) 2010-2011 ZXing authors @@ -72,4 +82,4 @@ public: static std::string convertString(const char* rawData, int length, const char* fromCharset, const char* toCharset); }; -#endif +#endif // __ZXING_COMMON_STRING_UTILS_HPP__ diff --git a/modules/objdetect/src/zxing/common/unicom_block.cpp b/modules/objdetect/src/zxing/common/unicom_block.cpp index c8c6cdc864..28f897a5b8 100644 --- a/modules/objdetect/src/zxing/common/unicom_block.cpp +++ b/modules/objdetect/src/zxing/common/unicom_block.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + #include "unicom_block.hpp" #include @@ -14,7 +24,7 @@ UnicomBlock::~UnicomBlock() { } -void UnicomBlock::Init() +void UnicomBlock::init() { if (m_bInit) return; m_vcIndex = std::vector(m_iHeight * m_iWidth, 0); @@ -25,30 +35,30 @@ void UnicomBlock::Init() m_bInit = true; } -void UnicomBlock::Reset(Ref poImage) +void UnicomBlock::reset(Ref poImage) { m_poImage = poImage; memset(&m_vcIndex[0], 0, m_vcIndex.size() * sizeof(short)); m_iNowIdx = 0; } -unsigned short UnicomBlock::GetUnicomBlockIndex(int y, int x) +unsigned short UnicomBlock::getUnicomBlockIndex(int y, int x) { if (x < 0 || y < 0 || y >= m_iHeight || x >= m_iWidth) return 0; if (m_vcIndex[y * m_iWidth + x]) return m_vcIndex[y * m_iWidth + x]; - Bfs(y, x); + bfs(y, x); return m_vcIndex[y * m_iWidth + x]; } -int UnicomBlock::GetUnicomBlockSize(int y, int x) +int UnicomBlock::getUnicomBlockSize(int y, int x) { if (y >= m_iHeight || x >= m_iWidth) return 0; if (m_vcIndex[y * m_iWidth + x]) return m_vcCount[y * m_iWidth + x]; - Bfs(y, x); + bfs(y, x); return m_vcCount[y * m_iWidth + x]; } -int UnicomBlock::GetMinPoint(int y, int x, int &iMinY, int &iMinX) +int UnicomBlock::getMinPoint(int y, int x, int &iMinY, int &iMinX) { if (y >= m_iHeight || x >= m_iWidth) return -1; if (m_vcIndex[y * m_iWidth + x]) @@ -57,13 +67,13 @@ int UnicomBlock::GetMinPoint(int y, int x, int &iMinY, int &iMinX) iMinX = m_vcMinPnt[y * m_iWidth + x] & (0xFFFF); return 0; } - Bfs(y, x); + bfs(y, x); iMinY = m_vcMinPnt[y * m_iWidth + x] >> 16; iMinX = m_vcMinPnt[y * m_iWidth + x] & (0xFFFF); return 0; } -int UnicomBlock::GetMaxPoint(int y, int x, int &iMaxY, int &iMaxX) +int UnicomBlock::getMaxPoint(int y, int x, int &iMaxY, int &iMaxX) { if (y >= m_iHeight || x >= m_iWidth) return -1; if (m_vcIndex[y * m_iWidth + x]) @@ -72,13 +82,13 @@ int UnicomBlock::GetMaxPoint(int y, int x, int &iMaxY, int &iMaxX) iMaxX = m_vcMaxPnt[y * m_iWidth + x] & (0xFFFF); return 0; } - Bfs(y, x); + bfs(y, x); iMaxY = m_vcMaxPnt[y * m_iWidth + x] >> 16; iMaxX = m_vcMaxPnt[y * m_iWidth + x] & (0xFFFF); return 0; } -void UnicomBlock::Bfs(int y, int x) +void UnicomBlock::bfs(int y, int x) { if (static_cast(m_iNowIdx) != -1) m_iNowIdx++; if (m_iNowIdx == 0) m_iNowIdx++; diff --git a/modules/objdetect/src/zxing/common/unicom_block.hpp b/modules/objdetect/src/zxing/common/unicom_block.hpp index 30b4b192aa..290b3fc246 100644 --- a/modules/objdetect/src/zxing/common/unicom_block.hpp +++ b/modules/objdetect/src/zxing/common/unicom_block.hpp @@ -1,4 +1,15 @@ -#pragma once +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_COMMON_UNICOM_BLOCK_HPP__ +#define __ZXING_COMMON_UNICOM_BLOCK_HPP__ #include "counted.hpp" #include "bit_matrix.hpp" #include @@ -12,18 +23,18 @@ public: UnicomBlock(int iMaxHeight, int iMaxWidth); ~UnicomBlock(); - void Init(); - void Reset(Ref poImage); + void init(); + void reset(Ref poImage); - unsigned short GetUnicomBlockIndex(int y, int x); + unsigned short getUnicomBlockIndex(int y, int x); - int GetUnicomBlockSize(int y, int x); + int getUnicomBlockSize(int y, int x); - int GetMinPoint(int y, int x, int &iMinY, int &iMinX); - int GetMaxPoint(int y, int x, int &iMaxY, int &iMaxX); + int getMinPoint(int y, int x, int &iMinY, int &iMinX); + int getMaxPoint(int y, int x, int &iMaxY, int &iMaxX); private: - void Bfs(int y, int x); + void bfs(int y, int x); int m_iHeight; int m_iWidth; @@ -40,3 +51,4 @@ private: Ref m_poImage; }; } // namespace zxing +#endif // __ZXING_COMMON_UNICOM_BLOCK_HPP__ diff --git a/modules/objdetect/src/zxing/common/util/bmp.cpp b/modules/objdetect/src/zxing/common/util/bmp.cpp index 09ca7570a9..a10386d30e 100644 --- a/modules/objdetect/src/zxing/common/util/bmp.cpp +++ b/modules/objdetect/src/zxing/common/util/bmp.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // BMP.cpp // QQView @@ -52,7 +62,7 @@ typedef struct tagRGBQUAD { -bool SaveBMP(const char* BMPfname, int nWidth, int nHeight, unsigned char* buffer) +bool saveBMP(const char* BMPfname, int nWidth, int nHeight, unsigned char* buffer) { BITMAPFILEHEADER BMFH; BITMAPINFOHEADER BMIH; @@ -152,7 +162,7 @@ bool SaveBMP(const char* BMPfname, int nWidth, int nHeight, unsigned char* buffe return true; } -bool LoadBMP(const char* BMPfname, int &nWidth, int &nHeight, unsigned char* buffer) +bool loadBMP(const char* BMPfname, int &nWidth, int &nHeight, unsigned char* buffer) { BITMAPINFOHEADER BMIH; BYTE *ptrbmp=NULL; diff --git a/modules/objdetect/src/zxing/common/util/bmp.hpp b/modules/objdetect/src/zxing/common/util/bmp.hpp index 6a0e7eacee..711feaa559 100644 --- a/modules/objdetect/src/zxing/common/util/bmp.hpp +++ b/modules/objdetect/src/zxing/common/util/bmp.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // BMP.hpp // QQView @@ -5,7 +15,11 @@ // Created by Tencent Research on 9/30/11. // Copyright 2011 __MyCompanyName__. All rights reserved. // +#ifndef __ZXING_COMMON_UTIL_BMP_HPP__ +#define __ZXING_COMMON_UTIL_BMP_HPP__ -bool SaveBMP(const char* BMPfname, int nWidth, int nHeight, unsigned char* buffer); +bool saveBMP(const char* BMPfname, int nWidth, int nHeight, unsigned char* buffer); -bool LoadBMP(const char* BMPfname, int &nWidth, int &nHeight, unsigned char* buffer); \ No newline at end of file +bool loadBMP(const char* BMPfname, int &nWidth, int &nHeight, unsigned char* buffer); + +#endif // __ZXING_COMMON_UTIL_BMP_HPP__ \ No newline at end of file diff --git a/modules/objdetect/src/zxing/common/util/ini.cpp b/modules/objdetect/src/zxing/common/util/ini.cpp index e7279d8f6e..8e69f9a8a0 100644 --- a/modules/objdetect/src/zxing/common/util/ini.cpp +++ b/modules/objdetect/src/zxing/common/util/ini.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* inih -- simple .INI file parser inih is released under the New BSD license (see LICENSE.txt). Go to the project diff --git a/modules/objdetect/src/zxing/common/util/ini.hpp b/modules/objdetect/src/zxing/common/util/ini.hpp index 2c6ab89f03..f324475d59 100644 --- a/modules/objdetect/src/zxing/common/util/ini.hpp +++ b/modules/objdetect/src/zxing/common/util/ini.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* inih -- simple .INI file parser inih is released under the New BSD license (see LICENSE.txt). Go to the project @@ -7,8 +17,8 @@ https:// github.com/benhoyt/inih */ -#ifndef __INI_H__ -#define __INI_H__ +#ifndef __ZXING_COMMON_UTIL_INI_HPP__ +#define __ZXING_COMMON_UTIL_INI_HPP__ /* Make this header file easier to include in C++ code */ #ifdef __cplusplus @@ -101,4 +111,4 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, } #endif -#endif /* __INI_H__ */ +#endif // __ZXING_COMMON_UTIL_INI_HPP__ diff --git a/modules/objdetect/src/zxing/common/util/inireader.cpp b/modules/objdetect/src/zxing/common/util/inireader.cpp index d4ec161a1d..2b55a664ee 100644 --- a/modules/objdetect/src/zxing/common/util/inireader.cpp +++ b/modules/objdetect/src/zxing/common/util/inireader.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // Read an INI file into easy-to-access name/value pairs. // inih and INIReader are released under the New BSD license (see LICENSE.txt). @@ -16,24 +26,24 @@ using std::string; INIReader::INIReader(const string& filename) { - _error = ini_parse(filename.c_str(), ValueHandler, this); + _error = ini_parse(filename.c_str(), valueHandler, this); } -int INIReader::ParseError() const +int INIReader::parseError() const { return _error; } -string INIReader::Get(const string& section, const string& name, const string& default_value) const +string INIReader::get(const string& section, const string& name, const string& default_value) const { - string key = MakeKey(section, name); + string key = makeKey(section, name); // Use _values.find() here instead of _values.at() to support pre C++11 compilers return _values.count(key) ? _values.find(key)->second : default_value; } -long INIReader::GetInteger(const string& section, const string& name, long default_value) const +long INIReader::getInteger(const string& section, const string& name, long default_value) const { - string valstr = Get(section, name, ""); + string valstr = get(section, name, ""); const char* value = valstr.c_str(); char* end; // This parses "1234" (decimal) and also "0x4D2" (hex) @@ -41,18 +51,18 @@ long INIReader::GetInteger(const string& section, const string& name, long defau return end > value ? n : default_value; } -double INIReader::GetReal(const string& section, const string& name, double default_value) const +double INIReader::getReal(const string& section, const string& name, double default_value) const { - string valstr = Get(section, name, ""); + string valstr = get(section, name, ""); const char* value = valstr.c_str(); char* end; double n = strtod(value, &end); return end > value ? n : default_value; } -bool INIReader::GetBoolean(const string& section, const string& name, bool default_value) const +bool INIReader::getBoolean(const string& section, const string& name, bool default_value) const { - string valstr = Get(section, name, ""); + string valstr = get(section, name, ""); // Convert to lower case to make string comparisons case-insensitive std::transform(valstr.begin(), valstr.end(), valstr.begin(), ::tolower); if (valstr == "true" || valstr == "yes" || valstr == "on" || valstr == "1") @@ -63,7 +73,7 @@ bool INIReader::GetBoolean(const string& section, const string& name, bool defau return default_value; } -string INIReader::MakeKey(const string& section, const string& name) +string INIReader::makeKey(const string& section, const string& name) { string key = section + "=" + name; // Convert to lower case to make section/name lookups case-insensitive @@ -71,11 +81,11 @@ string INIReader::MakeKey(const string& section, const string& name) return key; } -int INIReader::ValueHandler(void* user, const char* section, const char* name, +int INIReader::valueHandler(void* user, const char* section, const char* name, const char* value) { INIReader* reader = (INIReader*)user; - string key = MakeKey(section, name); + string key = makeKey(section, name); if (reader->_values[key].size() > 0) reader->_values[key] += "\n"; reader->_values[key] += value; diff --git a/modules/objdetect/src/zxing/common/util/inireader.hpp b/modules/objdetect/src/zxing/common/util/inireader.hpp index da65e04070..3c1806a1f4 100644 --- a/modules/objdetect/src/zxing/common/util/inireader.hpp +++ b/modules/objdetect/src/zxing/common/util/inireader.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // Read an INI file into easy-to-access name/value pairs. // inih and INIReader are released under the New BSD license (see LICENSE.txt). @@ -5,8 +15,8 @@ // // https:// github.com/benhoyt/inih -#ifndef __INIREADER_H__ -#define __INIREADER_H__ +#ifndef ____ZXING_COMMON_UTIL_INIREADER_HPP__ +#define ____ZXING_COMMON_UTIL_INIREADER_HPP__ #include #include @@ -22,31 +32,31 @@ public: // Return the result of ini_parse(), i.e., 0 on success, line number of // first error on parse error, or -1 on file open error. - int ParseError() const; + int parseError() const; // Get a string value from INI file, returning default_value if not found. - std::string Get(const std::string& section, const std::string& name, + std::string get(const std::string& section, const std::string& name, const std::string& default_value) const; // Get an integer (long) value from INI file, returning default_value if // not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2"). - long GetInteger(const std::string& section, const std::string& name, long default_value) const; + long getInteger(const std::string& section, const std::string& name, long default_value) const; // Get a real (floating point double) value from INI file, returning // default_value if not found or not a valid floating point value // according to strtod(). - double GetReal(const std::string& section, const std::string& name, double default_value) const; + double getReal(const std::string& section, const std::string& name, double default_value) const; // Get a boolean value from INI file, returning default_value if not found or if // not a valid true/false value. Valid true values are "true", "yes", "on", "1", // and valid false values are "false", "no", "off", "0" (not case sensitive). - bool GetBoolean(const std::string& section, const std::string& name, bool default_value) const; + bool getBoolean(const std::string& section, const std::string& name, bool default_value) const; private: int _error; std::map _values; - static std::string MakeKey(const std::string& section, const std::string& name); - static int ValueHandler(void* user, const char* section, const char* name, + static std::string makeKey(const std::string& section, const std::string& name); + static int valueHandler(void* user, const char* section, const char* name, const char* value); }; @@ -57,4 +67,4 @@ static inline INIReader * GetIniParser() } -#endif // __INIREADER_H__ +#endif // ____ZXING_COMMON_UTIL_INIREADER_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/data_matrix_reader.cpp b/modules/objdetect/src/zxing/datamatrix/data_matrix_reader.cpp index 837be5924e..b7b74203bd 100644 --- a/modules/objdetect/src/zxing/datamatrix/data_matrix_reader.cpp +++ b/modules/objdetect/src/zxing/datamatrix/data_matrix_reader.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * DataMatrixReader.cpp @@ -46,14 +56,14 @@ Ref DataMatrixReader::decode(Ref image, DecodeHints hints) Ref imageBitMatrix=image->getBlackMatrix(err_handler); Ref rst = decodeMore(image, imageBitMatrix, hints, err_handler); - if (err_handler.ErrCode() || rst == NULL) + if (err_handler.errCode() || rst == NULL) { // black white mirro!!! - err_handler.Reset(); + err_handler.reset(); Ref invertedMatrix = image->getInvertedMatrix(err_handler); - if (err_handler.ErrCode() || invertedMatrix == NULL) return Ref(); + if (err_handler.errCode() || invertedMatrix == NULL) return Ref(); Ref rst_ = decodeMore(image, invertedMatrix, hints, err_handler); - if (err_handler.ErrCode() || rst_ == NULL) { + if (err_handler.errCode() || rst_ == NULL) { if (!hints.getTryVideo() && hints.isUseLibdmtx()) { Ref gray_img = image->getLuminanceSource(); dmtx::DmtxDecode dec; @@ -98,11 +108,11 @@ Ref DataMatrixReader::decodeMore(Ref image, Ref (void)hints; Detector detector(imageBitMatrix); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); Ref detectorResult(detector.detect(true, true, err_handler)); - if (err_handler.ErrCode() || detectorResult == NULL) + if (err_handler.errCode() || detectorResult == NULL) { reader_call_path_ += "1"; // detect fail return Ref(); @@ -111,7 +121,7 @@ Ref DataMatrixReader::decodeMore(Ref image, Ref ArrayRef< Ref > points(detectorResult->getPoints()); Ref decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { reader_call_path_ += "2"; // decode fail return Ref(); diff --git a/modules/objdetect/src/zxing/datamatrix/data_matrix_reader.hpp b/modules/objdetect/src/zxing/datamatrix/data_matrix_reader.hpp index 29d53b5c24..9a987851d9 100644 --- a/modules/objdetect/src/zxing/datamatrix/data_matrix_reader.hpp +++ b/modules/objdetect/src/zxing/datamatrix/data_matrix_reader.hpp @@ -1,5 +1,15 @@ -#ifndef __DATA_MATRIX_READER_H__ -#define __DATA_MATRIX_READER_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_DATAMATRIX_DATA_MATRIX_READER_HPP__ +#define __ZXING_DATAMATRIX_DATA_MATRIX_READER_HPP__ /* * DataMatrixReader.hpp @@ -44,4 +54,4 @@ public: } // namespace datamatrix } // namespace zxing -#endif // __DATA_MATRIX_READER_H__ +#endif // __ZXING_DATAMATRIX_DATA_MATRIX_READER_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/decoder/bit_matrix_parser.cpp b/modules/objdetect/src/zxing/datamatrix/decoder/bit_matrix_parser.cpp index 4041228638..16396bd247 100644 --- a/modules/objdetect/src/zxing/datamatrix/decoder/bit_matrix_parser.cpp +++ b/modules/objdetect/src/zxing/datamatrix/decoder/bit_matrix_parser.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * BitMatrixParser.cpp * zxing @@ -41,13 +51,13 @@ readBitMatrix_(NULL) { } parsedVersion_ = readVersion(bitMatrix, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; bitMatrix_ = extractDataRegion(bitMatrix, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; readBitMatrix_ = new BitMatrix(bitMatrix_->getWidth(), bitMatrix_->getHeight() , err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } Version * BitMatrixParser::readVersion(Ref bitMatrix, ErrorHandler & err_handler) { @@ -61,7 +71,7 @@ Version * BitMatrixParser::readVersion(Ref bitMatrix, ErrorHandler & Version * version = parsedVersion_->getVersionForDimensions(numRows, numColumns, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { err_handler = ErrorHandler("Couldn't decode versio"); return NULL; @@ -415,7 +425,7 @@ Ref BitMatrixParser::extractDataRegion(Ref bitMatrix, Erro int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns; Ref bitMatrixWithoutAlignment(new BitMatrix(sizeDataRegionColumn, sizeDataRegionRow, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) { int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows; diff --git a/modules/objdetect/src/zxing/datamatrix/decoder/bit_matrix_parser.hpp b/modules/objdetect/src/zxing/datamatrix/decoder/bit_matrix_parser.hpp index 5cc60b9afa..d3a47368a9 100644 --- a/modules/objdetect/src/zxing/datamatrix/decoder/bit_matrix_parser.hpp +++ b/modules/objdetect/src/zxing/datamatrix/decoder/bit_matrix_parser.hpp @@ -1,5 +1,15 @@ -#ifndef __BIT_MATRIX_PARSER_DM_H__ -#define __BIT_MATRIX_PARSER_DM_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_DATAMATRIX_DECODER_BIT_MATRIX_PARSER_HPP__ +#define __ZXING_DATAMATRIX_DECODER_BIT_MATRIX_PARSER_HPP__ /* * BitMatrixParser.hpp @@ -58,4 +68,4 @@ private: } // namespace datamatrix } // namespace zxing -#endif // __BIT_MATRIX_PARSER_DM_H__ +#endif // __ZXING_DATAMATRIX_DECODER_BIT_MATRIX_PARSER_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/decoder/data_block.cpp b/modules/objdetect/src/zxing/datamatrix/decoder/data_block.cpp index 71b1cf156c..47e9d9db85 100644 --- a/modules/objdetect/src/zxing/datamatrix/decoder/data_block.cpp +++ b/modules/objdetect/src/zxing/datamatrix/decoder/data_block.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * DataBlock.cpp * zxing diff --git a/modules/objdetect/src/zxing/datamatrix/decoder/data_block.hpp b/modules/objdetect/src/zxing/datamatrix/decoder/data_block.hpp index c35ac8ae95..1f82196c22 100644 --- a/modules/objdetect/src/zxing/datamatrix/decoder/data_block.hpp +++ b/modules/objdetect/src/zxing/datamatrix/decoder/data_block.hpp @@ -1,5 +1,15 @@ -#ifndef __DATA_BLOCK_DM_H__ -#define __DATA_BLOCK_DM_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_DATAMATRIX_DECODER_DATA_BLOCK_HPP__ +#define __ZXING_DATAMATRIX_DECODER_DATA_BLOCK_HPP__ /* * DataBlock.hpp @@ -48,4 +58,4 @@ public: } // namespace datamatrix } // namespace zxing -#endif // __DATA_BLOCK_DM_H__ +#endif // __ZXING_DATAMATRIX_DECODER_DATA_BLOCK_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/decoder/decoded_bit_stream_parser.cpp b/modules/objdetect/src/zxing/datamatrix/decoder/decoded_bit_stream_parser.cpp index 7e069b8d6d..335dd273fe 100644 --- a/modules/objdetect/src/zxing/datamatrix/decoder/decoded_bit_stream_parser.cpp +++ b/modules/objdetect/src/zxing/datamatrix/decoder/decoded_bit_stream_parser.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * DecodedBitStreamParser.cpp @@ -59,30 +69,30 @@ Ref DecodedBitStreamParser::decode(ArrayRef bytes, ErrorHan if (mode == ASCII_ENCODE) { mode = decodeAsciiSegment(bits, result, resultTrailer, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } else { switch (mode) { case C40_ENCODE: decodeC40Segment(bits, result, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); break; case TEXT_ENCODE: decodeTextSegment(bits, result, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); break; case ANSIX12_ENCODE: decodeAnsiX12Segment(bits, result, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); break; case EDIFACT_ENCODE: decodeEdifactSegment(bits, result, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); break; case BASE256_ENCODE: decodeBase256Segment(bits, result, byteSegments, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); break; default: err_handler = ErrorHandler("Unsupported mode indicator"); @@ -106,7 +116,7 @@ int DecodedBitStreamParser::decodeAsciiSegment(Ref bits, std::ostring bool upperShift = false; do { int oneByte = bits->readBits(8, err_handler); - if (err_handler.ErrCode()) return 0; + if (err_handler.errCode()) return 0; if (oneByte == 0) { err_handler = ErrorHandler("Not enough bits to decode"); @@ -210,14 +220,14 @@ void DecodedBitStreamParser::decodeC40Segment(Ref bits, std::ostrings return; } int firstByte = bits->readBits(8, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; if (firstByte == 254) { // Unlatch codeword return; } parseTwoBytes(firstByte, bits->readBits(8, err_handler), cValues); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; for (int i = 0; i < 3; i++) { int cValue = cValues[i]; @@ -315,7 +325,7 @@ void DecodedBitStreamParser::decodeTextSegment(Ref bits, std::ostring return; } int firstByte = bits->readBits(8, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; if (firstByte == 254) { // Unlatch codeword return; @@ -417,14 +427,14 @@ void DecodedBitStreamParser::decodeAnsiX12Segment(Ref bits, std::ostr return; } int firstByte = bits->readBits(8, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; if (firstByte == 254) { // Unlatch codeword return; } parseTwoBytes(firstByte, bits->readBits(8, err_handler), cValues); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; for (int i = 0; i < 3; i++) { @@ -482,7 +492,7 @@ void DecodedBitStreamParser::decodeEdifactSegment(Ref bits, std::ostr for (int i = 0; i < 4; i++) { int edifactValue = bits->readBits(6, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; // Check for the unlatch character if (edifactValue == 0x1f) @@ -492,7 +502,7 @@ void DecodedBitStreamParser::decodeEdifactSegment(Ref bits, std::ostr if (bitsLeft != 8) { bits->readBits(bitsLeft, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } return; } @@ -510,7 +520,7 @@ void DecodedBitStreamParser::decodeBase256Segment(Ref bits, std::ostr // Figure out how long the Base 256 Segment is. int codewordPosition = 1 + bits->getByteOffset(); // position is 1-indexed int d1 = unrandomize255State(bits->readBits(8, err_handler), codewordPosition++); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; int count; if (d1 == 0) { // Read the remainder of the symbol @@ -523,7 +533,7 @@ void DecodedBitStreamParser::decodeBase256Segment(Ref bits, std::ostr else { count = 250 * (d1 - 249) + unrandomize255State(bits->readBits(8, err_handler), codewordPosition++); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } // We're seeing NegativeArraySizeException errors from users. @@ -542,7 +552,7 @@ void DecodedBitStreamParser::decodeBase256Segment(Ref bits, std::ostr return; } char byte = unrandomize255State(bits->readBits(8, err_handler), codewordPosition++); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; byteSegments.push_back(byte); result << static_cast(byte); } diff --git a/modules/objdetect/src/zxing/datamatrix/decoder/decoded_bit_stream_parser.hpp b/modules/objdetect/src/zxing/datamatrix/decoder/decoded_bit_stream_parser.hpp index f19b4074d7..f132cb9035 100644 --- a/modules/objdetect/src/zxing/datamatrix/decoder/decoded_bit_stream_parser.hpp +++ b/modules/objdetect/src/zxing/datamatrix/decoder/decoded_bit_stream_parser.hpp @@ -1,5 +1,15 @@ -#ifndef __DECODED_BIT_STREAM_PARSER_DM_H__ -#define __DECODED_BIT_STREAM_PARSER_DM_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_DATAMATRIX_DECODER_DECODED_BIT_STREAM_PARSER_HPP__ +#define __ZXING_DATAMATRIX_DECODER_DECODED_BIT_STREAM_PARSER_HPP__ /* * DecodedBitStreamParser.hpp @@ -103,4 +113,4 @@ public: } } -#endif // QBAR_AI_QBAR_ZXING_QRCODE_DECODER_DECODEDBITSTREAMPARSER_H_ +#endif // __ZXING_DATAMATRIX_DECODER_DECODED_BIT_STREAM_PARSER_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/decoder/decoder.cpp b/modules/objdetect/src/zxing/datamatrix/decoder/decoder.cpp index c6f4baa604..8003cbb124 100644 --- a/modules/objdetect/src/zxing/datamatrix/decoder/decoder.cpp +++ b/modules/objdetect/src/zxing/datamatrix/decoder/decoder.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * Decoder.cpp * zxing @@ -48,7 +58,7 @@ void Decoder::correctErrors(ArrayRef codewordBytes, int numDataCodewords, int numECCodewords = numCodewords - numDataCodewords; rsDecoder_.decode(codewordInts, numECCodewords, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; // Copy back into array of bytes -- only need to worry about the bytes that were data // We don't care about errors in the error-correction codewords @@ -61,18 +71,18 @@ Ref Decoder::decode(Ref bits, ErrorHandler & err_handl // Construct a parser and read version, error-correction level BitMatrixParser parser(bits, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); Version *version = parser.readVersion(bits, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); // Read codewords ArrayRef codewords(parser.readCodewords(err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); // Separate into data blocks std::vector > dataBlocks = DataBlock::getDataBlocks_new(codewords, version, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); int dataBlocksCount = dataBlocks.size(); @@ -97,7 +107,7 @@ Ref Decoder::decode(Ref bits, ErrorHandler & err_handl // Decode the contents of that stream of bytes DecodedBitStreamParser decodedBSParser; Ref decoderResult = decodedBSParser.decode(resultBytes, err_handler); - if (err_handler.ErrCode()) return Ref (); + if (err_handler.errCode()) return Ref (); return Ref (decoderResult); } diff --git a/modules/objdetect/src/zxing/datamatrix/decoder/decoder.hpp b/modules/objdetect/src/zxing/datamatrix/decoder/decoder.hpp index b3cc1a8bf6..dbe854d2a0 100644 --- a/modules/objdetect/src/zxing/datamatrix/decoder/decoder.hpp +++ b/modules/objdetect/src/zxing/datamatrix/decoder/decoder.hpp @@ -1,5 +1,15 @@ -#ifndef __DECODER_DM_H__ -#define __DECODER_DM_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_DATAMATRIX_DECODER_DECODER_HPP__ +#define __ZXING_DATAMATRIX_DECODER_DECODER_HPP__ /* * Decoder.hpp @@ -46,4 +56,4 @@ public: } // namespace datamatrix } // namespace zxing -#endif // __DECODER_DM_H__ +#endif // __ZXING_DATAMATRIX_DECODER_DECODER_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/detector/corner_point.cpp b/modules/objdetect/src/zxing/datamatrix/detector/corner_point.cpp index 3ba0c29027..ba8c8dbd68 100644 --- a/modules/objdetect/src/zxing/datamatrix/detector/corner_point.cpp +++ b/modules/objdetect/src/zxing/datamatrix/detector/corner_point.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * CornerPoint.cpp * zxing diff --git a/modules/objdetect/src/zxing/datamatrix/detector/corner_point.hpp b/modules/objdetect/src/zxing/datamatrix/detector/corner_point.hpp index 5f963b2507..2c30bf341d 100644 --- a/modules/objdetect/src/zxing/datamatrix/detector/corner_point.hpp +++ b/modules/objdetect/src/zxing/datamatrix/detector/corner_point.hpp @@ -1,5 +1,15 @@ -#ifndef __CORNER_FINDER_H__ -#define __CORNER_FINDER_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_DATAMATRIX_DETECTOR_CORNER_POINT_HPP__ +#define __ZXING_DATAMATRIX_DETECTOR_CORNER_POINT_HPP__ /* * CornerPoint.hpp @@ -40,4 +50,4 @@ public: } // namespace datamatrix } // namespace zxing -#endif // __CORNER_FINDER_H__ +#endif // __ZXING_DATAMATRIX_DETECTOR_CORNER_POINT_HPP__ \ No newline at end of file diff --git a/modules/objdetect/src/zxing/datamatrix/detector/detector.cpp b/modules/objdetect/src/zxing/datamatrix/detector/detector.cpp index cba472cde2..c8f67c01ee 100644 --- a/modules/objdetect/src/zxing/datamatrix/detector/detector.cpp +++ b/modules/objdetect/src/zxing/datamatrix/detector/detector.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Detector.cpp @@ -182,9 +192,9 @@ std::vector> Detector::shiftToModuleCenter(std::vector Detector::detectV1(ErrorHandler & err_handler) { Ref rectangleDetector_(new WhiteRectangleDetector(image_, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); std::vector > ResultPoints = rectangleDetector_->detectNew(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); Ref pointA = ResultPoints[0]; Ref pointB = ResultPoints[1]; Ref pointC = ResultPoints[2]; @@ -343,7 +353,7 @@ Ref Detector::detectV1(ErrorHandler & err_handler) { transform = createTransform(topLeft, correctedTopRight, bottomLeft, bottomRight, dimensionTop, dimensionRight); bits = sampleGrid(image_, dimensionTop, dimensionRight, transform, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } else { @@ -369,7 +379,7 @@ Ref Detector::detectV1(ErrorHandler & err_handler) { transform = createTransform(topLeft, correctedTopRight, bottomLeft, bottomRight, dimensionCorrected, dimensionCorrected); bits = sampleGrid(image_, dimensionCorrected, dimensionCorrected, transform, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } ArrayRef< Ref > points(new Array< Ref >(4)); @@ -680,7 +690,7 @@ Ref Detector::sampleGrid(Ref image, int dimensionX, int di GridSampler &sampler = GridSampler::getInstance(); Ref bits = sampler.sampleGrid(image, dimensionX, dimensionY, transform, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return bits; } @@ -1553,7 +1563,7 @@ Ref Detector::detectV3(ErrorHandler &err_handler) transform = createTransformV3(topLeft, topRight, bottomLeft, bottomRight, dimT, dimR); bits = sampleGrid(image_, dimT, dimR, transform, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); Ref detectorResult(new DetectorResult(bits, final_points)); return detectorResult; } @@ -1568,9 +1578,9 @@ Ref Detector::detectV3(ErrorHandler &err_handler) Ref Detector::detectV2(ErrorHandler &err_handler) { Ref rectangleDetector_(new WhiteRectangleDetector(image_, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); std::vector > ResultPoints = rectangleDetector_->detectNew(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); // 0 2 // 1 3 @@ -1692,7 +1702,7 @@ Ref Detector::detectV2(ErrorHandler &err_handler) transform = createTransform(topLeft, topRight, bottomLeft, bottomRight, dimensionTop, dimensionRight); bits = sampleGrid(image_, dimensionTop, dimensionRight, transform, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); ArrayRef< Ref > final_points(new Array< Ref >(4)); final_points[0].reset(topLeft); @@ -1718,10 +1728,10 @@ Ref Detector::detect(bool use_v2, bool use_v3, ErrorHandler &err err_handler = ErrorHandler("detectV3 error!"); } } - if (err_handler.ErrCode() || result == NULL) + if (err_handler.errCode() || result == NULL) { if (use_v2) { - err_handler.Reset(); + err_handler.reset(); result = detectV2(err_handler); } } diff --git a/modules/objdetect/src/zxing/datamatrix/detector/detector.hpp b/modules/objdetect/src/zxing/datamatrix/detector/detector.hpp index 4fb6391221..d8ba40d60f 100644 --- a/modules/objdetect/src/zxing/datamatrix/detector/detector.hpp +++ b/modules/objdetect/src/zxing/datamatrix/detector/detector.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __DETECTOR_H__ -#define __DETECTOR_H__ +#ifndef __ZXING_DATAMATRIX_DETECTOR_DETECTOR_HPP__ +#define __ZXING_DATAMATRIX_DETECTOR_DETECTOR_HPP__ /* * Detector.hpp @@ -104,4 +114,4 @@ private: } // namespace datamatrix } // namespace zxing -#endif // QBAR_AI_QBAR_ZXING_DATAMATRIX_DETECTOR_DETECTOR_H_ +#endif // __ZXING_DATAMATRIX_DETECTOR_DETECTOR_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/detector/detector_exception.cpp b/modules/objdetect/src/zxing/datamatrix/detector/detector_exception.cpp index 0ceb1eb76b..9f14dd977f 100644 --- a/modules/objdetect/src/zxing/datamatrix/detector/detector_exception.cpp +++ b/modules/objdetect/src/zxing/datamatrix/detector/detector_exception.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * DetectorException.cpp * diff --git a/modules/objdetect/src/zxing/datamatrix/detector/detector_exception.hpp b/modules/objdetect/src/zxing/datamatrix/detector/detector_exception.hpp index a2cfcc0105..23f8f0f6b0 100644 --- a/modules/objdetect/src/zxing/datamatrix/detector/detector_exception.hpp +++ b/modules/objdetect/src/zxing/datamatrix/detector/detector_exception.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * DetectorException.hpp * @@ -5,8 +15,8 @@ * Author: luiz */ -#ifndef DETECTOREXCEPTION_H_ -#define DETECTOREXCEPTION_H_ +#ifndef __ZXING_DATAMATRIX_DETECTOR_DETECTOR_EXCEPTION_HPP__ +#define __ZXING_DATAMATRIX_DETECTOR_DETECTOR_EXCEPTION_HPP__ #include "../../exception.hpp" @@ -20,4 +30,4 @@ public: }; } // namespace datamatrix } // namespace zxing -#endif /* DETECTOREXCEPTION_H_ */ +#endif // __ZXING_DATAMATRIX_DETECTOR_DETECTOR_EXCEPTION_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/common.hpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/common.hpp index 651b9266aa..27ca01fdfb 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/common.hpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/common.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // common.hpp // test_dm @@ -5,8 +15,8 @@ // Created by wechatcv on 2022/5/7. // -#ifndef common_h -#define common_h +#ifndef __ZXING_DATAMATRIX_LIBDMTX_COMMON_HPP__ +#define __ZXING_DATAMATRIX_LIBDMTX_COMMON_HPP__ namespace dmtx { #define NN 255 @@ -411,4 +421,4 @@ typedef enum { } DmtxScheme; } -#endif /* common_h */ +#endif // __ZXING_DATAMATRIX_LIBDMTX_COMMON_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxbytelist.cpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxbytelist.cpp index fb7c05fc46..dc0f59646a 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxbytelist.cpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxbytelist.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxbytelist.cpp // test_dm diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxbytelist.hpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxbytelist.hpp index edd000317c..4cb667365c 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxbytelist.hpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxbytelist.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxbytelist.hpp // test_dm @@ -5,8 +15,8 @@ // Created by wechatcv on 2022/5/7. // -#ifndef dmtxbytelist_hpp -#define dmtxbytelist_hpp +#ifndef __ZXING_DATAMATRIX_LIBDMTX_DMTXBYTELIST_HPP__ +#define __ZXING_DATAMATRIX_LIBDMTX_DMTXBYTELIST_HPP__ #include #include "common.hpp" @@ -24,4 +34,4 @@ DmtxByte dmtxByteListPop(DmtxByteList *list, unsigned int *passFail); } // namespace dmtx -#endif /* dmtxbytelist_hpp */ +#endif // __ZXING_DATAMATRIX_LIBDMTX_DMTXBYTELIST_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxdecode.cpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxdecode.cpp index ebfe814873..f7bbca5b8d 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxdecode.cpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxdecode.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxdecode.cpp // test_dm @@ -48,7 +58,7 @@ int DmtxDecode::dmtxDecodeCreate(unsigned char *pxl, int width, int height) return -1; } - if (InitScanGrid() < 0) return -1; + if (initScanGrid() < 0) return -1; return 0; } @@ -123,7 +133,7 @@ int DmtxDecode::dmtxRegionFindNext() /* Continue until we find a region or run out of chances */ int count = 0; for (;;) { - locStatus = PopGridLocation(&loc); + locStatus = popGridLocation(&loc); if (locStatus == DmtxRangeEnd) break; count += 1; @@ -140,12 +150,12 @@ int DmtxDecode::dmtxRegionFindNext() /// -int DmtxDecode::PopGridLocation( DmtxPixelLoc *locPtr) +int DmtxDecode::popGridLocation( DmtxPixelLoc *locPtr) { int locStatus; do { - locStatus = GetGridCoordinates(locPtr); + locStatus = getGridCoordinates(locPtr); /* Always leave grid pointing at next available location */ grid.pixelCount++; @@ -155,7 +165,7 @@ int DmtxDecode::PopGridLocation( DmtxPixelLoc *locPtr) return locStatus; } -int DmtxDecode::GetGridCoordinates(DmtxPixelLoc *locPtr) +int DmtxDecode::getGridCoordinates(DmtxPixelLoc *locPtr) { int count, half, quarter; DmtxPixelLoc loc; @@ -259,39 +269,39 @@ int DmtxDecode::dmtxRegionScanPixel(int x, int y) return -1; /* Test for presence of any reasonable edge at this location */ - flowBegin = MatrixRegionSeekEdge(loc); + flowBegin = matrixRegionSeekEdge(loc); if (flowBegin.mag < static_cast(this->edgeThresh * 7.65 + 0.5)) return -1; memset(®ion, 0x00, sizeof(DmtxRegion)); /* Determine barcode orientation */ - if (MatrixRegionOrientation(flowBegin) == DmtxFail) + if (matrixRegionOrientation(flowBegin) == DmtxFail) return -1; if (dmtxRegionUpdateXfrms() == DmtxFail) return -1; /* Define top edge */ - if (MatrixRegionAlignCalibEdge(DmtxEdgeTop) == DmtxFail) + if (matrixRegionAlignCalibEdge(DmtxEdgeTop) == DmtxFail) return -1; if (dmtxRegionUpdateXfrms() == DmtxFail) return -1; /* Define right edge */ - if (MatrixRegionAlignCalibEdge(DmtxEdgeRight) == DmtxFail) + if (matrixRegionAlignCalibEdge(DmtxEdgeRight) == DmtxFail) return -1; if (dmtxRegionUpdateXfrms() == DmtxFail) return -1; /* Calculate the best fitting symbol size */ - if (MatrixRegionFindSize() == DmtxFail) + if (matrixRegionFindSize() == DmtxFail) return -1; /* Found a valid matrix region */ return 0; } -DmtxPointFlow DmtxDecode::MatrixRegionSeekEdge(DmtxPixelLoc loc) +DmtxPointFlow DmtxDecode::matrixRegionSeekEdge(DmtxPixelLoc loc) { DmtxPointFlow flow, flowPlane; DmtxPointFlow flowPos, flowPosBack; @@ -305,11 +315,11 @@ DmtxPointFlow DmtxDecode::MatrixRegionSeekEdge(DmtxPixelLoc loc) flow = flowPlane; - flowPos = FindStrongestNeighbor(flow, +1); - flowNeg = FindStrongestNeighbor(flow, -1); + flowPos = findStrongestNeighbor(flow, +1); + flowNeg = findStrongestNeighbor(flow, -1); if (flowPos.mag != 0 && flowNeg.mag != 0) { - flowPosBack = FindStrongestNeighbor(flowPos, -1); - flowNegBack = FindStrongestNeighbor(flowNeg, +1); + flowPosBack = findStrongestNeighbor(flowPos, -1); + flowNegBack = findStrongestNeighbor(flowNeg, +1); if (flowPos.arrive == (flowPosBack.arrive + 4) % 8 && flowNeg.arrive == (flowNegBack.arrive + 4) % 8) { flow.arrive = dmtxNeighborNone; @@ -382,7 +392,7 @@ DmtxPointFlow DmtxDecode::GetPointFlow(DmtxPixelLoc loc, int arrive) return flow; } -unsigned int DmtxDecode:: MatrixRegionFindSize() +unsigned int DmtxDecode:: matrixRegionFindSize() { int row, col; int sizeIdxBeg, sizeIdxEnd; @@ -429,7 +439,7 @@ unsigned int DmtxDecode:: MatrixRegionFindSize() /* Sum module colors along horizontal calibration bar */ row = symbolRows - 1; for (col = 0; col < symbolCols; col++) { - color = ReadModuleColor(row, col, sizeIdx); + color = readModuleColor(row, col, sizeIdx); if (color == -1) return DmtxFail; if ((col & 0x01) != 0x00) @@ -441,7 +451,7 @@ unsigned int DmtxDecode:: MatrixRegionFindSize() /* Sum module colors along vertical calibration bar */ col = symbolCols - 1; for (row = 0; row < symbolRows; row++) { - color = ReadModuleColor(row, col, sizeIdx); + color = readModuleColor(row, col, sizeIdx); if (color == -1) return DmtxFail; if ((row & 0x01) != 0x00) @@ -480,48 +490,48 @@ unsigned int DmtxDecode:: MatrixRegionFindSize() region.mappingCols = dmtxGetSymbolAttribute(DmtxSymAttribMappingMatrixCols, region.sizeIdx); /* Tally jumps on horizontal calibration bar to verify sizeIdx */ - jumpCount = CountJumpTally(0, region.symbolRows - 1, DmtxDirRight); + jumpCount = countJumpTally(0, region.symbolRows - 1, DmtxDirRight); errors = abs(1 + jumpCount - region.symbolCols); if (jumpCount < 0 || errors > 2) return DmtxFail; /* Tally jumps on vertical calibration bar to verify sizeIdx */ - jumpCount = CountJumpTally(region.symbolCols - 1, 0, DmtxDirUp); + jumpCount = countJumpTally(region.symbolCols - 1, 0, DmtxDirUp); errors = abs(1 + jumpCount - region.symbolRows); if (jumpCount < 0 || errors > 2) return DmtxFail; /* Tally jumps on horizontal finder bar to verify sizeIdx */ - errors = CountJumpTally(0, 0, DmtxDirRight); + errors = countJumpTally(0, 0, DmtxDirRight); if (jumpCount < 0 || errors > 2) return DmtxFail; /* Tally jumps on vertical finder bar to verify sizeIdx */ - errors = CountJumpTally(0, 0, DmtxDirUp); + errors = countJumpTally(0, 0, DmtxDirUp); if (errors < 0 || errors > 2) return DmtxFail; /* Tally jumps on surrounding whitespace, else fail */ - errors = CountJumpTally(0, -1, DmtxDirRight); + errors = countJumpTally(0, -1, DmtxDirRight); if (errors < 0 || errors > 2) return DmtxFail; - errors = CountJumpTally(-1, 0, DmtxDirUp); + errors = countJumpTally(-1, 0, DmtxDirUp); if (errors < 0 || errors > 2) return DmtxFail; - errors = CountJumpTally(0, region.symbolRows, DmtxDirRight); + errors = countJumpTally(0, region.symbolRows, DmtxDirRight); if (errors < 0 || errors > 2) return DmtxFail; - errors = CountJumpTally(region.symbolCols, 0, DmtxDirUp); + errors = countJumpTally(region.symbolCols, 0, DmtxDirUp); if (errors < 0 || errors > 2) return DmtxFail; return DmtxPass; } -int DmtxDecode::CountJumpTally(int xStart, int yStart, DmtxDirection dir) +int DmtxDecode::countJumpTally(int xStart, int yStart, DmtxDirection dir) { int x, xInc = 0; int y, yInc = 0; @@ -548,7 +558,7 @@ int DmtxDecode::CountJumpTally(int xStart, int yStart, DmtxDirection dir) darkOnLight = static_cast(region.offColor > region.onColor); jumpThreshold = abs(static_cast(0.4 * (region.onColor - region.offColor) + 0.5)); - color = ReadModuleColor(yStart, xStart, region.sizeIdx); + color = readModuleColor(yStart, xStart, region.sizeIdx); if (color == -1) return -1; tModule = (darkOnLight) ? region.offColor - color : color - region.offColor; @@ -559,7 +569,7 @@ int DmtxDecode::CountJumpTally(int xStart, int yStart, DmtxDirection dir) x += xInc, y += yInc) { tPrev = tModule; - color = ReadModuleColor(y, x, region.sizeIdx); + color = readModuleColor(y, x, region.sizeIdx); if (color == -1) return -1; tModule = (darkOnLight) ? region.offColor - color : color - region.offColor; @@ -584,7 +594,7 @@ int DmtxDecode::CountJumpTally(int xStart, int yStart, DmtxDirection dir) return jumpCount; } -DmtxPointFlow DmtxDecode::FindStrongestNeighbor(DmtxPointFlow center, int sign) +DmtxPointFlow DmtxDecode::findStrongestNeighbor(DmtxPointFlow center, int sign) { int strongIdx; int attemptDiff; @@ -630,7 +640,7 @@ DmtxPointFlow DmtxDecode::FindStrongestNeighbor(DmtxPointFlow center, int sign) return (strongIdx == DmtxUndefined) ? dmtxBlankEdge : flow[strongIdx]; } -unsigned int DmtxDecode::MatrixRegionOrientation(DmtxPointFlow begin) +unsigned int DmtxDecode::matrixRegionOrientation(DmtxPointFlow begin) { int cross; int minArea; @@ -665,10 +675,10 @@ unsigned int DmtxDecode::MatrixRegionOrientation(DmtxPointFlow begin) } /* Follow to end in both directions */ - err = TrailBlazeContinuous(begin, maxDiagonal); + err = trailBlazeContinuous(begin, maxDiagonal); if (err == DmtxFail || region.stepsTotal < 40) { - TrailClear(0x40); + trailClear(0x40); return DmtxFail; } @@ -681,36 +691,36 @@ unsigned int DmtxDecode::MatrixRegionOrientation(DmtxPointFlow begin) minArea = (2 * this->edgeMin * this->edgeMin); if ((region.boundMax.X - region.boundMin.X) * (region.boundMax.Y - region.boundMin.Y) < minArea) { - TrailClear(0x40); + trailClear(0x40); return DmtxFail; } } unsigned int passFail; - line1x = FindBestSolidLine(0, 0, +1, DmtxUndefined, &passFail); + line1x = findBestSolidLine(0, 0, +1, DmtxUndefined, &passFail); if (passFail == DmtxFail) return DmtxFail; if (line1x.mag < 5) { - TrailClear(0x40); + trailClear(0x40); return DmtxFail; } - err = FindTravelLimits(&line1x); + err = findTravelLimits(&line1x); if (line1x.distSq < 100 || line1x.devn * 10 >= sqrt(static_cast(line1x.distSq))) { - TrailClear(0x40); + trailClear(0x40); return DmtxFail; } if (line1x.stepPos < line1x.stepNeg) return DmtxFail; - fTmp = FollowSeek(line1x.stepPos + 5, &passFail); + fTmp = followSeek(line1x.stepPos + 5, &passFail); if (passFail == DmtxFail) return DmtxFail; - line2p = FindBestSolidLine(fTmp.step, line1x.stepNeg, +1, line1x.angle, &passFail); + line2p = findBestSolidLine(fTmp.step, line1x.stepNeg, +1, line1x.angle, &passFail); if (passFail == DmtxFail) return DmtxFail; - fTmp = FollowSeek(line1x.stepNeg - 5, &passFail); + fTmp = followSeek(line1x.stepNeg - 5, &passFail); if (passFail == DmtxFail) return DmtxFail; - line2n = FindBestSolidLine(fTmp.step, line1x.stepPos, -1, line1x.angle, &passFail); + line2n = findBestSolidLine(fTmp.step, line1x.stepPos, -1, line1x.angle, &passFail); if (passFail == DmtxFail) return DmtxFail; if (fmax(line2p.mag, line2n.mag) < 5) return DmtxFail; @@ -718,7 +728,7 @@ unsigned int DmtxDecode::MatrixRegionOrientation(DmtxPointFlow begin) if (line2p.mag > line2n.mag) { line2x = line2p; - err = FindTravelLimits(&line2x); + err = findTravelLimits(&line2x); if (line2x.distSq < 100 || line2x.devn * 10 >= sqrt(static_cast(line2x.distSq))) return DmtxFail; @@ -758,7 +768,7 @@ unsigned int DmtxDecode::MatrixRegionOrientation(DmtxPointFlow begin) else { line2x = line2n; - err = FindTravelLimits(&line2x); + err = findTravelLimits(&line2x); if (line2x.distSq < 100 || line2x.devn / sqrt(static_cast(line2x.distSq)) >= 0.1) return DmtxFail; @@ -801,7 +811,7 @@ unsigned int DmtxDecode::MatrixRegionOrientation(DmtxPointFlow begin) return DmtxPass; } -DmtxFollow DmtxDecode::FollowSeek(int seek, unsigned int* passFail) +DmtxFollow DmtxDecode::followSeek(int seek, unsigned int* passFail) { int i; int sign; @@ -824,7 +834,7 @@ DmtxFollow DmtxDecode::FollowSeek(int seek, unsigned int* passFail) sign = (seek > 0) ? +1 : -1; for (i = 0; i != seek; i += sign) { - follow = FollowStep(follow, sign, passFail); + follow = followStep(follow, sign, passFail); if (passFail == DmtxFail) { // *passFail = DmtxFail; @@ -845,7 +855,7 @@ DmtxFollow DmtxDecode::FollowSeek(int seek, unsigned int* passFail) return follow; } -DmtxFollow DmtxDecode::FollowStep(DmtxFollow followBeg, int sign, unsigned int *passFail) +DmtxFollow DmtxDecode::followStep(DmtxFollow followBeg, int sign, unsigned int *passFail) { int patternIdx; int stepMod; @@ -900,7 +910,7 @@ DmtxFollow DmtxDecode::FollowStep(DmtxFollow followBeg, int sign, unsigned int * } -unsigned int DmtxDecode::TrailBlazeContinuous(DmtxPointFlow flowBegin, int maxDiagonal) +unsigned int DmtxDecode::trailBlazeContinuous(DmtxPointFlow flowBegin, int maxDiagonal) { int posAssigns, negAssigns, clears; int sign; @@ -930,7 +940,7 @@ unsigned int DmtxDecode::TrailBlazeContinuous(DmtxPointFlow flowBegin, int maxDi break; /* Find the strongest eligible neighbor */ - flowNext = FindStrongestNeighbor(flow, sign); + flowNext = findStrongestNeighbor(flow, sign); if (flowNext.mag < 50) break; @@ -983,7 +993,7 @@ unsigned int DmtxDecode::TrailBlazeContinuous(DmtxPointFlow flowBegin, int maxDi region.boundMax = boundMax; /* Clear "visited" bit from trail */ - clears = TrailClear(0x80); + clears = trailClear(0x80); if (clears < 0) return DmtxFail; if (posAssigns + negAssigns != clears - 1) return DmtxFail; @@ -995,7 +1005,7 @@ unsigned int DmtxDecode::TrailBlazeContinuous(DmtxPointFlow flowBegin, int maxDi return DmtxPass; } -int DmtxDecode::TrailClear(int clearMask) +int DmtxDecode::trailClear(int clearMask) { int clears; DmtxFollow follow; @@ -1005,12 +1015,12 @@ int DmtxDecode::TrailClear(int clearMask) /* Clear "visited" bit from trail */ clears = 0; - follow = FollowSeek(0, &passFail); + follow = followSeek(0, &passFail); if (passFail == DmtxFail) return -1; while (abs(follow.step) <= region.stepsTotal) { if (static_cast(*follow.ptr & clearMask) == 0x00) return -1; *follow.ptr &= (clearMask ^ 0xff); - follow = FollowStep(follow, +1, &passFail); + follow = followStep(follow, +1, &passFail); if (passFail == DmtxFail) return -1; clears++; } @@ -1018,7 +1028,7 @@ int DmtxDecode::TrailClear(int clearMask) return clears; } -unsigned int DmtxDecode::MatrixRegionAlignCalibEdge(int edgeLoc) +unsigned int DmtxDecode::matrixRegionAlignCalibEdge(int edgeLoc) { int streamDir; int steps; @@ -1054,7 +1064,7 @@ unsigned int DmtxDecode::MatrixRegionAlignCalibEdge(int edgeLoc) if (edgeLoc == DmtxEdgeTop) { streamDir = region.polarity * -1; avoidAngle = region.leftLine.angle; - follow = FollowSeekLoc(region.locT, &passFail); + follow = followSeekLoc(region.locT, &passFail); if (passFail == DmtxFail) return DmtxFail; pTmp.X = 0.8; pTmp.Y = (symbolShape == DmtxSymbolRectAuto) ? 0.2 : 0.6; @@ -1064,7 +1074,7 @@ unsigned int DmtxDecode::MatrixRegionAlignCalibEdge(int edgeLoc) if (edgeLoc != DmtxEdgeRight) return DmtxFail; streamDir = region.polarity; avoidAngle = region.bottomLine.angle; - follow = FollowSeekLoc(region.locR, &passFail); + follow = followSeekLoc(region.locR, &passFail); if (passFail == DmtxFail) return DmtxFail; pTmp.X = (symbolShape == DmtxSymbolSquareAuto) ? 0.7 : 0.9; pTmp.Y = 0.8; @@ -1076,11 +1086,11 @@ unsigned int DmtxDecode::MatrixRegionAlignCalibEdge(int edgeLoc) loc1.Y = static_cast(pTmp.Y + 0.5); loc0 = follow.loc; - line = BresLineInit(loc0, loc1, locOrigin); - steps = TrailBlazeGapped(line, streamDir); + line = bresLineInit(loc0, loc1, locOrigin); + steps = trailBlazeGapped(line, streamDir); if (steps < 0) return DmtxFail; - bestLine = FindBestSolidLine2(loc0, steps, streamDir, avoidAngle, &passFail); + bestLine = findBestSolidLine2(loc0, steps, streamDir, avoidAngle, &passFail); if (passFail == DmtxFail) { return DmtxFail; @@ -1105,7 +1115,7 @@ unsigned int DmtxDecode::MatrixRegionAlignCalibEdge(int edgeLoc) return DmtxPass; } -DmtxFollow DmtxDecode::FollowSeekLoc(DmtxPixelLoc loc, unsigned int* passFail) +DmtxFollow DmtxDecode::followSeekLoc(DmtxPixelLoc loc, unsigned int* passFail) { DmtxFollow follow; @@ -1123,7 +1133,7 @@ DmtxFollow DmtxDecode::FollowSeekLoc(DmtxPixelLoc loc, unsigned int* passFail) return follow; } -int DmtxDecode::TrailBlazeGapped(DmtxBresLine line, int streamDir) +int DmtxDecode::trailBlazeGapped(DmtxBresLine line, int streamDir) { unsigned char *beforeCache, *afterCache; DmtxBoolean onEdge; @@ -1153,11 +1163,11 @@ int DmtxDecode::TrailBlazeGapped(DmtxBresLine line, int streamDir) do { if (onEdge == DmtxTrue) { - flowNext = FindStrongestNeighbor(flow, streamDir); + flowNext = findStrongestNeighbor(flow, streamDir); if (flowNext.mag == DmtxUndefined) break; - err = BresLineGetStep(line, flowNext.loc, &travel, &outward); + err = bresLineGetStep(line, flowNext.loc, &travel, &outward); if (err == DmtxFail) { return DmtxFail; } if (flowNext.mag < 50 || outward < 0 || (outward == 0 && travel < 0)) { @@ -1165,14 +1175,14 @@ int DmtxDecode::TrailBlazeGapped(DmtxBresLine line, int streamDir) } else { - BresLineStep(&line, travel, outward); + bresLineStep(&line, travel, outward); flow = flowNext; } } if (onEdge == DmtxFalse) { - BresLineStep(&line, 1, 0); + bresLineStep(&line, 1, 0); flow = GetPointFlow(line.loc, dmtxNeighborNone); if (flow.mag > 50) onEdge = DmtxTrue; @@ -1215,7 +1225,7 @@ int DmtxDecode::TrailBlazeGapped(DmtxBresLine line, int streamDir) return steps; } -DmtxBestLine DmtxDecode::FindBestSolidLine2(DmtxPixelLoc loc0, int tripSteps, int sign, int houghAvoid, unsigned int* passFail) +DmtxBestLine DmtxDecode::findBestSolidLine2(DmtxPixelLoc loc0, int tripSteps, int sign, int houghAvoid, unsigned int* passFail) { int hough[3][DMTX_HOUGH_RES] = { { 0 } }; int houghMin, houghMax; @@ -1236,7 +1246,7 @@ DmtxBestLine DmtxDecode::FindBestSolidLine2(DmtxPixelLoc loc0, int tripSteps, in angleBest = 0; hOffset = hOffsetBest = 0; - follow = FollowSeekLoc(loc0, passFail); + follow = followSeekLoc(loc0, passFail); if (*passFail == DmtxFail) { return line; } @@ -1292,7 +1302,7 @@ DmtxBestLine DmtxDecode::FindBestSolidLine2(DmtxPixelLoc loc0, int tripSteps, in } } - follow = FollowStep2(follow, sign, passFail); + follow = followStep2(follow, sign, passFail); if (*passFail == DmtxFail) { return line; } @@ -1305,7 +1315,7 @@ DmtxBestLine DmtxDecode::FindBestSolidLine2(DmtxPixelLoc loc0, int tripSteps, in return line; } -DmtxFollow DmtxDecode:: FollowStep2(DmtxFollow followBeg, int sign, unsigned int *passFail) +DmtxFollow DmtxDecode:: followStep2(DmtxFollow followBeg, int sign, unsigned int *passFail) { int patternIdx; DmtxFollow follow; @@ -1341,10 +1351,10 @@ int DmtxDecode::dmtxDecodeMatrixRegion(int fix, DmtxMessage& msg) DmtxVector2 topLeft, topRight, bottomLeft, bottomRight; DmtxPixelLoc pxTopLeft, pxTopRight, pxBottomLeft, pxBottomRight; - if (msg.Init(this->region.sizeIdx, DmtxFormatMatrix) < 0) + if (msg.init(this->region.sizeIdx, DmtxFormatMatrix) < 0) return -1; - if (PopulateArrayFromMatrix(&msg) != DmtxPass) { + if (populateArrayFromMatrix(&msg) != DmtxPass) { return -1; } @@ -1371,7 +1381,7 @@ int DmtxDecode::dmtxDecodeMatrixRegion(int fix, DmtxMessage& msg) pxBottomRight.X = static_cast(0.5 + bottomRight.X); pxBottomRight.Y = static_cast(0.5 + bottomRight.Y); - if (CacheFillQuad(pxTopLeft, pxTopRight, pxBottomRight, pxBottomLeft) == DmtxFail) + if (cacheFillQuad(pxTopLeft, pxTopRight, pxBottomRight, pxBottomLeft) == DmtxFail) return NULL; msg.points.clear(); @@ -1383,7 +1393,7 @@ int DmtxDecode::dmtxDecodeMatrixRegion(int fix, DmtxMessage& msg) return dmtxDecodePopulatedArray(this->region.sizeIdx, msg, fix); } -unsigned int DmtxDecode::CacheFillQuad(DmtxPixelLoc p0, DmtxPixelLoc p1, DmtxPixelLoc p2, DmtxPixelLoc p3) +unsigned int DmtxDecode::cacheFillQuad(DmtxPixelLoc p0, DmtxPixelLoc p1, DmtxPixelLoc p2, DmtxPixelLoc p3) { DmtxBresLine lines[4]; DmtxPixelLoc pEmpty = { 0, 0 }; @@ -1392,10 +1402,10 @@ unsigned int DmtxDecode::CacheFillQuad(DmtxPixelLoc p0, DmtxPixelLoc p1, DmtxPix int minY, maxY, sizeY, posY, posX; int i, idx; - lines[0] = BresLineInit(p0, p1, pEmpty); - lines[1] = BresLineInit(p1, p2, pEmpty); - lines[2] = BresLineInit(p2, p3, pEmpty); - lines[3] = BresLineInit(p3, p0, pEmpty); + lines[0] = bresLineInit(p0, p1, pEmpty); + lines[1] = bresLineInit(p1, p2, pEmpty); + lines[2] = bresLineInit(p2, p3, pEmpty); + lines[3] = bresLineInit(p3, p0, pEmpty); minY = this->yMax; maxY = 0; @@ -1424,7 +1434,7 @@ unsigned int DmtxDecode::CacheFillQuad(DmtxPixelLoc p0, DmtxPixelLoc p1, DmtxPix idx = lines[i].loc.Y - minY; scanlineMin[idx] = fmin(scanlineMin[idx], lines[i].loc.X); scanlineMax[idx] = fmax(scanlineMax[idx], lines[i].loc.X); - BresLineStep(lines + i, 1, 0); + bresLineStep(lines + i, 1, 0); } } @@ -1443,7 +1453,7 @@ unsigned int DmtxDecode::CacheFillQuad(DmtxPixelLoc p0, DmtxPixelLoc p1, DmtxPix return DmtxPass; } -DmtxBresLine DmtxDecode::BresLineInit(DmtxPixelLoc loc0, DmtxPixelLoc loc1, DmtxPixelLoc locInside) +DmtxBresLine DmtxDecode::bresLineInit(DmtxPixelLoc loc0, DmtxPixelLoc loc1, DmtxPixelLoc locInside) { int cp; DmtxBresLine line; @@ -1509,7 +1519,7 @@ DmtxBresLine DmtxDecode::BresLineInit(DmtxPixelLoc loc0, DmtxPixelLoc loc1, Dmtx return line; } -unsigned int DmtxDecode::BresLineStep(DmtxBresLine *line, int travel, int outward) +unsigned int DmtxDecode::bresLineStep(DmtxBresLine *line, int travel, int outward) { int i; DmtxBresLine lineNew; @@ -1581,7 +1591,7 @@ unsigned int DmtxDecode::BresLineStep(DmtxBresLine *line, int travel, int outwar return DmtxPass; } -DmtxBestLine DmtxDecode::FindBestSolidLine(int step0, int step1, int streamDir, int houghAvoid, unsigned int* passFail) +DmtxBestLine DmtxDecode::findBestSolidLine(int step0, int step1, int streamDir, int houghAvoid, unsigned int* passFail) { int hough[3][DMTX_HOUGH_RES] = { { 0 } }; int houghMin, houghMax; @@ -1638,7 +1648,7 @@ DmtxBestLine DmtxDecode::FindBestSolidLine(int step0, int step1, int streamDir, return line; } - follow = FollowSeek(step0, passFail); + follow = followSeek(step0, passFail); if (*passFail == DmtxFail) { // *passFail = DmtxFail; @@ -1700,7 +1710,7 @@ DmtxBestLine DmtxDecode::FindBestSolidLine(int step0, int step1, int streamDir, } } } - follow = FollowStep(follow, sign, passFail); + follow = followStep(follow, sign, passFail); if (*passFail == DmtxFail) { // *passFail = DmtxFail; @@ -1715,7 +1725,7 @@ DmtxBestLine DmtxDecode::FindBestSolidLine(int step0, int step1, int streamDir, return line; } -unsigned int DmtxDecode::FindTravelLimits(DmtxBestLine *line) +unsigned int DmtxDecode::findTravelLimits(DmtxBestLine *line) { int i; int distSq, distSqMax; @@ -1730,7 +1740,7 @@ unsigned int DmtxDecode::FindTravelLimits(DmtxBestLine *line) unsigned int passFail; /* line->stepBeg is already known to sit on the best Hough line */ - followPos = followNeg = FollowSeek(line->stepBeg, &passFail); + followPos = followNeg = followSeek(line->stepBeg, &passFail); if (passFail == DmtxFail) return DmtxFail; loc0 = followPos.loc; @@ -1756,7 +1766,7 @@ unsigned int DmtxDecode::FindTravelLimits(DmtxBestLine *line) posWander = (cosAngle * yDiff) - (sinAngle * xDiff); if (posWander >= -3*256 && posWander <= 3*256) { - distSq = static_cast(DistanceSquared(followPos.loc, negMax)); + distSq = static_cast(distanceSquared(followPos.loc, negMax)); if (distSq > distSqMax) { posMax = followPos.loc; distSqMax = distSq; @@ -1786,7 +1796,7 @@ unsigned int DmtxDecode::FindTravelLimits(DmtxBestLine *line) if (negWander >= -3*256 && negWander < 3*256) { - distSq = static_cast(DistanceSquared(followNeg.loc, posMax)); + distSq = static_cast(distanceSquared(followNeg.loc, posMax)); if (distSq > distSqMax) { negMax = followNeg.loc; distSqMax = distSq; @@ -1807,9 +1817,9 @@ unsigned int DmtxDecode::FindTravelLimits(DmtxBestLine *line) break; } - followPos = FollowStep(followPos, +1, &passFail); + followPos = followStep(followPos, +1, &passFail); if (passFail == DmtxFail) return DmtxFail; - followNeg = FollowStep(followNeg, -1, &passFail); + followNeg = followStep(followNeg, -1, &passFail); if (passFail == DmtxFail) return DmtxFail; } line->devn = fmax(posWanderMaxLock - posWanderMinLock, negWanderMaxLock - negWanderMinLock)/256; @@ -1818,7 +1828,7 @@ unsigned int DmtxDecode::FindTravelLimits(DmtxBestLine *line) return DmtxPass; } -long DmtxDecode::DistanceSquared(DmtxPixelLoc a, DmtxPixelLoc b) +long DmtxDecode::distanceSquared(DmtxPixelLoc a, DmtxPixelLoc b) { long xDelta, yDelta; @@ -1957,9 +1967,9 @@ unsigned int DmtxDecode::dmtxRegionUpdateCorners(DmtxVector2 p00, DmtxVector2 p1 dmtxVector2Cross(&vOT, &vTX) >= 0.0) return DmtxFail; - if (RightAngleTrueness(p00, p10, p11, M_PI_2) <= this->squareDevn) + if (rightAngleTrueness(p00, p10, p11, M_PI_2) <= this->squareDevn) return DmtxFail; - if (RightAngleTrueness(p10, p11, p01, M_PI_2) <= this->squareDevn) + if (rightAngleTrueness(p10, p11, p01, M_PI_2) <= this->squareDevn) return DmtxFail; /* Calculate values needed for transformations */ @@ -2023,7 +2033,7 @@ unsigned int DmtxDecode::dmtxRegionUpdateCorners(DmtxVector2 p00, DmtxVector2 p1 return DmtxPass; } -double DmtxDecode::RightAngleTrueness(DmtxVector2 c0, DmtxVector2 c1, DmtxVector2 c2, double angle) +double DmtxDecode::rightAngleTrueness(DmtxVector2 c0, DmtxVector2 c1, DmtxVector2 c2, double angle) { DmtxVector2 vA, vB; DmtxMatrix3 m; @@ -2038,19 +2048,19 @@ double DmtxDecode::RightAngleTrueness(DmtxVector2 c0, DmtxVector2 c1, DmtxVector return dmtxVector2Dot(&vA, &vB); } -unsigned int DmtxDecode::BresLineGetStep(DmtxBresLine line, DmtxPixelLoc target, int *travel, int *outward) +unsigned int DmtxDecode::bresLineGetStep(DmtxBresLine line, DmtxPixelLoc target, int *travel, int *outward) { /* Determine necessary step along and outward from Bresenham line */ if (line.steep != 0) { *travel = (line.yStep > 0) ? target.Y - line.loc.Y : line.loc.Y - target.Y; - BresLineStep(&line, *travel, 0); + bresLineStep(&line, *travel, 0); *outward = (line.xOut > 0) ? target.X - line.loc.X : line.loc.X - target.X; if (line.yOut != 0) return DmtxFail; } else { *travel = (line.xStep > 0) ? target.X - line.loc.X : line.loc.X - target.X; - BresLineStep(&line, *travel, 0); + bresLineStep(&line, *travel, 0); *outward = (line.yOut > 0) ? target.Y - line.loc.Y : line.loc.Y - target.Y; if (line.xOut != 0) return DmtxFail; } @@ -2060,7 +2070,7 @@ unsigned int DmtxDecode::BresLineGetStep(DmtxBresLine line, DmtxPixelLoc target, /// -unsigned int DmtxDecode::PopulateArrayFromMatrix(DmtxMessage *msg) +unsigned int DmtxDecode::populateArrayFromMatrix(DmtxMessage *msg) { int weightFactor; int mapWidth, mapHeight; @@ -2094,13 +2104,13 @@ unsigned int DmtxDecode::PopulateArrayFromMatrix(DmtxMessage *msg) xOrigin = xRegionCount * (mapWidth + 2) + 1; memset(tally, 0x00, 24 * 24 * sizeof(int)); - if (TallyModuleJumps(tally, xOrigin, yOrigin, mapWidth, mapHeight, DmtxDirUp) == DmtxFail) + if (tallyModuleJumps(tally, xOrigin, yOrigin, mapWidth, mapHeight, DmtxDirUp) == DmtxFail) return DmtxFail; - if (TallyModuleJumps(tally, xOrigin, yOrigin, mapWidth, mapHeight, DmtxDirLeft) == DmtxFail) + if (tallyModuleJumps(tally, xOrigin, yOrigin, mapWidth, mapHeight, DmtxDirLeft) == DmtxFail) return DmtxFail; - if (TallyModuleJumps(tally, xOrigin, yOrigin, mapWidth, mapHeight, DmtxDirDown) == DmtxFail) + if (tallyModuleJumps(tally, xOrigin, yOrigin, mapWidth, mapHeight, DmtxDirDown) == DmtxFail) return DmtxFail; - if (TallyModuleJumps(tally, xOrigin, yOrigin, mapWidth, mapHeight, DmtxDirRight) == DmtxFail) + if (tallyModuleJumps(tally, xOrigin, yOrigin, mapWidth, mapHeight, DmtxDirRight) == DmtxFail) return DmtxFail; /* Decide module status based on final tallies */ @@ -2129,7 +2139,7 @@ unsigned int DmtxDecode::PopulateArrayFromMatrix(DmtxMessage *msg) return DmtxPass; } -unsigned int DmtxDecode::TallyModuleJumps(int tally[][24], int xOrigin, int yOrigin, int mapWidth, int mapHeight, DmtxDirection dir) +unsigned int DmtxDecode::tallyModuleJumps(int tally[][24], int xOrigin, int yOrigin, int mapWidth, int mapHeight, DmtxDirection dir) { int extent, weight; int travelStep; @@ -2187,7 +2197,7 @@ unsigned int DmtxDecode::TallyModuleJumps(int tally[][24], int xOrigin, int yOri decide status based on predictable barcode border pattern */ *travel = travelStart; - color = ReadModuleColor(symbolRow, symbolCol, region.sizeIdx); + color = readModuleColor(symbolRow, symbolCol, region.sizeIdx); if (color == -1) return DmtxFail; tModule = (darkOnLight) ? region.offColor - color : color - region.offColor; @@ -2204,7 +2214,7 @@ unsigned int DmtxDecode::TallyModuleJumps(int tally[][24], int xOrigin, int yOri /* For normal data-bearing modules capture color and decide module status based on comparison to previous "known" module */ - color = ReadModuleColor(symbolRow, symbolCol, region.sizeIdx); + color = readModuleColor(symbolRow, symbolCol, region.sizeIdx); if (color == -1) return DmtxFail; tModule = (darkOnLight) ? region.offColor - color : color - region.offColor; @@ -2251,7 +2261,7 @@ unsigned int DmtxDecode::TallyModuleJumps(int tally[][24], int xOrigin, int yOri return DmtxPass; } -int DmtxDecode::ReadModuleColor(int symbolRow, int symbolCol, int sizeIdx) +int DmtxDecode::readModuleColor(int symbolRow, int symbolCol, int sizeIdx) { int colorTmp; double sampleX[] = { 0.5, 0.4, 0.5, 0.6, 0.5 }; @@ -2298,14 +2308,14 @@ int DmtxDecode::dmtxDecodePopulatedArray(int sizeIdx, DmtxMessage& msg, int fix) * */ - if (ModulePlacementEcc200(msg.array, msg.code, sizeIdx, DmtxModuleOnRed | DmtxModuleOnGreen | DmtxModuleOnBlue) < 0) + if (modulePlacementEcc200(msg.array, msg.code, sizeIdx, DmtxModuleOnRed | DmtxModuleOnGreen | DmtxModuleOnBlue) < 0) return -1; - if (RsDecode(msg.code, sizeIdx, fix) == DmtxFail){ + if (rsDecode(msg.code, sizeIdx, fix) == DmtxFail){ return -1; } - if (msg.DecodeDataStream(sizeIdx, NULL) == DmtxFail) + if (msg.decodeDataStream(sizeIdx, NULL) == DmtxFail) { return -1; } @@ -2315,7 +2325,7 @@ int DmtxDecode::dmtxDecodePopulatedArray(int sizeIdx, DmtxMessage& msg, int fix) /// -int DmtxDecode::InitScanGrid() +int DmtxDecode::initScanGrid() { memset(&grid, 0x00, sizeof(DmtxScanGrid)); diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxdecode.hpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxdecode.hpp index 8360ab60ad..92f9776e17 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxdecode.hpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxdecode.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxdecode.hpp // test_dm @@ -5,8 +15,8 @@ // Created by wechatcv on 2022/5/7. // -#ifndef dmtxdecode_hpp -#define dmtxdecode_hpp +#ifndef __ZXING_DATAMATRIX_LIBDMTX_DMTXDECODE_HPP__ +#define __ZXING_DATAMATRIX_LIBDMTX_DMTXDECODE_HPP__ #include #include "common.hpp" @@ -39,47 +49,47 @@ public: int dmtxRegionFindNext(); private: - int InitScanGrid(); + int initScanGrid(); - unsigned int PopulateArrayFromMatrix(DmtxMessage *msg); - unsigned int CacheFillQuad(DmtxPixelLoc p0, DmtxPixelLoc p1, DmtxPixelLoc p2, DmtxPixelLoc p3); - unsigned int TallyModuleJumps(int tally[][24], int xOrigin, int yOrigin, int mapWidth, int mapHeight, DmtxDirection dir); - int ReadModuleColor(int symbolRow, int symbolCol, int sizeIdx); + unsigned int populateArrayFromMatrix(DmtxMessage *msg); + unsigned int cacheFillQuad(DmtxPixelLoc p0, DmtxPixelLoc p1, DmtxPixelLoc p2, DmtxPixelLoc p3); + unsigned int tallyModuleJumps(int tally[][24], int xOrigin, int yOrigin, int mapWidth, int mapHeight, DmtxDirection dir); + int readModuleColor(int symbolRow, int symbolCol, int sizeIdx); - DmtxBresLine BresLineInit(DmtxPixelLoc loc0, DmtxPixelLoc loc1, DmtxPixelLoc locInside); - unsigned int BresLineStep(DmtxBresLine *line, int travel, int outward); - unsigned int BresLineGetStep(DmtxBresLine line, DmtxPixelLoc target, int *travel, int *outward); + DmtxBresLine bresLineInit(DmtxPixelLoc loc0, DmtxPixelLoc loc1, DmtxPixelLoc locInside); + unsigned int bresLineStep(DmtxBresLine *line, int travel, int outward); + unsigned int bresLineGetStep(DmtxBresLine line, DmtxPixelLoc target, int *travel, int *outward); - int PopGridLocation( DmtxPixelLoc *locPtr); - int GetGridCoordinates(DmtxPixelLoc *locPtr); + int popGridLocation( DmtxPixelLoc *locPtr); + int getGridCoordinates(DmtxPixelLoc *locPtr); int dmtxRegionScanPixel(int x, int y); - DmtxPointFlow MatrixRegionSeekEdge(DmtxPixelLoc loc); + DmtxPointFlow matrixRegionSeekEdge(DmtxPixelLoc loc); DmtxPointFlow GetPointFlow(DmtxPixelLoc loc, int arrive); - DmtxPointFlow FindStrongestNeighbor(DmtxPointFlow center, int sign); - unsigned int MatrixRegionOrientation(DmtxPointFlow begin); + DmtxPointFlow findStrongestNeighbor(DmtxPointFlow center, int sign); + unsigned int matrixRegionOrientation(DmtxPointFlow begin); - unsigned int TrailBlazeContinuous(DmtxPointFlow flowBegin, int maxDiagonal); - int TrailClear(int clearMask); - int TrailBlazeGapped(DmtxBresLine line, int streamDir); + unsigned int trailBlazeContinuous(DmtxPointFlow flowBegin, int maxDiagonal); + int trailClear(int clearMask); + int trailBlazeGapped(DmtxBresLine line, int streamDir); - DmtxBestLine FindBestSolidLine(int step0, int step1, int streamDir, int houghAvoid, unsigned int* passFail); - DmtxBestLine FindBestSolidLine2(DmtxPixelLoc loc0, int tripSteps, int sign, int houghAvoid, unsigned int* passFail); + DmtxBestLine findBestSolidLine(int step0, int step1, int streamDir, int houghAvoid, unsigned int* passFail); + DmtxBestLine findBestSolidLine2(DmtxPixelLoc loc0, int tripSteps, int sign, int houghAvoid, unsigned int* passFail); - unsigned int FindTravelLimits(DmtxBestLine *line); + unsigned int findTravelLimits(DmtxBestLine *line); unsigned int dmtxRegionUpdateXfrms(); - unsigned int MatrixRegionAlignCalibEdge(int edgeLoc); - unsigned int MatrixRegionFindSize(); - int CountJumpTally(int xStart, int yStart, DmtxDirection dir); - DmtxFollow FollowSeek(int seek, unsigned int* passFail); - DmtxFollow FollowStep(DmtxFollow followBeg, int sign, unsigned int* passFail); - DmtxFollow FollowSeekLoc(DmtxPixelLoc loc, unsigned int* passFail); - DmtxFollow FollowStep2(DmtxFollow followBeg, int sign, unsigned int* passFail); + unsigned int matrixRegionAlignCalibEdge(int edgeLoc); + unsigned int matrixRegionFindSize(); + int countJumpTally(int xStart, int yStart, DmtxDirection dir); + DmtxFollow followSeek(int seek, unsigned int* passFail); + DmtxFollow followStep(DmtxFollow followBeg, int sign, unsigned int* passFail); + DmtxFollow followSeekLoc(DmtxPixelLoc loc, unsigned int* passFail); + DmtxFollow followStep2(DmtxFollow followBeg, int sign, unsigned int* passFail); - long DistanceSquared(DmtxPixelLoc a, DmtxPixelLoc b); + long distanceSquared(DmtxPixelLoc a, DmtxPixelLoc b); unsigned int dmtxRegionUpdateCorners(DmtxVector2 p00, DmtxVector2 p10, DmtxVector2 p11, DmtxVector2 p01); - double RightAngleTrueness(DmtxVector2 c0, DmtxVector2 c1, DmtxVector2 c2, double angle); + double rightAngleTrueness(DmtxVector2 c0, DmtxVector2 c1, DmtxVector2 c2, double angle); private: @@ -107,4 +117,4 @@ private: }; } // namespace dmtx -#endif /* dmtxdecode_hpp */ +#endif // __ZXING_DATAMATRIX_LIBDMTX_DMTXDECODE_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtximage.cpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtximage.cpp index c9ff699a71..5080ef7f8b 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtximage.cpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtximage.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtximage.cpp // test_dm diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtximage.hpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtximage.hpp index 36a76cae94..ebc4fe085d 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtximage.hpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtximage.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtximage.hpp // test_dm @@ -5,8 +15,8 @@ // Created by wechatcv on 2022/5/5. // -#ifndef dmtximage_hpp -#define dmtximage_hpp +#ifndef __ZXING_DATAMATRIX_LIBDMTX_DMTXIMAGE_HPP__ +#define __ZXING_DATAMATRIX_LIBDMTX_DMTXIMAGE_HPP__ #include @@ -36,4 +46,4 @@ private: }; } // namespace dmtx -#endif // QBAR_AI_QBAR_ZXING_DATAMATRIX_LIBDMTX_DMTXIMAGE_H_ +#endif // __ZXING_DATAMATRIX_LIBDMTX_DMTXIMAGE_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmatrix3.cpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmatrix3.cpp index 5aeddb3c51..2087d8f246 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmatrix3.cpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmatrix3.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxmatrix3.cpp // test_dm diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmatrix3.hpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmatrix3.hpp index e5ae766ab4..72d89d1506 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmatrix3.hpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmatrix3.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxmatrix3.hpp // test_dm @@ -5,8 +15,8 @@ // Created by wechatcv on 2022/5/5. // -#ifndef dmtxmatrix3_hpp -#define dmtxmatrix3_hpp +#ifndef __ZXING_DATAMATRIX_LIBDMTX_DMTXMATRIX3_HPP__ +#define __ZXING_DATAMATRIX_LIBDMTX_DMTXMATRIX3_HPP__ #include #include "common.hpp" @@ -29,4 +39,4 @@ int dmtxMatrix3VMultiplyBy(DmtxVector2 *v, DmtxMatrix3 m); } // namespace dmtx -#endif /* dmtxmatrix3_hpp */ +#endif // __ZXING_DATAMATRIX_LIBDMTX_DMTXMATRIX3_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmessage.cpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmessage.cpp index 9a502918a9..be4777f52f 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmessage.cpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmessage.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxmessage.cpp // test_dm @@ -26,7 +36,7 @@ DmtxMessage::~DmtxMessage() free(this->output); } -int DmtxMessage::Init(int sizeIdx, int symbolFormat) +int DmtxMessage::init(int sizeIdx, int symbolFormat) { int mappingRows, mappingCols; @@ -70,7 +80,7 @@ int DmtxMessage::Init(int sizeIdx, int symbolFormat) return 0; } -unsigned int DmtxMessage::DecodeDataStream(int sizeIdx, unsigned char *outputStart) +unsigned int DmtxMessage::decodeDataStream(int sizeIdx, unsigned char *outputStart) { DmtxBoolean macro = DmtxFalse; DmtxScheme encScheme; @@ -87,7 +97,7 @@ unsigned int DmtxMessage::DecodeDataStream(int sizeIdx, unsigned char *outputSta /* Print macro header if first codeword triggers it */ if (*ptr == DmtxValue05Macro || *ptr == DmtxValue06Macro) { - PushOutputMacroHeader(*ptr); + pushOutputMacroHeader(*ptr); macro = DmtxTrue; } @@ -95,7 +105,7 @@ unsigned int DmtxMessage::DecodeDataStream(int sizeIdx, unsigned char *outputSta return DmtxFail; while (ptr < dataEnd) { - encScheme = (DmtxScheme)GetEncodationScheme(*ptr); + encScheme = (DmtxScheme)getEncodationScheme(*ptr); if (encScheme != DmtxSchemeAscii) ptr++; @@ -104,20 +114,20 @@ unsigned int DmtxMessage::DecodeDataStream(int sizeIdx, unsigned char *outputSta switch (encScheme) { case DmtxSchemeAscii: - ptr = DecodeSchemeAscii(ptr, dataEnd); + ptr = decodeSchemeAscii(ptr, dataEnd); break; case DmtxSchemeC40: case DmtxSchemeText: - ptr = DecodeSchemeC40Text(ptr, dataEnd, encScheme); + ptr = decodeSchemeC40Text(ptr, dataEnd, encScheme); break; case DmtxSchemeX12: - ptr = DecodeSchemeX12(ptr, dataEnd); + ptr = decodeSchemeX12(ptr, dataEnd); break; case DmtxSchemeEdifact: - ptr = DecodeSchemeEdifact(ptr, dataEnd); + ptr = decodeSchemeEdifact(ptr, dataEnd); break; case DmtxSchemeBase256: - ptr = DecodeSchemeBase256(ptr, dataEnd); + ptr = decodeSchemeBase256(ptr, dataEnd); break; default: /* error */ @@ -130,12 +140,12 @@ unsigned int DmtxMessage::DecodeDataStream(int sizeIdx, unsigned char *outputSta /* Print macro trailer if required */ if (macro == DmtxTrue) - PushOutputMacroTrailer(); + pushOutputMacroTrailer(); return DmtxPass; } -int DmtxMessage::GetEncodationScheme(unsigned char cw) +int DmtxMessage::getEncodationScheme(unsigned char cw) { DmtxScheme encScheme; @@ -163,7 +173,7 @@ int DmtxMessage::GetEncodationScheme(unsigned char cw) return encScheme; } -unsigned int DmtxMessage::PushOutputWord(int value) +unsigned int DmtxMessage::pushOutputWord(int value) { if (value < 0 || value >= 256) return DmtxFail; @@ -171,12 +181,12 @@ unsigned int DmtxMessage::PushOutputWord(int value) return DmtxPass; } -DmtxBoolean DmtxMessage::ValidOutputWord(int value) +DmtxBoolean DmtxMessage::validOutputWord(int value) { return (value >= 0 && value < 256) ? DmtxTrue : DmtxFalse; } -unsigned int DmtxMessage::PushOutputC40TextWord(C40TextState *state, int value) +unsigned int DmtxMessage::pushOutputC40TextWord(C40TextState *state, int value) { if (value < 0 || value >= 256) return DmtxFail; @@ -196,39 +206,39 @@ unsigned int DmtxMessage::PushOutputC40TextWord(C40TextState *state, int value) return DmtxPass; } -unsigned int DmtxMessage::PushOutputMacroHeader(int macroType) +unsigned int DmtxMessage::pushOutputMacroHeader(int macroType) { - PushOutputWord('['); - PushOutputWord(')'); - PushOutputWord('>'); - PushOutputWord(30); /* ASCII RS */ - PushOutputWord('0'); + pushOutputWord('['); + pushOutputWord(')'); + pushOutputWord('>'); + pushOutputWord(30); /* ASCII RS */ + pushOutputWord('0'); if (macroType != DmtxValue05Macro && macroType != DmtxValue06Macro) return DmtxFail; if (macroType == DmtxValue05Macro) - PushOutputWord('5'); + pushOutputWord('5'); else - PushOutputWord('6'); + pushOutputWord('6'); - PushOutputWord(29); /* ASCII GS */ + pushOutputWord(29); /* ASCII GS */ return DmtxPass; } -void DmtxMessage::PushOutputMacroTrailer() +void DmtxMessage::pushOutputMacroTrailer() { - PushOutputWord(30); /* ASCII RS */ - PushOutputWord(4); /* ASCII EOT */ + pushOutputWord(30); /* ASCII RS */ + pushOutputWord(4); /* ASCII EOT */ } -unsigned char * DmtxMessage::DecodeSchemeAscii(unsigned char *ptr, unsigned char *dataEnd) +unsigned char * DmtxMessage::decodeSchemeAscii(unsigned char *ptr, unsigned char *dataEnd) { int upperShift = DmtxFalse; while (ptr < dataEnd) { int codeword = static_cast(*ptr); - if (GetEncodationScheme(*ptr) != DmtxSchemeAscii) + if (getEncodationScheme(*ptr) != DmtxSchemeAscii) return ptr; else ptr++; @@ -236,9 +246,9 @@ unsigned char * DmtxMessage::DecodeSchemeAscii(unsigned char *ptr, unsigned char if (upperShift == DmtxTrue) { int pushword = codeword + 127; - if (ValidOutputWord(pushword) != DmtxTrue) + if (validOutputWord(pushword) != DmtxTrue) return NULL; - PushOutputWord(pushword); + pushOutputWord(pushword); upperShift = DmtxFalse; } else if (codeword == DmtxValueAsciiUpperShift) @@ -258,15 +268,15 @@ unsigned char * DmtxMessage::DecodeSchemeAscii(unsigned char *ptr, unsigned char } else if (codeword <= 128) { - if (PushOutputWord(codeword - 1) == DmtxFail) + if (pushOutputWord(codeword - 1) == DmtxFail) return NULL; } else if (codeword <= 229) { int digits = codeword - 130; - if (PushOutputWord(digits/10 + '0') == DmtxFail) + if (pushOutputWord(digits/10 + '0') == DmtxFail) return NULL; - if (PushOutputWord(digits - (digits/10)*10 + '0') == DmtxFail) + if (pushOutputWord(digits - (digits/10)*10 + '0') == DmtxFail) return NULL; } else if (codeword == DmtxValueFNC1) @@ -274,9 +284,9 @@ unsigned char * DmtxMessage::DecodeSchemeAscii(unsigned char *ptr, unsigned char if (this->fnc1 != DmtxUndefined) { int pushword = this->fnc1; - if (ValidOutputWord(pushword) != DmtxTrue) + if (validOutputWord(pushword) != DmtxTrue) return NULL; - PushOutputWord(pushword); + pushOutputWord(pushword); } } } @@ -284,7 +294,7 @@ unsigned char * DmtxMessage::DecodeSchemeAscii(unsigned char *ptr, unsigned char return ptr; } -unsigned char * DmtxMessage::DecodeSchemeC40Text(unsigned char *ptr, unsigned char *dataEnd, DmtxScheme encScheme) +unsigned char * DmtxMessage::decodeSchemeC40Text(unsigned char *ptr, unsigned char *dataEnd, DmtxScheme encScheme) { int i; int packed; @@ -317,55 +327,55 @@ unsigned char * DmtxMessage::DecodeSchemeC40Text(unsigned char *ptr, unsigned ch } else if (c40Values[i] == 3) { - if (PushOutputC40TextWord(&state, ' ') == DmtxFail) + if (pushOutputC40TextWord(&state, ' ') == DmtxFail) return NULL; } else if (c40Values[i] <= 13) { - if (PushOutputC40TextWord(&state, c40Values[i] - 13 + '9') == DmtxFail) + if (pushOutputC40TextWord(&state, c40Values[i] - 13 + '9') == DmtxFail) return NULL; /* 0-9 */ } else if (c40Values[i] <= 39) { if (encScheme == DmtxSchemeC40) { - if (PushOutputC40TextWord(&state, c40Values[i] - 39 + 'Z') == DmtxFail) + if (pushOutputC40TextWord(&state, c40Values[i] - 39 + 'Z') == DmtxFail) return NULL; /* A-Z */ } else if (encScheme == DmtxSchemeText) { - if (PushOutputC40TextWord(&state, c40Values[i] - 39 + 'z') == DmtxFail) + if (pushOutputC40TextWord(&state, c40Values[i] - 39 + 'z') == DmtxFail) return NULL; /* a-z */ } } } else if (state.shift == DmtxC40TextShift1) { /* Shift 1 set */ - if (PushOutputC40TextWord(&state, c40Values[i]) == DmtxFail) + if (pushOutputC40TextWord(&state, c40Values[i]) == DmtxFail) return NULL; /* ASCII 0 - 31 */ } else if (state.shift == DmtxC40TextShift2) { /* Shift 2 set */ if (c40Values[i] <= 14) { - if (PushOutputC40TextWord(&state, c40Values[i] + 33) == DmtxFail) + if (pushOutputC40TextWord(&state, c40Values[i] + 33) == DmtxFail) return NULL; /* ASCII 33 - 47 */ } else if (c40Values[i] <= 21) { - if (PushOutputC40TextWord(&state, c40Values[i] + 43) == DmtxFail) + if (pushOutputC40TextWord(&state, c40Values[i] + 43) == DmtxFail) return NULL; /* ASCII 58 - 64 */ } else if (c40Values[i] <= 26) { - if (PushOutputC40TextWord(&state, c40Values[i] + 69) == DmtxFail) + if (pushOutputC40TextWord(&state, c40Values[i] + 69) == DmtxFail) return NULL; /* ASCII 91 - 95 */ } else if (c40Values[i] == 27) { if (this->fnc1 != DmtxUndefined) { - if (PushOutputC40TextWord(&state, this->fnc1) == DmtxFail) + if (pushOutputC40TextWord(&state, this->fnc1) == DmtxFail) return NULL; } } @@ -379,24 +389,24 @@ unsigned char * DmtxMessage::DecodeSchemeC40Text(unsigned char *ptr, unsigned ch { /* Shift 3 set */ if (encScheme == DmtxSchemeC40) { - if (PushOutputC40TextWord(&state, c40Values[i] + 96) == DmtxFail) + if (pushOutputC40TextWord(&state, c40Values[i] + 96) == DmtxFail) return NULL; } else if (encScheme == DmtxSchemeText) { if (c40Values[i] == 0) { - if (PushOutputC40TextWord(&state, c40Values[i] + 96) == DmtxFail) + if (pushOutputC40TextWord(&state, c40Values[i] + 96) == DmtxFail) return NULL; } else if (c40Values[i] <= 26) { - if (PushOutputC40TextWord(&state, c40Values[i] - 26 + 'Z') == DmtxFail) + if (pushOutputC40TextWord(&state, c40Values[i] - 26 + 'Z') == DmtxFail) return NULL; /* A-Z */ } else { - if (PushOutputC40TextWord(&state, c40Values[i] - 31 + 127) == DmtxFail) + if (pushOutputC40TextWord(&state, c40Values[i] - 31 + 127) == DmtxFail) return NULL; /* { | } ~ DEL */ } } @@ -415,7 +425,7 @@ unsigned char * DmtxMessage::DecodeSchemeC40Text(unsigned char *ptr, unsigned ch return ptr; } -unsigned char * DmtxMessage::DecodeSchemeX12(unsigned char *ptr, unsigned char *dataEnd) +unsigned char * DmtxMessage::decodeSchemeX12(unsigned char *ptr, unsigned char *dataEnd) { int i; int packed; @@ -435,21 +445,21 @@ unsigned char * DmtxMessage::DecodeSchemeX12(unsigned char *ptr, unsigned char * for (i = 0; i < 3; i++) { if (x12Values[i] == 0) - PushOutputWord(13); + pushOutputWord(13); else if (x12Values[i] == 1) - PushOutputWord(42); + pushOutputWord(42); else if (x12Values[i] == 2) - PushOutputWord(62); + pushOutputWord(62); else if (x12Values[i] == 3) - PushOutputWord(32); + pushOutputWord(32); else if (x12Values[i] <= 13) { - if (PushOutputWord(x12Values[i] + 44) == DmtxFail) + if (pushOutputWord(x12Values[i] + 44) == DmtxFail) return NULL; } else if (x12Values[i] <= 90) { - if (PushOutputWord(x12Values[i] + 51) == DmtxFail) + if (pushOutputWord(x12Values[i] + 51) == DmtxFail) return NULL; } } @@ -466,7 +476,7 @@ unsigned char * DmtxMessage::DecodeSchemeX12(unsigned char *ptr, unsigned char * return ptr; } -unsigned char * DmtxMessage::DecodeSchemeEdifact(unsigned char *ptr, unsigned char *dataEnd) +unsigned char * DmtxMessage::decodeSchemeEdifact(unsigned char *ptr, unsigned char *dataEnd) { int i; unsigned char unpacked[4]; @@ -497,7 +507,7 @@ unsigned char * DmtxMessage::DecodeSchemeEdifact(unsigned char *ptr, unsigned ch return ptr; } - if (PushOutputWord(unpacked[i] ^ (((unpacked[i] & 0x20) ^ 0x20) << 1)) == DmtxFail) + if (pushOutputWord(unpacked[i] ^ (((unpacked[i] & 0x20) ^ 0x20) << 1)) == DmtxFail) return NULL; } @@ -509,7 +519,7 @@ unsigned char * DmtxMessage::DecodeSchemeEdifact(unsigned char *ptr, unsigned ch return ptr; } -unsigned char * DmtxMessage::DecodeSchemeBase256(unsigned char *ptr, unsigned char *dataEnd) +unsigned char * DmtxMessage::decodeSchemeBase256(unsigned char *ptr, unsigned char *dataEnd) { int d0, d1; int idx; @@ -520,7 +530,7 @@ unsigned char * DmtxMessage::DecodeSchemeBase256(unsigned char *ptr, unsigned ch if (ptr + 1 - this->code > INT_MAX) return NULL; idx = static_cast(ptr + 1 - this->code); - d0 = UnRandomize255State(*(ptr++), idx++); + d0 = unRandomize255State(*(ptr++), idx++); if (d0 == 0) { ptrEnd = dataEnd; } @@ -530,7 +540,7 @@ unsigned char * DmtxMessage::DecodeSchemeBase256(unsigned char *ptr, unsigned ch } else { - d1 = UnRandomize255State(*(ptr++), idx++); + d1 = unRandomize255State(*(ptr++), idx++); ptrEnd = ptr + (d0 - 249) * 250 + d1; } @@ -538,14 +548,14 @@ unsigned char * DmtxMessage::DecodeSchemeBase256(unsigned char *ptr, unsigned ch return NULL; while (ptr < ptrEnd) { - if (PushOutputWord(UnRandomize255State(*(ptr++), idx++)) == DmtxFail) + if (pushOutputWord(unRandomize255State(*(ptr++), idx++)) == DmtxFail) return NULL; } return ptr; } -unsigned char DmtxMessage::UnRandomize255State(unsigned char value, int idx) +unsigned char DmtxMessage::unRandomize255State(unsigned char value, int idx) { int pseudoRandom; int tmp; diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmessage.hpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmessage.hpp index 4a053531cd..93d0b2c80b 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmessage.hpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxmessage.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxmessage.hpp // test_dm @@ -5,8 +15,8 @@ // Created by wechatcv on 2022/5/5. // -#ifndef dmtxmessage_hpp -#define dmtxmessage_hpp +#ifndef __ZXING_DATAMATRIX_LIBDMTX_DMTXMESSAGE_HPP__ +#define __ZXING_DATAMATRIX_LIBDMTX_DMTXMESSAGE_HPP__ #include #include @@ -19,23 +29,23 @@ public: DmtxMessage() {} ~DmtxMessage(); - int Init(int sizeIdx, int symbolFormat); + int init(int sizeIdx, int symbolFormat); - unsigned int DecodeDataStream(int sizeIdx, unsigned char *outputStart); + unsigned int decodeDataStream(int sizeIdx, unsigned char *outputStart); private: - int GetEncodationScheme(unsigned char cw); - DmtxBoolean ValidOutputWord(int value); - unsigned int PushOutputWord(int value); - unsigned int PushOutputC40TextWord(C40TextState *state, int value); - unsigned int PushOutputMacroHeader(int macroType); - void PushOutputMacroTrailer(); - unsigned char *DecodeSchemeAscii(unsigned char *ptr, unsigned char *dataEnd); - unsigned char *DecodeSchemeC40Text(unsigned char *ptr, unsigned char *dataEnd, DmtxScheme encScheme); - unsigned char *DecodeSchemeX12(unsigned char *ptr, unsigned char *dataEnd); - unsigned char *DecodeSchemeEdifact(unsigned char *ptr, unsigned char *dataEnd); - unsigned char *DecodeSchemeBase256(unsigned char *ptr, unsigned char *dataEnd); - unsigned char UnRandomize255State(unsigned char value, int idx); + int getEncodationScheme(unsigned char cw); + DmtxBoolean validOutputWord(int value); + unsigned int pushOutputWord(int value); + unsigned int pushOutputC40TextWord(C40TextState *state, int value); + unsigned int pushOutputMacroHeader(int macroType); + void pushOutputMacroTrailer(); + unsigned char *decodeSchemeAscii(unsigned char *ptr, unsigned char *dataEnd); + unsigned char *decodeSchemeC40Text(unsigned char *ptr, unsigned char *dataEnd, DmtxScheme encScheme); + unsigned char *decodeSchemeX12(unsigned char *ptr, unsigned char *dataEnd); + unsigned char *decodeSchemeEdifact(unsigned char *ptr, unsigned char *dataEnd); + unsigned char *decodeSchemeBase256(unsigned char *ptr, unsigned char *dataEnd); + unsigned char unRandomize255State(unsigned char value, int idx); public: size_t arraySize; /* mappingRows * mappingCols */ @@ -53,4 +63,4 @@ public: } // namespace dmtx -#endif /* dmtxmessage_hpp */ +#endif // __ZXING_DATAMATRIX_LIBDMTX_DMTXMESSAGE_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxplacemod.cpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxplacemod.cpp index b93f3c6315..8b479caa7e 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxplacemod.cpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxplacemod.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxplacemod.cpp // test_dm @@ -12,7 +22,7 @@ namespace dmtx { -int ModulePlacementEcc200(unsigned char *modules, unsigned char *codewords, int sizeIdx, int moduleOnColor) +int modulePlacementEcc200(unsigned char *modules, unsigned char *codewords, int sizeIdx, int moduleOnColor) { int row, col, chr; int mappingRows, mappingCols; @@ -32,19 +42,19 @@ int ModulePlacementEcc200(unsigned char *modules, unsigned char *codewords, int do { /* Repeatedly first check for one of the special corner cases */ if ((row == mappingRows) && (col == 0)) - PatternShapeSpecial1(modules, mappingRows, mappingCols, &(codewords[chr++]), moduleOnColor); + patternShapeSpecial1(modules, mappingRows, mappingCols, &(codewords[chr++]), moduleOnColor); else if ((row == mappingRows-2) && (col == 0) && (mappingCols%4 != 0)) - PatternShapeSpecial2(modules, mappingRows, mappingCols, &(codewords[chr++]), moduleOnColor); + patternShapeSpecial2(modules, mappingRows, mappingCols, &(codewords[chr++]), moduleOnColor); else if ((row == mappingRows-2) && (col == 0) && (mappingCols%8 == 4)) - PatternShapeSpecial3(modules, mappingRows, mappingCols, &(codewords[chr++]), moduleOnColor); + patternShapeSpecial3(modules, mappingRows, mappingCols, &(codewords[chr++]), moduleOnColor); else if ((row == mappingRows+4) && (col == 2) && (mappingCols%8 == 0)) - PatternShapeSpecial4(modules, mappingRows, mappingCols, &(codewords[chr++]), moduleOnColor); + patternShapeSpecial4(modules, mappingRows, mappingCols, &(codewords[chr++]), moduleOnColor); /* Sweep upward diagonally, inserting successive characters */ do { if ((row < mappingRows) && (col >= 0) && !(modules[row*mappingCols+col] & DmtxModuleVisited)) - PatternShapeStandard(modules, mappingRows, mappingCols, row, col, &(codewords[chr++]), moduleOnColor); + patternShapeStandard(modules, mappingRows, mappingCols, row, col, &(codewords[chr++]), moduleOnColor); row -= 2; col += 2; } while ((row >= 0) && (col < mappingCols)); @@ -55,7 +65,7 @@ int ModulePlacementEcc200(unsigned char *modules, unsigned char *codewords, int do { if ((row >= 0) && (col < mappingCols) && !(modules[row*mappingCols+col] & DmtxModuleVisited)) - PatternShapeStandard(modules, mappingRows, mappingCols, row, col, &(codewords[chr++]), moduleOnColor); + patternShapeStandard(modules, mappingRows, mappingCols, row, col, &(codewords[chr++]), moduleOnColor); row += 2; col -= 2; } while ((row < mappingRows) && (col >= 0)); @@ -76,67 +86,67 @@ int ModulePlacementEcc200(unsigned char *modules, unsigned char *codewords, int return chr; /* XXX number of codewords read off */ } -static void PatternShapeStandard(unsigned char *modules, int mappingRows, int mappingCols, int row, int col, unsigned char *codeword, int moduleOnColor) +static void patternShapeStandard(unsigned char *modules, int mappingRows, int mappingCols, int row, int col, unsigned char *codeword, int moduleOnColor) { - PlaceModule(modules, mappingRows, mappingCols, row-2, col-2, codeword, DmtxMaskBit1, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, row-2, col-1, codeword, DmtxMaskBit2, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, row-1, col-2, codeword, DmtxMaskBit3, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, row-1, col-1, codeword, DmtxMaskBit4, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, row-1, col, codeword, DmtxMaskBit5, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, row, col-2, codeword, DmtxMaskBit6, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, row, col-1, codeword, DmtxMaskBit7, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, row, col, codeword, DmtxMaskBit8, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, row-2, col-2, codeword, DmtxMaskBit1, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, row-2, col-1, codeword, DmtxMaskBit2, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, row-1, col-2, codeword, DmtxMaskBit3, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, row-1, col-1, codeword, DmtxMaskBit4, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, row-1, col, codeword, DmtxMaskBit5, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, row, col-2, codeword, DmtxMaskBit6, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, row, col-1, codeword, DmtxMaskBit7, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, row, col, codeword, DmtxMaskBit8, moduleOnColor); } -static void PatternShapeSpecial1(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor) +static void patternShapeSpecial1(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor) { - PlaceModule(modules, mappingRows, mappingCols, mappingRows-1, 0, codeword, DmtxMaskBit1, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, mappingRows-1, 1, codeword, DmtxMaskBit2, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, mappingRows-1, 2, codeword, DmtxMaskBit3, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 0, mappingCols-2, codeword, DmtxMaskBit4, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 0, mappingCols-1, codeword, DmtxMaskBit5, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 1, mappingCols-1, codeword, DmtxMaskBit6, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 2, mappingCols-1, codeword, DmtxMaskBit7, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 3, mappingCols-1, codeword, DmtxMaskBit8, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, mappingRows-1, 0, codeword, DmtxMaskBit1, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, mappingRows-1, 1, codeword, DmtxMaskBit2, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, mappingRows-1, 2, codeword, DmtxMaskBit3, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 0, mappingCols-2, codeword, DmtxMaskBit4, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 0, mappingCols-1, codeword, DmtxMaskBit5, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 1, mappingCols-1, codeword, DmtxMaskBit6, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 2, mappingCols-1, codeword, DmtxMaskBit7, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 3, mappingCols-1, codeword, DmtxMaskBit8, moduleOnColor); } -static void PatternShapeSpecial2(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor) +static void patternShapeSpecial2(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor) { - PlaceModule(modules, mappingRows, mappingCols, mappingRows-3, 0, codeword, DmtxMaskBit1, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, mappingRows-2, 0, codeword, DmtxMaskBit2, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, mappingRows-1, 0, codeword, DmtxMaskBit3, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 0, mappingCols-4, codeword, DmtxMaskBit4, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 0, mappingCols-3, codeword, DmtxMaskBit5, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 0, mappingCols-2, codeword, DmtxMaskBit6, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 0, mappingCols-1, codeword, DmtxMaskBit7, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 1, mappingCols-1, codeword, DmtxMaskBit8, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, mappingRows-3, 0, codeword, DmtxMaskBit1, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, mappingRows-2, 0, codeword, DmtxMaskBit2, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, mappingRows-1, 0, codeword, DmtxMaskBit3, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 0, mappingCols-4, codeword, DmtxMaskBit4, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 0, mappingCols-3, codeword, DmtxMaskBit5, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 0, mappingCols-2, codeword, DmtxMaskBit6, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 0, mappingCols-1, codeword, DmtxMaskBit7, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 1, mappingCols-1, codeword, DmtxMaskBit8, moduleOnColor); } -static void PatternShapeSpecial3(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor) +static void patternShapeSpecial3(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor) { - PlaceModule(modules, mappingRows, mappingCols, mappingRows-3, 0, codeword, DmtxMaskBit1, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, mappingRows-2, 0, codeword, DmtxMaskBit2, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, mappingRows-1, 0, codeword, DmtxMaskBit3, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 0, mappingCols-2, codeword, DmtxMaskBit4, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 0, mappingCols-1, codeword, DmtxMaskBit5, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 1, mappingCols-1, codeword, DmtxMaskBit6, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 2, mappingCols-1, codeword, DmtxMaskBit7, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 3, mappingCols-1, codeword, DmtxMaskBit8, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, mappingRows-3, 0, codeword, DmtxMaskBit1, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, mappingRows-2, 0, codeword, DmtxMaskBit2, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, mappingRows-1, 0, codeword, DmtxMaskBit3, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 0, mappingCols-2, codeword, DmtxMaskBit4, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 0, mappingCols-1, codeword, DmtxMaskBit5, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 1, mappingCols-1, codeword, DmtxMaskBit6, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 2, mappingCols-1, codeword, DmtxMaskBit7, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 3, mappingCols-1, codeword, DmtxMaskBit8, moduleOnColor); } -static void PatternShapeSpecial4(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor) +static void patternShapeSpecial4(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor) { - PlaceModule(modules, mappingRows, mappingCols, mappingRows-1, 0, codeword, DmtxMaskBit1, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, mappingRows-1, mappingCols-1, codeword, DmtxMaskBit2, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 0, mappingCols-3, codeword, DmtxMaskBit3, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 0, mappingCols-2, codeword, DmtxMaskBit4, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 0, mappingCols-1, codeword, DmtxMaskBit5, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 1, mappingCols-3, codeword, DmtxMaskBit6, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 1, mappingCols-2, codeword, DmtxMaskBit7, moduleOnColor); - PlaceModule(modules, mappingRows, mappingCols, 1, mappingCols-1, codeword, DmtxMaskBit8, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, mappingRows-1, 0, codeword, DmtxMaskBit1, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, mappingRows-1, mappingCols-1, codeword, DmtxMaskBit2, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 0, mappingCols-3, codeword, DmtxMaskBit3, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 0, mappingCols-2, codeword, DmtxMaskBit4, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 0, mappingCols-1, codeword, DmtxMaskBit5, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 1, mappingCols-3, codeword, DmtxMaskBit6, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 1, mappingCols-2, codeword, DmtxMaskBit7, moduleOnColor); + placeModule(modules, mappingRows, mappingCols, 1, mappingCols-1, codeword, DmtxMaskBit8, moduleOnColor); } -static void PlaceModule(unsigned char *modules, int mappingRows, int mappingCols, int row, int col, unsigned char *codeword, int mask, int moduleOnColor) +static void placeModule(unsigned char *modules, int mappingRows, int mappingCols, int row, int col, unsigned char *codeword, int mask, int moduleOnColor) { if (row < 0) { diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxplacemod.hpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxplacemod.hpp index 7f68bfeb22..f468b9479f 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxplacemod.hpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxplacemod.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxplacemod.hpp // test_dm @@ -5,19 +15,19 @@ // Created by wechatcv on 2022/5/7. // -#ifndef dmtxplacemod_hpp -#define dmtxplacemod_hpp +#ifndef __ZXING_DATAMATRIX_LIBDMTX_DMTXPLACEMOD_HPP__ +#define __ZXING_DATAMATRIX_LIBDMTX_DMTXPLACEMOD_HPP__ #include namespace dmtx { -int ModulePlacementEcc200(unsigned char *modules, unsigned char *codewords, int sizeIdx, int moduleOnColor); -static void PatternShapeStandard(unsigned char *modules, int mappingRows, int mappingCols, int row, int col, unsigned char *codeword, int moduleOnColor); -static void PatternShapeSpecial1(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor); -static void PatternShapeSpecial2(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor); -static void PatternShapeSpecial3(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor); -static void PatternShapeSpecial4(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor); -static void PlaceModule(unsigned char *modules, int mappingRows, int mappingCols, int row, int col, +int modulePlacementEcc200(unsigned char *modules, unsigned char *codewords, int sizeIdx, int moduleOnColor); +static void patternShapeStandard(unsigned char *modules, int mappingRows, int mappingCols, int row, int col, unsigned char *codeword, int moduleOnColor); +static void patternShapeSpecial1(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor); +static void patternShapeSpecial2(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor); +static void patternShapeSpecial3(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor); +static void patternShapeSpecial4(unsigned char *modules, int mappingRows, int mappingCols, unsigned char *codeword, int moduleOnColor); +static void placeModule(unsigned char *modules, int mappingRows, int mappingCols, int row, int col, unsigned char *codeword, int mask, int moduleOnColor); } // namespace dmtx -#endif /* dmtxplacemod_hpp */ +#endif // __ZXING_DATAMATRIX_LIBDMTX_DMTXPLACEMOD_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxreedsol.cpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxreedsol.cpp index 4ea9af9e5e..74349b0d67 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxreedsol.cpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxreedsol.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxreedsol.cpp // test_dm @@ -71,7 +81,7 @@ static DmtxByte antilog301[] = #undef CHKPASS #define CHKPASS { if (passFail == DmtxFail) return DmtxFail; } -unsigned int RsDecode(unsigned char *code, int sizeIdx, int fix) +unsigned int rsDecode(unsigned char *code, int sizeIdx, int fix) { (void)fix; int i; @@ -124,23 +134,23 @@ unsigned int RsDecode(unsigned char *code, int sizeIdx, int fix) } /* Compute syndromes (syn) */ - error = RsComputeSyndromes(&syn, &rec, blockErrorWords); + error = rsComputeSyndromes(&syn, &rec, blockErrorWords); /* Error(s) detected: Attempt repair */ if (error) { /* Find error locator polynomial (elp) */ - repairable = RsFindErrorLocatorPoly(&elp, &syn, blockErrorWords, blockMaxCorrectable); + repairable = rsFindErrorLocatorPoly(&elp, &syn, blockErrorWords, blockMaxCorrectable); if (!repairable) return DmtxFail; /* Find error positions (loc) */ - repairable = RsFindErrorLocations(&loc, &elp); + repairable = rsFindErrorLocations(&loc, &elp); if (!repairable) return DmtxFail; /* Find error values and repair */ - RsRepairErrors(&rec, &loc, &elp, &syn); + rsRepairErrors(&rec, &loc, &elp, &syn); } /* @@ -169,7 +179,7 @@ unsigned int RsDecode(unsigned char *code, int sizeIdx, int fix) #undef CHKPASS #define CHKPASS { if (passFail == DmtxFail) return DmtxTrue; } -static DmtxBoolean RsComputeSyndromes(DmtxByteList *syn, const DmtxByteList *rec, int blockErrorWords) +static DmtxBoolean rsComputeSyndromes(DmtxByteList *syn, const DmtxByteList *rec, int blockErrorWords) { int i, j; unsigned int passFail; @@ -194,7 +204,7 @@ static DmtxBoolean RsComputeSyndromes(DmtxByteList *syn, const DmtxByteList *rec #undef CHKPASS #define CHKPASS { if (passFail == DmtxFail) return DmtxFalse; } -static DmtxBoolean RsFindErrorLocatorPoly(DmtxByteList *elpOut, const DmtxByteList *syn, int errorWordCount, int maxCorrectable) +static DmtxBoolean rsFindErrorLocatorPoly(DmtxByteList *elpOut, const DmtxByteList *syn, int errorWordCount, int maxCorrectable) { int i, iNext, j; int m, mCmp, lambda; @@ -267,7 +277,7 @@ static DmtxBoolean RsFindErrorLocatorPoly(DmtxByteList *elpOut, const DmtxByteLi #undef CHKPASS #define CHKPASS { if (passFail == DmtxFail) return DmtxFalse; } -static DmtxBoolean RsFindErrorLocations(DmtxByteList *loc, const DmtxByteList *elp) +static DmtxBoolean rsFindErrorLocations(DmtxByteList *loc, const DmtxByteList *elp) { int i, j; int lambda = elp->length - 1; @@ -297,7 +307,7 @@ static DmtxBoolean RsFindErrorLocations(DmtxByteList *loc, const DmtxByteList *e #undef CHKPASS #define CHKPASS { if (passFail == DmtxFail) return DmtxFail; } -static unsigned int RsRepairErrors(DmtxByteList *rec, const DmtxByteList *loc, const DmtxByteList *elp, const DmtxByteList *syn) +static unsigned int rsRepairErrors(DmtxByteList *rec, const DmtxByteList *loc, const DmtxByteList *elp, const DmtxByteList *syn) { int i, j, q; int lambda = elp->length - 1; diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxreedsol.hpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxreedsol.hpp index 5312b28f6d..bd67c29e37 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxreedsol.hpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxreedsol.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxreedsol.hpp // test_dm @@ -5,21 +15,21 @@ // Created by wechatcv on 2022/5/7. // -#ifndef dmtxreedsol_hpp -#define dmtxreedsol_hpp +#ifndef __ZXING_DATAMATRIX_LIBDMTX_DMTXREEDSOL_HPP__ +#define __ZXING_DATAMATRIX_LIBDMTX_DMTXREEDSOL_HPP__ #include #include "common.hpp" namespace dmtx { -unsigned int RsDecode(unsigned char *code, int sizeIdx, int fix); +unsigned int rsDecode(unsigned char *code, int sizeIdx, int fix); -static DmtxBoolean RsComputeSyndromes(DmtxByteList *syn, const DmtxByteList *rec, int blockErrorWords); -static DmtxBoolean RsFindErrorLocatorPoly(DmtxByteList *elp, const DmtxByteList *syn, int errorWordCount, int maxCorrectable); -static DmtxBoolean RsFindErrorLocations(DmtxByteList *loc, const DmtxByteList *elp); -static unsigned int RsRepairErrors(DmtxByteList *rec, const DmtxByteList *loc, const DmtxByteList *elp, const DmtxByteList *syn); +static DmtxBoolean rsComputeSyndromes(DmtxByteList *syn, const DmtxByteList *rec, int blockErrorWords); +static DmtxBoolean rsFindErrorLocatorPoly(DmtxByteList *elp, const DmtxByteList *syn, int errorWordCount, int maxCorrectable); +static DmtxBoolean rsFindErrorLocations(DmtxByteList *loc, const DmtxByteList *elp); +static unsigned int rsRepairErrors(DmtxByteList *rec, const DmtxByteList *loc, const DmtxByteList *elp, const DmtxByteList *syn); } // namespace dmtx -#endif /* dmtxreedsol_hpp */ +#endif // __ZXING_DATAMATRIX_LIBDMTX_DMTXREEDSOL_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxsymbol.cpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxsymbol.cpp index 8cd1ca3390..a48071023c 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxsymbol.cpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxsymbol.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxsymbol.cpp // test_dm diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxsymbol.hpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxsymbol.hpp index 24ab48e4bb..f0159aefee 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxsymbol.hpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxsymbol.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxsymbol.hpp // test_dm @@ -5,8 +15,8 @@ // Created by wechatcv on 2022/5/7. // -#ifndef dmtxsymbol_hpp -#define dmtxsymbol_hpp +#ifndef __ZXING_DATAMATRIX_LIBDMTX_DMTXSYMBOL_HPP__ +#define __ZXING_DATAMATRIX_LIBDMTX_DMTXSYMBOL_HPP__ #include @@ -17,4 +27,4 @@ int dmtxGetBlockDataSize(int sizeIdx, int blockIdx); int getSizeIdxFromSymbolDimension(int rows, int cols); int dmtxGetSymbolAttribute(int attribute, int sizeIdx); } // namespace dmtx -#endif /* dmtxsymbol_hpp */ +#endif // __ZXING_DATAMATRIX_LIBDMTX_DMTXSYMBOL_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxvector2.cpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxvector2.cpp index dc8aeb95a2..3c4d90d90c 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxvector2.cpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxvector2.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxvector2.cpp // test_dm diff --git a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxvector2.hpp b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxvector2.hpp index c867edb798..64f3c4cd5b 100644 --- a/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxvector2.hpp +++ b/modules/objdetect/src/zxing/datamatrix/libdmtx/dmtxvector2.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // // dmtxvector2.hpp // test_dm @@ -5,8 +15,8 @@ // Created by wechatcv on 2022/5/5. // -#ifndef dmtxvector2_hpp -#define dmtxvector2_hpp +#ifndef __ZXING_DATAMATRIX_LIBDMTX_DMTXVECTOR2_HPP__ +#define __ZXING_DATAMATRIX_LIBDMTX_DMTXVECTOR2_HPP__ #include #include "common.hpp" @@ -29,4 +39,4 @@ unsigned int dmtxPointAlongRay2(DmtxVector2 *point, const DmtxRay2 *r, double t) } // namespace dmtx -#endif /* dmtxvector2_hpp */ +#endif // __ZXING_DATAMATRIX_LIBDMTX_DMTXVECTOR2_HPP__ diff --git a/modules/objdetect/src/zxing/datamatrix/version.cpp b/modules/objdetect/src/zxing/datamatrix/version.cpp index 642ed88e41..b6f6b2d1dd 100644 --- a/modules/objdetect/src/zxing/datamatrix/version.cpp +++ b/modules/objdetect/src/zxing/datamatrix/version.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * Version.cpp * zxing diff --git a/modules/objdetect/src/zxing/datamatrix/version.hpp b/modules/objdetect/src/zxing/datamatrix/version.hpp index ca09ef77d5..0632513e7b 100644 --- a/modules/objdetect/src/zxing/datamatrix/version.hpp +++ b/modules/objdetect/src/zxing/datamatrix/version.hpp @@ -1,5 +1,15 @@ -#ifndef __VERSION_H_DM__ -#define __VERSION_H_DM__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_DATAMATRIX_VERSION_HPP__ +#define __ZXING_DATAMATRIX_VERSION_HPP__ /* * Version.hpp @@ -85,4 +95,4 @@ private: } // namespace datamatrix } // namespace zxing -#endif // __VERSION_H__ +#endif // __ZXING_DATAMATRIX_VERSION_HPP__ diff --git a/modules/objdetect/src/zxing/decode_hints.cpp b/modules/objdetect/src/zxing/decode_hints.cpp index a3d6f93d51..ccd846dc80 100644 --- a/modules/objdetect/src/zxing/decode_hints.cpp +++ b/modules/objdetect/src/zxing/decode_hints.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * DecodeHintType.cpp diff --git a/modules/objdetect/src/zxing/decode_hints.hpp b/modules/objdetect/src/zxing/decode_hints.hpp index 872641d74d..93289fea67 100644 --- a/modules/objdetect/src/zxing/decode_hints.hpp +++ b/modules/objdetect/src/zxing/decode_hints.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __DECODEHINTS_H_ -#define __DECODEHINTS_H_ +#ifndef __ZXING_DECODE_HINTS_HPP__ +#define __ZXING_DECODE_HINTS_HPP__ /* * DecodeHintType.hpp * zxing @@ -144,4 +154,4 @@ public: } // namespace zxing -#endif +#endif // __ZXING_DECODE_HINTS_HPP__ diff --git a/modules/objdetect/src/zxing/error_handler.cpp b/modules/objdetect/src/zxing/error_handler.cpp index 6a669a6eff..71c2a5132a 100644 --- a/modules/objdetect/src/zxing/error_handler.cpp +++ b/modules/objdetect/src/zxing/error_handler.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // ===================================================================================== // // Filename: ErrorHandler.cpp @@ -23,60 +33,60 @@ using namespace zxing; ErrorHandler::ErrorHandler() :err_code_(0), err_msg_("") { - Init(); + init(); } ErrorHandler::ErrorHandler(const char * err_msg) :err_code_(-1), err_msg_(err_msg) { - Init(); + init(); } ErrorHandler::ErrorHandler(std::string & err_msg) :err_code_(-1), err_msg_(err_msg) { - Init(); + init(); } ErrorHandler::ErrorHandler(int err_code) :err_code_(err_code), err_msg_("error") { - Init(); + init(); } ErrorHandler::ErrorHandler(int err_code, const char * err_msg) :err_code_(err_code), err_msg_(err_msg) { - Init(); + init(); } ErrorHandler::ErrorHandler(const ErrorHandler & other) { - err_code_ = other.ErrCode(); - err_msg_.assign(other.ErrMsg()); - Init(); + err_code_ = other.errCode(); + err_msg_.assign(other.errMsg()); + init(); } ErrorHandler& ErrorHandler::operator=(const ErrorHandler & other) { - err_code_ = other.ErrCode(); - err_msg_.assign(other.ErrMsg()); - Init(); + err_code_ = other.errCode(); + err_msg_.assign(other.errMsg()); + init(); return *this; } -void ErrorHandler::Init() +void ErrorHandler::init() { handler_type_ = KErrorHandler; } -void ErrorHandler::Reset() +void ErrorHandler::reset() { err_code_ = 0; err_msg_.assign(""); } -void ErrorHandler::PrintInfo() +void ErrorHandler::printInfo() { printf("handler_tpye %d, error code %d, errmsg %s\n", handler_type_, err_code_, err_msg_.c_str()); } diff --git a/modules/objdetect/src/zxing/error_handler.hpp b/modules/objdetect/src/zxing/error_handler.hpp index 019ba02462..b3ade6305c 100644 --- a/modules/objdetect/src/zxing/error_handler.hpp +++ b/modules/objdetect/src/zxing/error_handler.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // ===================================================================================== // // Filename: ErrorHandler.hpp @@ -14,8 +24,8 @@ // // ===================================================================================== -#ifndef __ERRORHANDLER_H__ -#define __ERRORHANDLER_H__ +#ifndef __ZXING_ERROR_HANDLER_HPP__ +#define __ZXING_ERROR_HANDLER_HPP__ #include @@ -45,17 +55,17 @@ public: virtual ~ErrorHandler() {}; - virtual inline int ErrCode() const {return err_code_;} - virtual inline const std::string & ErrMsg() const {return err_msg_;} - virtual inline int HandlerType() const {return handler_type_;} + virtual inline int errCode() const {return err_code_;} + virtual inline const std::string & errMsg() const {return err_msg_;} + virtual inline int handlerType() const {return handler_type_;} - virtual void Init(); + virtual void init(); ErrorHandler(const ErrorHandler & other); ErrorHandler& operator=(const ErrorHandler & other); - virtual void PrintInfo(); - virtual void Reset(); + virtual void printInfo(); + virtual void reset(); protected: int handler_type_; @@ -69,14 +79,14 @@ private: #define DECLARE_ERROR_HANDLER(__HANDLER__) \ class __HANDLER__##ErrorHandler : public ErrorHandler{ \ public: \ -__HANDLER__##ErrorHandler() : ErrorHandler() { Init();}; \ -__HANDLER__##ErrorHandler(std::string & err_msg) : ErrorHandler(err_msg) { Init();}; \ -__HANDLER__##ErrorHandler(const char * err_msg) : ErrorHandler(err_msg) { Init();}; \ -__HANDLER__##ErrorHandler(int err_code) : ErrorHandler(err_code) { Init();}; \ -__HANDLER__##ErrorHandler(int err_code, std::string & err_msg) : ErrorHandler(err_code, err_msg) { Init();}; \ -__HANDLER__##ErrorHandler(int err_code, const char * err_msg) : ErrorHandler(err_code, err_msg) {Init();}; \ -__HANDLER__##ErrorHandler(const ErrorHandler & other) : ErrorHandler(other) { Init();}; \ -void Init(){ \ +__HANDLER__##ErrorHandler() : ErrorHandler() { init();}; \ +__HANDLER__##ErrorHandler(std::string & err_msg) : ErrorHandler(err_msg) { init();}; \ +__HANDLER__##ErrorHandler(const char * err_msg) : ErrorHandler(err_msg) { init();}; \ +__HANDLER__##ErrorHandler(int err_code) : ErrorHandler(err_code) { init();}; \ +__HANDLER__##ErrorHandler(int err_code, std::string & err_msg) : ErrorHandler(err_code, err_msg) { init();}; \ +__HANDLER__##ErrorHandler(int err_code, const char * err_msg) : ErrorHandler(err_code, err_msg) {init();}; \ +__HANDLER__##ErrorHandler(const ErrorHandler & other) : ErrorHandler(other) { init();}; \ +void init(){ \ handler_type_ = KErrorHandler_##__HANDLER__; \ } \ }; @@ -94,4 +104,4 @@ DECLARE_ERROR_HANDLER(IllegalState) } // namespace zxing -#endif // __##ERRORHANDLER_H__ +#endif // __ZXING_ERROR_HANDLER_HPP__ diff --git a/modules/objdetect/src/zxing/exception.cpp b/modules/objdetect/src/zxing/exception.cpp index c49df8a5de..a5ff182579 100644 --- a/modules/objdetect/src/zxing/exception.cpp +++ b/modules/objdetect/src/zxing/exception.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Exception.cpp diff --git a/modules/objdetect/src/zxing/exception.hpp b/modules/objdetect/src/zxing/exception.hpp index b126816d00..69eae29511 100644 --- a/modules/objdetect/src/zxing/exception.hpp +++ b/modules/objdetect/src/zxing/exception.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __EXCEPTION_H__ -#define __EXCEPTION_H__ +#ifndef __ZXING_EXCEPTION_HPP__ +#define __ZXING_EXCEPTION_HPP__ /* * Exception.hpp @@ -48,4 +58,4 @@ private: } // namespace zxing -#endif // __EXCEPTION_H__ +#endif // __ZXING_EXCEPTION_HPP__ diff --git a/modules/objdetect/src/zxing/format_exception.cpp b/modules/objdetect/src/zxing/format_exception.cpp index 4e752b3689..e663d84764 100644 --- a/modules/objdetect/src/zxing/format_exception.cpp +++ b/modules/objdetect/src/zxing/format_exception.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * FormatException.cpp diff --git a/modules/objdetect/src/zxing/format_exception.hpp b/modules/objdetect/src/zxing/format_exception.hpp index 8f6ca0ae1a..59567dcbbb 100644 --- a/modules/objdetect/src/zxing/format_exception.hpp +++ b/modules/objdetect/src/zxing/format_exception.hpp @@ -1,5 +1,15 @@ -#ifndef __FORMAT_EXCEPTION_H__ -#define __FORMAT_EXCEPTION_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_FORMAT_EXCEPTION_HPP__ +#define __ZXING_FORMAT_EXCEPTION_HPP__ /* * FormatException.hpp @@ -34,4 +44,4 @@ public: }; } // namespace zxing -#endif // __FORMAT_EXCEPTION_H__ +#endif // __ZXING_FORMAT_EXCEPTION_HPP__ diff --git a/modules/objdetect/src/zxing/illegal_state_exception.hpp b/modules/objdetect/src/zxing/illegal_state_exception.hpp index 72d9fe3b4d..1bb2e9e12f 100644 --- a/modules/objdetect/src/zxing/illegal_state_exception.hpp +++ b/modules/objdetect/src/zxing/illegal_state_exception.hpp @@ -1,7 +1,17 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __ILLEGAL_STATE_EXCEPTION_H__ -#define __ILLEGAL_STATE_EXCEPTION_H__ +#ifndef __ZXING_ILLEGAL_STATE_EXCEPTION_HPP__ +#define __ZXING_ILLEGAL_STATE_EXCEPTION_HPP__ /* * Copyright 20011 ZXing authors @@ -32,4 +42,4 @@ public: } -#endif // __ILLEGAL_STATE_EXCEPTION_H__ +#endif // __ZXING_ILLEGAL_STATE_EXCEPTION_HPP__ diff --git a/modules/objdetect/src/zxing/inverted_luminance_source.cpp b/modules/objdetect/src/zxing/inverted_luminance_source.cpp index 5acd060662..a4ef24e41a 100644 --- a/modules/objdetect/src/zxing/inverted_luminance_source.cpp +++ b/modules/objdetect/src/zxing/inverted_luminance_source.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2013 ZXing authors All rights reserved. @@ -32,7 +42,7 @@ InvertedLuminanceSource::InvertedLuminanceSource(Ref const& del ArrayRef InvertedLuminanceSource::getRow(int y, ArrayRef row, ErrorHandler & err_handler) const { row = delegate->getRow(y, row, err_handler); - if (err_handler.ErrCode()) return ArrayRef(); + if (err_handler.errCode()) return ArrayRef(); int width = getWidth(); for (int i = 0; i < width; i++) { row[i] = static_cast(255 - (row[i] & 0xFF)); diff --git a/modules/objdetect/src/zxing/inverted_luminance_source.hpp b/modules/objdetect/src/zxing/inverted_luminance_source.hpp index 8d5fa97869..551a42b5a4 100644 --- a/modules/objdetect/src/zxing/inverted_luminance_source.hpp +++ b/modules/objdetect/src/zxing/inverted_luminance_source.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __INVERTEDLUMINANCESOURCE_H__ -#define __INVERTEDLUMINANCESOURCE_H__ +#ifndef __ZXING_INVERTED_LUMINANCE_SOURCE_HPP__ +#define __ZXING_INVERTED_LUMINANCE_SOURCE_HPP__ /* * Copyright 2013 ZXing authors All rights reserved. * @@ -50,4 +60,4 @@ public: } // namespace zxing -#endif /* INVERTEDLUMINANCESOURCE_H_ */ +#endif // __ZXING_INVERTED_LUMINANCE_SOURCE_HPP__ diff --git a/modules/objdetect/src/zxing/luminance_source.cpp b/modules/objdetect/src/zxing/luminance_source.cpp index 7031aa84e0..a92ac8f4b5 100644 --- a/modules/objdetect/src/zxing/luminance_source.cpp +++ b/modules/objdetect/src/zxing/luminance_source.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * LuminanceSource.cpp @@ -51,9 +61,9 @@ LuminanceSource::operator std::string() const { std::ostringstream oss; zxing::ErrorHandler err_handler; for (int y = 0; y < getHeight(); y++) { - err_handler.Reset(); + err_handler.reset(); row = getRow(y, row, err_handler); - if (err_handler.ErrCode()) continue; + if (err_handler.errCode()) continue; for (int x = 0; x < getWidth(); x++) { int luminance = row[x] & 0xFF; char c; diff --git a/modules/objdetect/src/zxing/luminance_source.hpp b/modules/objdetect/src/zxing/luminance_source.hpp index ba49d0f946..1f5f668366 100644 --- a/modules/objdetect/src/zxing/luminance_source.hpp +++ b/modules/objdetect/src/zxing/luminance_source.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __LUMINANCESOURCE_H__ -#define __LUMINANCESOURCE_H__ +#ifndef __ZXING_LUMINANCE_SOURCE_HPP__ +#define __ZXING_LUMINANCE_SOURCE_HPP__ /* * LuminanceSource.hpp * zxing @@ -64,4 +74,4 @@ public: } // namespace zxing -#endif /* LUMINANCESOURCE_H_ */ +#endif // __ZXING_LUMINANCE_SOURCE_HPP__ diff --git a/modules/objdetect/src/zxing/multi_format_reader.cpp b/modules/objdetect/src/zxing/multi_format_reader.cpp index e30d7afaad..1e19104bc9 100644 --- a/modules/objdetect/src/zxing/multi_format_reader.cpp +++ b/modules/objdetect/src/zxing/multi_format_reader.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2010 ZXing authors All rights reserved. @@ -23,7 +33,7 @@ #ifndef USE_QRCODE_ONLY #include "datamatrix/data_matrix_reader.hpp" #include "pdf417/pdf417reader.hpp" -#include "oned/multi_format_one_dreader.hpp" +// #include "oned/multi_format_one_dreader.hpp" #endif #include "reader_exception.hpp" @@ -101,23 +111,23 @@ void MultiFormatReader::setHints(DecodeHints hints) { if (hints.containsFormat(BarcodeFormat::QR_CODE)) readers_.push_back(Ref(new zxing::qrcode::QRCodeReader())); - bool addOneDReader = hints.containsFormat(BarcodeFormat::UPC_E) || - hints.containsFormat(BarcodeFormat::UPC_A) || - hints.containsFormat(BarcodeFormat::UPC_E) || - hints.containsFormat(BarcodeFormat::EAN_13) || - hints.containsFormat(BarcodeFormat::EAN_8) || - hints.containsFormat(BarcodeFormat::CODABAR) || - hints.containsFormat(BarcodeFormat::CODE_39) || - hints.containsFormat(BarcodeFormat::CODE_93) || - hints.containsFormat(BarcodeFormat::CODE_128) || - hints.containsFormat(BarcodeFormat::CODE_25) || - hints.containsFormat(BarcodeFormat::ITF) || - hints.containsFormat(BarcodeFormat::RSS_14) || - hints.containsFormat(BarcodeFormat::RSS_EXPANDED); - if (addOneDReader) - { - readers_.push_back(Ref(new zxing::oned::MultiFormatOneDReader(hints))); - } + // bool addOneDReader = hints.containsFormat(BarcodeFormat::UPC_E) || + // hints.containsFormat(BarcodeFormat::UPC_A) || + // hints.containsFormat(BarcodeFormat::UPC_E) || + // hints.containsFormat(BarcodeFormat::EAN_13) || + // hints.containsFormat(BarcodeFormat::EAN_8) || + // hints.containsFormat(BarcodeFormat::CODABAR) || + // hints.containsFormat(BarcodeFormat::CODE_39) || + // hints.containsFormat(BarcodeFormat::CODE_93) || + // hints.containsFormat(BarcodeFormat::CODE_128) || + // hints.containsFormat(BarcodeFormat::CODE_25) || + // hints.containsFormat(BarcodeFormat::ITF) || + // hints.containsFormat(BarcodeFormat::RSS_14) || + // hints.containsFormat(BarcodeFormat::RSS_EXPANDED); + // if (addOneDReader) + // { + // readers_.push_back(Ref(new zxing::oned::MultiFormatOneDReader(hints))); + // } if (hints.containsFormat(BarcodeFormat::PDF_417)) { diff --git a/modules/objdetect/src/zxing/multi_format_reader.hpp b/modules/objdetect/src/zxing/multi_format_reader.hpp index 539ba4baa2..f93edfead7 100644 --- a/modules/objdetect/src/zxing/multi_format_reader.hpp +++ b/modules/objdetect/src/zxing/multi_format_reader.hpp @@ -1,5 +1,15 @@ -#ifndef __MULTI_FORMAT_READER_H__ -#define __MULTI_FORMAT_READER_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_MULTI_FORMAT_READER_HPP__ +#define __ZXING_MULTI_FORMAT_READER_HPP__ /* * MultiFormatBarcodeReader.hpp @@ -63,4 +73,4 @@ public: }; } // namespace zxing -#endif +#endif // __ZXING_MULTI_FORMAT_READER_HPP__ diff --git a/modules/objdetect/src/zxing/not_found_exception.hpp b/modules/objdetect/src/zxing/not_found_exception.hpp index 3e49251af2..425fdba5fc 100644 --- a/modules/objdetect/src/zxing/not_found_exception.hpp +++ b/modules/objdetect/src/zxing/not_found_exception.hpp @@ -1,7 +1,17 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __NOT_FOUND_EXCEPTION_H__ -#define __NOT_FOUND_EXCEPTION_H__ +#ifndef __ZXING_NOT_FOUND_EXCEPTION_HPP__ +#define __ZXING_NOT_FOUND_EXCEPTION_HPP__ /* * Copyright 20011 ZXing authors @@ -32,4 +42,4 @@ public: } -#endif // __NOT_FOUND_EXCEPTION_H__ +#endif // __ZXING_NOT_FOUND_EXCEPTION_HPP__ diff --git a/modules/objdetect/src/zxing/oned/coda_bar_reader.cpp b/modules/objdetect/src/zxing/oned/coda_bar_reader.cpp deleted file mode 100644 index b5f1f2c8cc..0000000000 --- a/modules/objdetect/src/zxing/oned/coda_bar_reader.cpp +++ /dev/null @@ -1,339 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../zxing.hpp" -#include "coda_bar_reader.hpp" -#include "one_dresult_point.hpp" -#include "../common/array.hpp" -#include "../reader_exception.hpp" -#include "../not_found_exception.hpp" -#include "../format_exception.hpp" -#include "../checksum_exception.hpp" -#include "one_dconstant.hpp" -#include -#include - -using std::vector; -using std::string; -using zxing::NotFoundException; -using zxing::FormatException; -using zxing::ChecksumException; -using zxing::Ref; -using zxing::Result; -using zxing::oned::CodaBarReader; - -// VC++ -using zxing::BitArray; - -using namespace zxing; -using namespace oned; -using namespace zxing::oned::constant::CodaBar; - -// These values are critical for determining how permissive the decoding -// will be. All stripe sizes must be within the window these define, as -// compared to the average stripe size. -const int CodaBarReader::MAX_ACCEPTABLE = -static_cast (PATTERN_MATCH_RESULT_SCALE_FACTOR * 2.0f); -const int CodaBarReader::PADDING = -static_cast (PATTERN_MATCH_RESULT_SCALE_FACTOR * 1.5f); - -CodaBarReader::CodaBarReader() -: counters(80, 0), counterLength(0) {} - - -Ref CodaBarReader::decodeRow(int rowNumber, Ref row) { - { - int size = counters.size(); - counters.resize(0); - counters.resize(size); - } - - setCounters(row); - int startOffset = findStartPattern(); - - if (startOffset < 0) - { - return Ref(NULL); - } - - int nextStart = startOffset; - - decodeRowResult.clear(); - do { - int charOffset = toNarrowWidePattern(nextStart); - if (charOffset == -1) - { - return Ref(NULL); - } - // Hack: We store the position in the alphabet table into a - // StringBuilder, so that we can access the decoded patterns in - // validatePattern. We'll translate to the actual characters later. - decodeRowResult.append(1, static_cast(charOffset)); - nextStart += 8; - // Stop as soon as we see the end character. - if (decodeRowResult.length() > 1 && - arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) - { - break; - } - } while (nextStart < counterLength); // no fixed end pattern so keep on reading while data is available - - // Look for whitespace after pattern: - int trailingWhitespace = counters[nextStart - 1]; - int lastPatternSize = 0; - for (int i = -8; i < -1; i++) { - lastPatternSize += counters[nextStart + i]; - } - - // We need to see whitespace equal to 50% of the last pattern size, - // otherwise this is probably a false positive. The exception is if we are - // at the end of the row. (I.e. the barcode barely fits.) - if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) - { - return Ref(NULL); - } - - ErrorHandler err_handler; - validatePattern(startOffset, err_handler); - if (err_handler.ErrCode()) return Ref(NULL); - - // Translate character table offsets to actual characters. - for (size_t i = 0; i < decodeRowResult.length(); i++) { - decodeRowResult[i] = ALPHABET[static_cast(decodeRowResult[i])]; - } - // Ensure a valid start and end character - char startchar = decodeRowResult[0]; - if (!arrayContains(STARTEND_ENCODING, startchar)) - { - return Ref(NULL); - } - char endchar = decodeRowResult[decodeRowResult.length() - 1]; - if (!arrayContains(STARTEND_ENCODING, endchar)) - { - return Ref(NULL); - } - - // remove stop/start characters character and check if a long enough string is contained - if (static_cast(decodeRowResult.length()) <= MIN_CHARACTER_LENGTH) { - // Almost surely a false positive (start + stop + at least 1 character) - return Ref(NULL); - } - - decodeRowResult.erase(decodeRowResult.length() - 1, 1); - decodeRowResult.erase(0, 1); - - int runningCount = 0; - for (int i = 0; i < startOffset; i++) { - runningCount += counters[i]; - } - float left = static_cast(runningCount); - for (int i = startOffset; i < nextStart - 1; i++) { - runningCount += counters[i]; - } - float right = static_cast(runningCount); - - ArrayRef< Ref > resultPoints(2); - resultPoints[0] = - Ref(new OneDResultPoint(left, static_cast(rowNumber))); - resultPoints[1] = - Ref(new OneDResultPoint(right, static_cast(rowNumber))); - - return Ref(new Result(Ref(new String(decodeRowResult)), - ArrayRef(), - resultPoints, - BarcodeFormat::CODABAR)); -} - -void CodaBarReader::validatePattern(int start, ErrorHandler & err_handler) { - // First, sum up the total size of our four categories of stripe sizes; - vector sizes (4, 0); - vector counts(4, 0); - int end = decodeRowResult.length() - 1; - - // We break out of this loop in the middle, in order to handle - // inter-character spaces properly. - int pos = start; - for (int i = 0; true; i++) { - int pattern = CHARACTER_ENCODINGS[static_cast(decodeRowResult[i])]; - for (int j = 6; j >= 0; j--) { - // Even j = bars, while odd j = spaces. Categories 2 and 3 are for - // long stripes, while 0 and 1 are for short stripes. - int category = (j & 1) + (pattern & 1) * 2; - sizes[category] += counters[pos + j]; - counts[category]++; - pattern >>= 1; - } - if (i >= end) { - break; - } - // We ignore the inter-character space - it could be of any size. - pos += 8; - } - - // Calculate our allowable size thresholds using fixed-point math. - vector maxes (4, 0); - vector mins (4, 0); - // Define the threshold of acceptability to be the midpoint between the - // average small stripe and the average large stripe. No stripe lengths - // should be on the "wrong" side of that line. - for (int i = 0; i < 2; i++) { - mins[i] = 0; // Accept arbitrarily small "short" stripes. - mins[i + 2] = ((sizes[i] << INTEGER_MATH_SHIFT) / counts[i] + - (sizes[i + 2] << INTEGER_MATH_SHIFT) / counts[i + 2]) >> 1; - maxes[i] = mins[i + 2]; - maxes[i + 2] = (sizes[i + 2] * MAX_ACCEPTABLE + PADDING) / counts[i + 2]; - } - - // Now verify that all of the stripes are within the thresholds. - pos = start; - for (int i = 0; true; i++) { - int pattern = CHARACTER_ENCODINGS[static_cast(decodeRowResult[i])]; - for (int j = 6; j >= 0; j--) { - // Even j = bars, while odd j = spaces. Categories 2 and 3 are for - // long stripes, while 0 and 1 are for short stripes. - int category = (j & 1) + (pattern & 1) * 2; - int size = counters[pos + j] << INTEGER_MATH_SHIFT; - if (size < mins[category] || size > maxes[category]) - { - err_handler = NotFoundErrorHandler(-1); - return; - } - pattern >>= 1; - } - if (i >= end) - { - break; - } - pos += 8; - } -} - -/** - * Records the size of all runs of white and black pixels, starting with white. - * This is just like recordPattern, except it records all the counters, and - * uses our builtin "counters" member for storage. - * @param row row to count from - */ -void CodaBarReader::setCounters(Ref row) { - if (static_cast(_onedReaderData->all_counters.size()) != row->getSize()) - recordAllPattern(row, _onedReaderData); - counters.resize(0); - counterLength = 0; - - int i=_onedReaderData->first_is_white ? 0:1; - for (; i < _onedReaderData->counter_size; i++){ - counters.push_back(_onedReaderData->all_counters[i]); - counterLength++; - } -} - -void CodaBarReader::counterAppend(int e) { - if (counterLength < static_cast(counters.size())) - { - counters[counterLength] = e; - } - else - { - counters.push_back(e); - } - counterLength++; -} - -int CodaBarReader::findStartPattern() { - for (int i = 1; i < counterLength; i += 2) { - int charOffset = toNarrowWidePattern(i); - if (charOffset != -1 && arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) - { - // Look for whitespace before start pattern, >= 50% of width of start pattern - // We make an exception if the whitespace is the first element. - int patternSize = 0; - for (int j = i; j < i + 7; j++) { - patternSize += counters[j]; - } - if (i == 1 || counters[i-1] >= patternSize / 2) - { - return i; - } - } - } - - return -1; -} - -bool CodaBarReader::arrayContains(char const array[], char key) { - return strchr(array, key) != 0; -} - - -int CodaBarReader::toNarrowWidePattern(int position) { - int end = position + 7; - if (end >= counterLength) - { - return -1; - } - - vector& theCounters = counters; - - int maxBar = 0; - int minBar = std::numeric_limits::max(); - for (int j = position; j < end; j += 2) { - int currentCounter = theCounters[j]; - if (currentCounter < minBar) - { - minBar = currentCounter; - } - if (currentCounter > maxBar) - { - maxBar = currentCounter; - } - } - int thresholdBar = (minBar + maxBar) / 2; - - int maxSpace = 0; - int minSpace = std::numeric_limits::max(); - for (int j = position + 1; j < end; j += 2) { - int currentCounter = theCounters[j]; - if (currentCounter < minSpace) - { - minSpace = currentCounter; - } - if (currentCounter > maxSpace) - { - maxSpace = currentCounter; - } - } - int thresholdSpace = (minSpace + maxSpace) / 2; - - int bitmask = 1 << 7; - int pattern = 0; - for (int i = 0; i < 7; i++) { - int threshold = (i & 1) == 0 ? thresholdBar : thresholdSpace; - bitmask >>= 1; - if (theCounters[position + i] > threshold) - { - pattern |= bitmask; - } - } - - for (int i = 0; i < ZXING_ARRAY_LEN(CHARACTER_ENCODINGS); i++) { - if (CHARACTER_ENCODINGS[i] == pattern) - { - return i; - } - } - return -1; -} diff --git a/modules/objdetect/src/zxing/oned/coda_bar_reader.hpp b/modules/objdetect/src/zxing/oned/coda_bar_reader.hpp deleted file mode 100644 index a0d2f770cb..0000000000 --- a/modules/objdetect/src/zxing/oned/coda_bar_reader.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __CODA_BAR_READER_H__ -#define __CODA_BAR_READER_H__ -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "one_dreader.hpp" -#include "../common/bit_array.hpp" -#include "../result.hpp" -#include "../error_handler.hpp" - -namespace zxing { -namespace oned { - -class CodaBarReader : public OneDReader { -private: - static const int MAX_ACCEPTABLE; - static const int PADDING; - - // Keep some instance variables to avoid reallocations - std::string decodeRowResult; - std::vector counters; - int counterLength; - -public: - CodaBarReader(); - - Ref decodeRow(int rowNumber, Ref row); - - void validatePattern(int start, ErrorHandler & err_handler); - - static bool arrayContains(char const array[], char key); - -private: - void setCounters(Ref row); - void counterAppend(int e); - int findStartPattern(); - - int toNarrowWidePattern(int position); -}; - -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/code128reader.cpp b/modules/objdetect/src/zxing/oned/code128reader.cpp deleted file mode 100644 index a19c62f0fd..0000000000 --- a/modules/objdetect/src/zxing/oned/code128reader.cpp +++ /dev/null @@ -1,503 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../zxing.hpp" -#include "code128reader.hpp" -#include "one_dresult_point.hpp" -#include "../common/array.hpp" -#include "../reader_exception.hpp" -#include "../not_found_exception.hpp" -#include "../format_exception.hpp" -#include "../checksum_exception.hpp" -#include "one_dconstant.hpp" -#include "../error_handler.hpp" - -// Add charset for Code128 -#include "../common/string_utils.hpp" - -#include -#include -#include - -#include - -using std::vector; -using std::string; -using zxing::NotFoundException; -using zxing::FormatException; -using zxing::ChecksumException; -using zxing::Ref; -using zxing::Result; -using zxing::oned::Code128Reader; - -using namespace zxing::oned::constant::Code128; - -// Add charset for Code128 -using namespace zxing::common; - -// VC++ -using zxing::BitArray; - -const int Code128Reader::MAX_AVG_VARIANCE = static_cast(PATTERN_MATCH_RESULT_SCALE_FACTOR * 250/1000); -// const int Code128Reader::MAX_INDIVIDUAL_VARIANCE = static_cast(PATTERN_MATCH_RESULT_SCALE_FACTOR * 700/1000); -const int Code128Reader::MAX_INDIVIDUAL_VARIANCE = static_cast(PATTERN_MATCH_RESULT_SCALE_FACTOR * 840/1000); - -Code128Reader::Code128Reader(){ -} - -vector Code128Reader::findStartPattern(Ref row, ONED_READER_DATA* onedReaderData){ - vector counters(6, 0); - - int counterOffset = onedReaderData->first_is_white ? 1 : 0; - - // int counterPosition = 0; - int patternStart = onedReaderData->first_is_white ? onedReaderData->all_counters[0]: 0; - - for (int c = counterOffset; c < onedReaderData->counter_size-5; c+=2){ - int i = patternStart; - for (int ii = 0; ii < 6; ii++){ - counters[ii] = onedReaderData->all_counters[c+ii]; - i+=counters[ii]; - } - - int bestVariance = MAX_AVG_VARIANCE; - int bestMatch = -1; - for (int startCode = CODE_START_A; startCode <= CODE_START_C; startCode++) { - int variance = patternMatchVariance(counters, CODE_PATTERNS[startCode], MAX_INDIVIDUAL_VARIANCE); - if (variance < bestVariance) - { - bestVariance = variance; - bestMatch = startCode; - } - } - - // Look for whitespace before start pattern, >= 50% of width of start pattern - ErrorHandler err_handler; - if (bestMatch >= 0 && - row->isRange((std::max)(0, patternStart - (i - patternStart) / 2), patternStart, false, err_handler)) { - if (err_handler.ErrCode()) return vector(0); - vector resultValue(3, 0); - resultValue[0] = patternStart; - resultValue[1] = i; - resultValue[2] = bestMatch; - - return resultValue; - } - patternStart += counters[0]+counters[1]; - } - - return vector(0); -} - -int Code128Reader::decodeCode(Ref row, vector& counters, int rowOffset, ONED_READER_DATA* onedReaderData) { - bool rp = recordPattern(row, rowOffset, counters, onedReaderData); - - if (rp == false) - { - return -1; - } - - int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept - int bestMatch = -1; - for (int d = 0; d < CODE_PATTERNS_LENGTH; d++) { - int const* const pattern = CODE_PATTERNS[d]; - int variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE); - if (variance < bestVariance) { - bestVariance = variance; - bestMatch = d; - } - } - // TODO(sofiawu) We're overlooking the fact that the STOP pattern has 7 values, not 6. - if (bestMatch >= 0) - { - return bestMatch; - } - else - { - return -1; - } -} - - -Ref Code128Reader::decodeRow(int rowNumber, Ref row) { - bool convertFNC1 = false; - vector startPatternInfo(findStartPattern(row, _onedReaderData)); - - if (startPatternInfo.size() == 0) - { - return Ref(NULL); - } - - int startCode = startPatternInfo[2]; - int codeSet; - switch (startCode) { - case CODE_START_A: - codeSet = CODE_CODE_A; - break; - case CODE_START_B: - codeSet = CODE_CODE_B; - break; - case CODE_START_C: - codeSet = CODE_CODE_C; - break; - default: - return Ref(NULL); - } - - bool done = false; - bool isNextShifted = false; - - string result; - vector rawCodes(20, 0); - rawCodes.push_back(static_cast(startCode)); - - int lastStart = startPatternInfo[0]; - int nextStart = startPatternInfo[1]; - vector counters(6, 0); - - int lastCode = 0; - int code = 0; - int checksumTotal = startCode; - int multiplier = 0; - bool lastCharacterWasPrintable = true; - - // ZXing Patch 2992 - bool upperMode = false; - bool shiftUpperMode = false; - - while (!done) { - bool unshift = isNextShifted; - isNextShifted = false; - - // Save off last code - lastCode = code; - - code = decodeCode(row, counters, nextStart, _onedReaderData); - - if (code < 0) - { - return Ref(NULL); - } - - // Remember whether the last code was printable or not (excluding CODE_STOP) - if (code != CODE_STOP) - { - lastCharacterWasPrintable = true; - } - - // Add to checksum computation (if not CODE_STOP of course) - if (code != CODE_STOP) - { - multiplier++; - checksumTotal += multiplier * code; - } - - // Advance to where the next code will to start - lastStart = nextStart; - for (int i = 0, e = counters.size(); i < e; i++) { - nextStart += counters[i]; - } - - // Take care of illegal start codes - switch (code) { - case CODE_START_A: - case CODE_START_B: - case CODE_START_C: - return Ref(NULL); - } - - switch (codeSet) { - case CODE_CODE_A: - if (code < 64) - { - // Patch 2992 : Valiantliu - if (shiftUpperMode == upperMode) - { - result.append(1, static_cast(' ' + code)); - } - else - { - result.append(1, static_cast(' ' + code + 128)); - } - shiftUpperMode = false; - } - else if (code < 96) - { - if (shiftUpperMode == upperMode) - { - result.append(1, static_cast(code - 64)); - } - else - { - result.append(1, static_cast(code + 64)); - } - shiftUpperMode = false; - } - else - { - // Don't let CODE_STOP, which always appears, affect whether whether we think the - // last code was printable or not. - if (code != CODE_STOP) - { - lastCharacterWasPrintable = false; - } - switch (code) { - case CODE_FNC_1: - if (convertFNC1) - { - if (result.length() == 0) - { - // GS1 specification 5.4.3.7. and 5.4.6.4. If the first char after the start code - // is FNC1 then this is GS1-128. We add the symbology identifier. - result.append("]C1"); - } - else - { - // GS1 specification 5.4.7.5. Every subsequent FNC1 is returned as ASCII 29 (GS) - result.append(1, static_cast(29)); - } - } - break; - case CODE_FNC_2: - case CODE_FNC_3: - break; - // Patch 2992 : Valiantliu - case CODE_FNC_4_A: - if (!upperMode && shiftUpperMode) - { - upperMode = true; - shiftUpperMode = false; - } - else if (upperMode && shiftUpperMode) - { - upperMode = false; - shiftUpperMode = false; - } - else - { - shiftUpperMode = true; - } - break; - case CODE_SHIFT: - isNextShifted = true; - codeSet = CODE_CODE_B; - break; - case CODE_CODE_B: - codeSet = CODE_CODE_B; - break; - case CODE_CODE_C: - codeSet = CODE_CODE_C; - break; - case CODE_STOP: - done = true; - break; - } - } - break; - case CODE_CODE_B: - if (code < 96) - { - if (shiftUpperMode == upperMode) - { - result.append(1, static_cast(' ' + code)); - } - else - { - result.append(1, static_cast(' ' + code + 128)); - } - shiftUpperMode = false; - } - else - { - if (code != CODE_STOP) - { - lastCharacterWasPrintable = false; - } - switch (code) { - case CODE_FNC_1: - if (convertFNC1) - { - if (result.length() == 0) - { - // GS1 specification 5.4.3.7. and 5.4.6.4. If the first char after the start code - // is FNC1 then this is GS1-128. We add the symbology identifier. - result.append("]C1"); - } - else - { - // GS1 specification 5.4.7.5. Every subsequent FNC1 is returned as ASCII 29 (GS) - result.append(1, static_cast(29)); - } - } - break; - case CODE_FNC_2: - case CODE_FNC_3: - break; - // Patch 2992 - case CODE_FNC_4_B: - if (!upperMode && shiftUpperMode) - { - upperMode = true; - shiftUpperMode = false; - } - else if (upperMode && shiftUpperMode) - { - upperMode = false; - shiftUpperMode = false; - } - else - { - shiftUpperMode = true; - } - break; - case CODE_SHIFT: - isNextShifted = true; - codeSet = CODE_CODE_A; - break; - case CODE_CODE_A: - codeSet = CODE_CODE_A; - break; - case CODE_CODE_C: - codeSet = CODE_CODE_C; - break; - case CODE_STOP: - done = true; - break; - } - } - break; - case CODE_CODE_C: - if (code < 100) - { - if (code < 10) - { - result.append(1, '0'); - } - char ccode[20]; - sprintf(ccode, "%d", code); - result.append(ccode); - } - else - { - if (code != CODE_STOP) - { - lastCharacterWasPrintable = false; - } - switch (code) { - case CODE_FNC_1: - if (convertFNC1) - { - if (result.length() == 0) - { - // GS1 specification 5.4.3.7. and 5.4.6.4. If the first char after the start code - // is FNC1 then this is GS1-128. We add the symbology identifier. - result.append("]C1"); - } - else - { - // GS1 specification 5.4.7.5. Every subsequent FNC1 is returned as ASCII 29 (GS) - result.append(1, static_cast(29)); - } - } - break; - case CODE_CODE_A: - codeSet = CODE_CODE_A; - break; - case CODE_CODE_B: - codeSet = CODE_CODE_B; - break; - case CODE_STOP: - done = true; - break; - } - } - break; - } - - // Unshift back to another code set if we were shifted - if (unshift) - { - codeSet = codeSet == CODE_CODE_A ? CODE_CODE_B : CODE_CODE_A; - } - } - - int lastPatternSize = nextStart - lastStart; - - // Check for ample whitespace following pattern, but, to do this we first need to remember that - // we fudged decoding CODE_STOP since it actually has 7 bars, not 6. There is a black bar left - // to read off. Would be slightly better to properly read. Here we just skip it: - ErrorHandler err_handler; - nextStart = row->getNextUnset(nextStart); - if (!row->isRange(nextStart, - (std::min)(row->getSize(), nextStart + (nextStart - lastStart) / 2), - false, err_handler)) { - return Ref(NULL); - } - if (err_handler.ErrCode()) return Ref(NULL); - - // Pull out from sum the value of the penultimate check code - checksumTotal -= multiplier * lastCode; - // lastCode is the checksum then: - if (checksumTotal % 103 != lastCode) - { - return Ref(NULL); - } - - // Need to pull out the check digits from string - int resultLength = result.length(); - if (resultLength == 0) - { - return Ref(NULL); - } - - // Only bother if the result had at least one character, and if the checksum digit happened to - // be a printable character. If it was just interpreted as a control code, nothing to remove. - if (resultLength > 0 && lastCharacterWasPrintable) - { - if (codeSet == CODE_CODE_C) - { - result.erase(resultLength - 2, resultLength); - } - else - { - result.erase(resultLength - 1, resultLength); - } - } - - float left = static_cast(startPatternInfo[1] + startPatternInfo[0]) / 2.0f; - float right = lastStart + lastPatternSize / 2.0f; - - int rawCodesSize = rawCodes.size(); - ArrayRef rawBytes (rawCodesSize); - for (int i = 0; i < rawCodesSize; i++) { - rawBytes[i] = rawCodes[i]; - } - - ArrayRef< Ref > resultPoints(2); - resultPoints[0] = - Ref(new OneDResultPoint(left, static_cast(rowNumber))); - resultPoints[1] = - Ref(new OneDResultPoint(right, static_cast(rowNumber))); - - return Ref(new Result(Ref(new String(result)), rawBytes, resultPoints, BarcodeFormat::CODE_128)); -} - -Code128Reader::~Code128Reader(){} - -zxing::BarcodeFormat Code128Reader::getBarcodeFormat(){ - return BarcodeFormat::CODE_128; -} diff --git a/modules/objdetect/src/zxing/oned/code128reader.hpp b/modules/objdetect/src/zxing/oned/code128reader.hpp deleted file mode 100644 index 1683748220..0000000000 --- a/modules/objdetect/src/zxing/oned/code128reader.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __CODE_128_READER_H__ -#define __CODE_128_READER_H__ -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "one_dreader.hpp" -#include "../common/bit_array.hpp" -#include "../result.hpp" - -namespace zxing { -namespace oned { - -class Code128Reader : public OneDReader { -private: - static const int MAX_AVG_VARIANCE; - static const int MAX_INDIVIDUAL_VARIANCE; - - static std::vector findStartPattern(Ref row, ONED_READER_DATA* onedReaderData); - static int decodeCode(Ref row, - std::vector& counters, - int rowOffset, - ONED_READER_DATA* onedReaderData); - -public: - std::vector counters; - -public: - Ref decodeRow(int rowNumber, Ref row); - - Code128Reader(); - ~Code128Reader(); - - BarcodeFormat getBarcodeFormat(); -}; - -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/code25reader.cpp b/modules/objdetect/src/zxing/oned/code25reader.cpp deleted file mode 100644 index 87666c4629..0000000000 --- a/modules/objdetect/src/zxing/oned/code25reader.cpp +++ /dev/null @@ -1,319 +0,0 @@ -#include "code25reader.hpp" -#include "one_dresult_point.hpp" -#include "../common/array.hpp" -#include "../reader_exception.hpp" -#include "../not_found_exception.hpp" -#include "../checksum_exception.hpp" -#include -#include - -#include - -using std::vector; -using zxing::Ref; -using zxing::Result; -using zxing::String; -using zxing::NotFoundException; -using zxing::ChecksumException; -using zxing::oned::Code25Reader; - -// VC++ -using zxing::BitArray; - -#include "one_dconstant.hpp" -using namespace zxing; -using namespace oned; -using namespace zxing::oned::constant::Code25; - -const int Code25Reader::MAX_AVG_VARIANCE = static_cast(PATTERN_MATCH_RESULT_SCALE_FACTOR * 250 / 1000); -const int Code25Reader::MAX_INDIVIDUAL_VARIANCE = static_cast(PATTERN_MATCH_RESULT_SCALE_FACTOR * 700 / 1000); - -void Code25Reader::init(bool usingCheckDigit_, bool extendedMode_) { - usingCheckDigit = usingCheckDigit_; - extendedMode = extendedMode_; // fake - decodeRowResult.reserve(20); - counters.resize(10); -} - -/** - * Creates a reader that assumes all encoded data is data, and does not treat - * the final character as a check digit. It will not decoded "extended - * Code 39" sequences. - */ -Code25Reader::Code25Reader() { - init(); -} - -/** - * Creates a reader that can be configured to check the last character as a - * check digit. It will not decoded "extended Code 39" sequences. - * - * @param usingCheckDigit if true, treat the last data character as a check - * digit, not data, and verify that the checksum passes. - */ -Code25Reader::Code25Reader(bool usingCheckDigit_) { - init(usingCheckDigit_); -} - -Code25Reader::Code25Reader(bool usingCheckDigit_, bool extendedMode_) { - init(usingCheckDigit_, extendedMode_); -} - -Ref Code25Reader::decodeRow(int rowNumber, Ref row) { - - ErrorHandler err_handler; - std::vector& theCounters(counters); - std::string& result(decodeRowResult); - result.clear(); - std::vector startCounters; - startCounters.resize(4); - - vector start(findStartPattern(row, startCounters, _onedReaderData)); - - if (start.size() == 0) - { - return Ref(NULL); - } - - // Read off white space - int nextStart = row->getNextSet(start[1]); - // int end = row->getSize(); - - char decodedChar; - int lastStart; - do { - bool rp = recordPattern(row, nextStart, theCounters, _onedReaderData); - - if (rp == false) - { - break; - } - - int whitePattern, blackPattern; - if (!splitPattern(theCounters, blackPattern, whitePattern)) - { - break; - } - decodedChar = patternToChar(blackPattern, err_handler); - if (err_handler.ErrCode()) return Ref(NULL); - result.append(1, decodedChar); - - decodedChar = patternToChar(whitePattern, err_handler); - if (err_handler.ErrCode()) return Ref(NULL); - result.append(1, decodedChar); - - lastStart = nextStart; - for (int i = 0, end = theCounters.size(); i < end; i++) { - nextStart += theCounters[i]; - } - // Read off white space - nextStart = row->getNextSet(nextStart); - } while (true); - - std::vector endCounters; - endCounters.resize(3); - - // check end - if (recordPattern(row, nextStart, endCounters, _onedReaderData)) - { - int lastPatternSize = 0; - int endSize = endCounters.size(); - - float deltaA = 0.5; - float deltaB = 1.5; - if (!(endCounters[0] < (3+deltaA) * endCounters[2] && endCounters[0] > (3-deltaB) * endCounters[2])) - return Ref(NULL); - - int minCounters = INT_MAX; - for (int i = 1; i < endSize; ++i) - { - minCounters = (std::min)(minCounters, endCounters[i]); - } - - if (abs(endCounters[1] - endCounters[2]) > minCounters) - return Ref(NULL); - - if (result.length() <= 4) - { - // Almost false positive - return Ref(NULL); - } - - { - ErrorHandler err_handler_; - const int range_start = nextStart + (endCounters[0] + endCounters[1] + endCounters[2]); - const int range_end = range_start + (endCounters[0] + endCounters[1]/2); - if (range_end >= row->getSize() || !row->isRange(range_start, range_end, false, err_handler_)) - return Ref(NULL); - if (err_handler_.ErrCode()) return Ref(NULL); - } - - Ref resultString = Ref(new String(result)); - - float left = static_cast(start[1] + start[0]) / 2.0f; - float right = lastStart + lastPatternSize / 2.0f; - ArrayRef< Ref > resultPoints(2); - resultPoints[0] = - Ref(new OneDResultPoint(left, static_cast(rowNumber))); - resultPoints[1] = - Ref(new OneDResultPoint(right, static_cast(rowNumber))); - return Ref(new Result(resultString, ArrayRef(), resultPoints, BarcodeFormat::CODE_25)); - - return Ref(NULL); - } - return Ref(NULL); -} - -vector Code25Reader::findStartPattern(Ref row, vector& counters, ONED_READER_DATA* onedReaderData) { - vector counters_a; - vector counters_b; - counters_a.resize(2); - counters_b.resize(2); - - int counterOffset = onedReaderData->first_is_white ? 1 : 0; - int patternLength = counters.size(); - int patternStart = onedReaderData->first_is_white ? onedReaderData->all_counters[0] : 0; - - for (int c = counterOffset; c < onedReaderData->counter_size - patternLength + 1; c += 2) { - int i = patternStart; - for (int ii = 0; ii < patternLength; ii++) { - counters[ii] = onedReaderData->all_counters[c + ii]; - i += counters[ii]; - - if (ii == 0 || ii == 2) - { - counters_a[ii/2] = counters[ii]; - } - else - { - counters_b[ii/2] = counters[ii]; - } - } - - // Look for whitespace before start pattern, >= 50% of width of - // start pattern. - - ErrorHandler err_handler; - if ( - counters_a[0] == counters_a[1] && - std::abs(counters_b[0] - counters_b[1]) < 2 && - counters_a[0] / counters_b[0] < 3 && - patternMatchVariance(counters, START_PATTERN, MAX_INDIVIDUAL_VARIANCE) < INT_MAX && - row->isRange((std::max)(0, patternStart - ((i - patternStart) >> 1)), patternStart, false , err_handler)&& - true - ) - { - if (err_handler.ErrCode()) return vector(0); - vector resultValue(2, 0); - resultValue[0] = patternStart; - resultValue[1] = i; - return resultValue; - } - patternStart += counters[0] + counters[1]; - } - - return vector(0); -} - -// For efficiency, returns -1 on failure. Not throwing here saved as many as -// 700 exceptions per image when using some of our blackbox images. -bool Code25Reader::splitPattern(vector& counters, int &blackPattern, int &whitePattern) { - - blackPattern = 0; - whitePattern = 0; - - const int numCounters = counters.size(); - - int minCounterBlack = INT_MAX; - int minCounterWhite = INT_MAX; - - { // get base module - int realMinCounterBlack = INT_MAX; - int realMinCounterWhite = INT_MAX; - int realMaxCounterBlack = 0; - int realMaxCounterWhite = 0; - - // find real min - for (int i = 0; i < numCounters; i++) { - int counter = counters[i]; - if (i & 1) { - if (counter < realMinCounterWhite) - realMinCounterWhite = counter; - if (counter > realMaxCounterWhite) - realMaxCounterWhite = counter; - } - else - { - if (counter < realMinCounterBlack) - realMinCounterBlack = counter; - if (counter > realMaxCounterBlack) - realMaxCounterBlack = counter; - } - } - - minCounterBlack = realMaxCounterBlack; - minCounterWhite = realMaxCounterWhite; - - // find base min - for (int i = 0; i < numCounters; i++) { - int counter = counters[i]; - if (i & 1) - { - if (counter < minCounterWhite && counter > realMinCounterWhite) - minCounterWhite = counter; - } - else - { - if (counter < minCounterBlack && counter > realMinCounterBlack) - minCounterBlack = counter; - } - } - - if (minCounterWhite == realMaxCounterWhite || minCounterWhite + 1 == realMaxCounterWhite) - minCounterWhite = realMinCounterWhite; - if (minCounterBlack == realMaxCounterBlack || minCounterBlack + 1 == realMaxCounterBlack) - minCounterBlack= realMinCounterBlack; - } - - float delta_big = 1; - float delta_small= 1.8; - for (int i = 0; i < numCounters; i++) { - int counter = counters[i]; - - int * piPattern = NULL; - if (i & 1) { - if (counter > (3 + delta_big) * minCounterWhite) return false; - piPattern = &whitePattern; - } - else - { - if (counter > (3 + delta_big) * minCounterBlack) return false; - piPattern = &blackPattern; - } - - *piPattern = *piPattern << 1; - - if (i & 1) - { - if (counter > (3 - delta_small) * minCounterWhite) - *piPattern |= 1; - } - else - { - if (counter > (3 - delta_small) * minCounterBlack) - *piPattern |= 1; - } - } - return true; -} - -char Code25Reader::patternToChar(int pattern, ErrorHandler & err_handler) { - for (int i = 0; i < NUMBER_ENCODINGS_LEN; i++) { - if (NUMBER_ENCODINGS[i] == pattern) { - return i + '0'; - } - } - - err_handler = ErrorHandler(-1); - return 0; -} diff --git a/modules/objdetect/src/zxing/oned/code25reader.hpp b/modules/objdetect/src/zxing/oned/code25reader.hpp deleted file mode 100644 index c124306c95..0000000000 --- a/modules/objdetect/src/zxing/oned/code25reader.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "one_dreader.hpp" -#include "../common/bit_array.hpp" -#include "../error_handler.hpp" -#include "../result.hpp" - -namespace zxing { -namespace oned { - -/** - *

Decodes Code 39 barcodes. This does not support "Full ASCII Code 39" yet.

- * Ported form Java (author Sean Owen) - * @author Lukasz Warchol - */ -class Code25Reader : public OneDReader { -private: - bool usingCheckDigit; - bool extendedMode; - std::string decodeRowResult; - std::vector counters; - - void init(bool usingCheckDigit = false, bool extendedMode = false); - - static std::vector findStartPattern(Ref row, - std::vector& counters, ONED_READER_DATA* onedReaderData); - - static bool splitPattern(std::vector& counters, int &blackPattern, int &whitePattern); - static char patternToChar(int pattern, ErrorHandler & err_handler); - - static const int MAX_AVG_VARIANCE; - static const int MAX_INDIVIDUAL_VARIANCE; - -public: - Code25Reader(); - Code25Reader(bool usingCheckDigit_); - Code25Reader(bool usingCheckDigit_, bool extendedMode_); - - Ref decodeRow(int rowNumber, Ref row); -}; - -} // namespace oned -} // namespace zxing diff --git a/modules/objdetect/src/zxing/oned/code39reader.cpp b/modules/objdetect/src/zxing/oned/code39reader.cpp deleted file mode 100644 index 86742ba11a..0000000000 --- a/modules/objdetect/src/zxing/oned/code39reader.cpp +++ /dev/null @@ -1,337 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "code39reader.hpp" -#include "one_dresult_point.hpp" -#include "../common/array.hpp" -#include "../reader_exception.hpp" -#include "../not_found_exception.hpp" -#include "../checksum_exception.hpp" -#include -#include - -#include - -using std::vector; -using zxing::Ref; -using zxing::Result; -using zxing::String; -using zxing::NotFoundException; -using zxing::ChecksumException; -using zxing::oned::Code39Reader; - -// VC++ -using zxing::BitArray; - -#include "one_dconstant.hpp" -using namespace zxing; -using namespace oned; - -using namespace zxing::oned::constant::Code39; - -void Code39Reader::init(bool usingCheckDigit_, bool extendedMode_) { - usingCheckDigit = usingCheckDigit_; - extendedMode = extendedMode_; - decodeRowResult.reserve(20); - counters.resize(9); -} - -/** - * Creates a reader that assumes all encoded data is data, and does not treat - * the final character as a check digit. It will not decoded "extended - * Code 39" sequences. - */ -Code39Reader::Code39Reader() { - init(); -} - -/** - * Creates a reader that can be configured to check the last character as a - * check digit. It will not decoded "extended Code 39" sequences. - * - * @param usingCheckDigit if true, treat the last data character as a check - * digit, not data, and verify that the checksum passes. - */ -Code39Reader::Code39Reader(bool usingCheckDigit_) { - init(usingCheckDigit_); -} - -Code39Reader::Code39Reader(bool usingCheckDigit_, bool extendedMode_) { - init(usingCheckDigit_, extendedMode_); -} - -Ref Code39Reader::decodeRow(int rowNumber, Ref row) { - std::vector& theCounters(counters); - - std::string& result(decodeRowResult); - result.clear(); - - vector start(findAsteriskPattern(row, theCounters, _onedReaderData)); - - if (start.size() == 0) - { - return Ref(NULL); - } - - // Read off white space - int nextStart = row->getNextSet(start[1]); - int end = row->getSize(); - - ErrorHandler err_handler; - char decodedChar; - int lastStart; - do { - bool rp = recordPattern(row, nextStart, theCounters,_onedReaderData); - - if (rp == false) { - return Ref(NULL); - } - - int pattern = toNarrowWidePattern(theCounters); - if (pattern < 0) { - return Ref(NULL); - } - decodedChar = patternToChar(pattern, err_handler); - if (err_handler.ErrCode()) return Ref(NULL); - result.append(1, decodedChar); - lastStart = nextStart; - - end=theCounters.size(); - for (int i = 0; i < end; i++) { - nextStart += theCounters[i]; - } - // Read off white space - nextStart = row->getNextSet(nextStart); - } while (decodedChar != '*'); - result.resize(decodeRowResult.length()-1); // remove asterisk - - // Look for whitespace after pattern: - int lastPatternSize = 0; - for (int i = 0, e = theCounters.size(); i < e; i++) { - lastPatternSize += theCounters[i]; - } - int whiteSpaceAfterEnd = nextStart - lastStart - lastPatternSize; - // If 50% of last pattern size, following last pattern, is not whitespace, - // fail (but if it's whitespace to the very end of the image, that's OK) - // if (nextStart != end && (whiteSpaceAfterEnd >> 1) < lastPatternSize) { - // Issue #86 : Fix logic error in Code 39 that was requiring too much quiet zone - // https:// github.com/zxing/zxing/commit/f0532a273031f71e75110276833164156c768a6f - if (nextStart != end && (whiteSpaceAfterEnd << 1) < lastPatternSize) { - return Ref(NULL); - } - - if (usingCheckDigit) { - int max = result.length() - 1; - int total = 0; - for (int i = 0; i < max; i++) { - total += alphabet_string.find_first_of(decodeRowResult[i], 0); - } - if (result[max] != ALPHABET[total % 43]) { - return Ref(NULL); - } - result.resize(max); - } - - if (result.length() == 0) { - // Almost false positive - return Ref(NULL); - } - - Ref resultString; - if (extendedMode) { - resultString = decodeExtended(result, err_handler); - if (err_handler.ErrCode()) return Ref(NULL); - } - else - { - resultString = Ref(new String(result)); - } - - float left = static_cast(start[1] + start[0]) / 2.0f; - float right = lastStart + lastPatternSize / 2.0f; - - ArrayRef< Ref > resultPoints(2); - resultPoints[0] = - Ref(new OneDResultPoint(left, static_cast(rowNumber))); - resultPoints[1] = - Ref(new OneDResultPoint(right, static_cast(rowNumber))); - - return Ref( - new Result(resultString, ArrayRef(), resultPoints, BarcodeFormat::CODE_39) - ); -} - -vector Code39Reader::findAsteriskPattern(Ref row, vector& counters, ONED_READER_DATA* onedReaderData){ - - int counterOffset = onedReaderData->first_is_white ? 1 : 0; - int patternLength = counters.size(); - int patternStart = onedReaderData->first_is_white ? onedReaderData->all_counters[0]: 0; - - for (int c = counterOffset; c < onedReaderData->counter_size-patternLength+1; c+=2){ - int i = patternStart; - for (int ii = 0; ii < patternLength; ii++){ - counters[ii] = onedReaderData->all_counters[c+ii]; - i+=counters[ii]; - } - - // Look for whitespace before start pattern, >= 50% of width of - // start pattern. - ErrorHandler err_handler; - if (toNarrowWidePattern(counters) == ASTERISK_ENCODING && - row->isRange((std::max)(0, patternStart - ((i - patternStart) >> 1)), patternStart, false, err_handler)) { - if (err_handler.ErrCode()) return vector(0); - vector resultValue (2, 0); - resultValue[0] = patternStart; - resultValue[1] = i; - return resultValue; - } - patternStart += counters[0]+counters[1]; - } - - return vector(0); -} - -// For efficiency, returns -1 on failure. Not throwing here saved as many as -// 700 exceptions per image when using some of our blackbox images. -int Code39Reader::toNarrowWidePattern(vector& counters){ - int numCounters = counters.size(); - int maxNarrowCounter = 0; - int wideCounters; - do { - int minCounter = INT_MAX; - for (int i = 0; i < numCounters; i++) { - int counter = counters[i]; - if (counter < minCounter && counter > maxNarrowCounter) { - minCounter = counter; - } - } - maxNarrowCounter = minCounter; - wideCounters = 0; - int totalWideCountersWidth = 0; - int pattern = 0; - for (int i = 0; i < numCounters; i++) { - int counter = counters[i]; - if (counter > maxNarrowCounter) { - pattern |= 1 << (numCounters - 1 - i); - wideCounters++; - totalWideCountersWidth += counter; - } - } - if (wideCounters == 3) { - // Found 3 wide counters, but are they close enough in width? - // We can perform a cheap, conservative check to see if any individual - // counter is more than 1.5 times the average: - for (int i = 0; i < numCounters && wideCounters > 0; i++) { - int counter = counters[i]; - if (counter > maxNarrowCounter) { - wideCounters--; - // totalWideCountersWidth = 3 * average, so this checks if - // counter >= 3/2 * average. - if ((counter << 1) >= totalWideCountersWidth) { - return -1; - } - } - } - return pattern; - } - } while (wideCounters > 3); - return -1; -} - -char Code39Reader::patternToChar(int pattern, ErrorHandler & err_handler){ - for (int i = 0; i < CHARACTER_ENCODINGS_LEN; i++) { - if (CHARACTER_ENCODINGS[i] == pattern) { - return ALPHABET[i]; - } - } - - err_handler = ErrorHandler(-1); - return 0; -} - -Ref Code39Reader::decodeExtended(std::string encoded, ErrorHandler & err_handler){ - std::string tmpDecoded; - for (size_t i = 0; i < encoded.length(); i++) { - char c = encoded[i]; - if (c == '+' || c == '$' || c == '%' || c == '/') - { - char next = encoded[i + 1]; - char decodedChar = '\0'; - switch (c) { - case '+': // +A to +Z map to a to z - if (next >= 'A' && next <= 'Z') - { - decodedChar = static_cast(next + 32); - } - else - { - err_handler = ErrorHandler(-1); - return Ref(); - } - break; - case '$': // $A to $Z map to control codes SH to SB - if (next >= 'A' && next <= 'Z') - { - decodedChar = static_cast(next - 64); - } - else - { - err_handler = ErrorHandler(-1); - return Ref(); - } - break; - case '%': // %A to %E map to control codes ESC to US - if (next >= 'A' && next <= 'E') - { - decodedChar = static_cast(next - 38); - } - else if (next >= 'F' && next <= 'W') - { - decodedChar = static_cast(next - 11); - } - else - { - err_handler = ErrorHandler(-1); - return Ref(); - } - break; - case '/': // /A to /O map to ! to , and /Z maps to : - if (next >= 'A' && next <= 'O') { - decodedChar = static_cast(next - 32); - } - else if (next == 'Z') - { - decodedChar = ':'; - } - else - { - err_handler = ErrorHandler(-1); - return Ref(); - } - break; - } - tmpDecoded.append(1, decodedChar); - i++; // bump up i again since we read two characters - } - else - { - tmpDecoded.append(1, c); - } - } - Ref decoded(new String(tmpDecoded)); - return decoded; -} diff --git a/modules/objdetect/src/zxing/oned/code39reader.hpp b/modules/objdetect/src/zxing/oned/code39reader.hpp deleted file mode 100644 index 4950589dda..0000000000 --- a/modules/objdetect/src/zxing/oned/code39reader.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __CODE_39_READER_H__ -#define __CODE_39_READER_H__ -/* - * Code39Reader.hpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "one_dreader.hpp" -#include "../common/bit_array.hpp" -#include "../result.hpp" -#include "../error_handler.hpp" - -namespace zxing { -namespace oned { - -/** - *

Decodes Code 39 barcodes. This does not support "Full ASCII Code 39" yet.

- * Ported form Java (author Sean Owen) - * @author Lukasz Warchol - */ -class Code39Reader : public OneDReader { -private: - bool usingCheckDigit; - bool extendedMode; - std::string decodeRowResult; - std::vector counters; - - void init(bool usingCheckDigit = false, bool extendedMode = false); - - static std::vector findAsteriskPattern(Ref row, - std::vector& counters, ONED_READER_DATA* onedReaderData); - static int toNarrowWidePattern(std::vector& counters); - static char patternToChar(int pattern, ErrorHandler & err_handler); - static Ref decodeExtended(std::string encoded, ErrorHandler & err_handler); - - void append(char* s, char c); - -public: - Code39Reader(); - Code39Reader(bool usingCheckDigit_); - Code39Reader(bool usingCheckDigit_, bool extendedMode_); - - Ref decodeRow(int rowNumber, Ref row); -}; - -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/code93reader.cpp b/modules/objdetect/src/zxing/oned/code93reader.cpp deleted file mode 100644 index d2f197b98e..0000000000 --- a/modules/objdetect/src/zxing/oned/code93reader.cpp +++ /dev/null @@ -1,331 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "code93reader.hpp" -#include "one_dresult_point.hpp" -#include "../common/array.hpp" -#include "../reader_exception.hpp" -#include "../format_exception.hpp" -#include "../not_found_exception.hpp" -#include "../checksum_exception.hpp" -#include -#include - -using std::vector; -using std::string; -using zxing::Ref; -using zxing::Result; -using zxing::String; -using zxing::NotFoundException; -using zxing::ChecksumException; -using zxing::oned::Code93Reader; - -// VC++ -using zxing::BitArray; - -#include "one_dconstant.hpp" -using namespace zxing; -using namespace oned; -using namespace zxing::oned::constant::Code93; - -Code93Reader::Code93Reader() { - decodeRowResult.reserve(20); - counters.resize(6); -} - -Ref Code93Reader::decodeRow(int rowNumber, Ref row) { - Range start(findAsteriskPattern(row)); - - if (start.isValid() == false) { - return Ref(NULL); - } - - // Read off white space - int nextStart = row->getNextSet(start[1]); - int end = row->getSize(); - - vector& theCounters(counters); - { - int size = theCounters.size(); - theCounters.resize(0); - theCounters.resize(size); - } - string& result(decodeRowResult); - result.clear(); - - char decodedChar; - int lastStart; - - ErrorHandler err_handler; - do { - bool rp = recordPattern(row, nextStart, theCounters, _onedReaderData); - - if (rp == false) { - return Ref(NULL); - } - - int pattern = toPattern(theCounters); - if (pattern < 0) { - return Ref(NULL); - } - decodedChar = patternToChar(pattern, err_handler); - if (err_handler.ErrCode()) return Ref(NULL); - - result.append(1, decodedChar); - lastStart = nextStart; - for (int i = 0, e=theCounters.size(); i < e; ++i) { - nextStart += theCounters[i]; - } - // Read off white space - nextStart = row->getNextSet(nextStart); - } while (decodedChar != '*'); - result.resize(result.length() - 1); // remove asterisk - - // Look for whitespace after pattern: - int lastPatternSize = 0; - for (int i = 0, e = theCounters.size(); i < e; i++) { - lastPatternSize += theCounters[i]; - } - - // Should be at least one more black module - if (nextStart == end || !row->get(nextStart)) { - return Ref(NULL); - } - - if (result.length() < 2) { - // false positive -- need at least 2 checksum digits - return Ref(NULL); - } - - checkChecksums(result, err_handler); - if (err_handler.ErrCode()) return Ref(NULL); - // Remove checksum digits - result.resize(result.length() - 2); - - Ref resultString = decodeExtended(result, err_handler); - if (err_handler.ErrCode()) return Ref(NULL); - - float left = static_cast(start[1] + start[0]) / 2.0f; - float right = lastStart + lastPatternSize / 2.0f; - - ArrayRef< Ref > resultPoints(2); - resultPoints[0] = - Ref(new OneDResultPoint(left, static_cast(rowNumber))); - resultPoints[1] = - Ref(new OneDResultPoint(right, static_cast(rowNumber))); - - return Ref(new Result( - resultString, - ArrayRef(), - resultPoints, - BarcodeFormat::CODE_93)); -} - -Code93Reader::Range Code93Reader::findAsteriskPattern(Ref row) { - (void)row; - - { - int size = counters.size(); - counters.resize(0); - counters.resize(size); - } - vector& theCounters(counters); - int counterOffset = _onedReaderData->first_is_white ? 1 : 0; - int patternLength = theCounters.size(); - int patternStart = _onedReaderData->first_is_white ? _onedReaderData->all_counters[0]: 0; - - for (int c = counterOffset; c < _onedReaderData->counter_size-patternLength+1; c+=2){ - int i=patternStart; - for (int ii = 0; ii < patternLength; ii++){ - theCounters[ii] = _onedReaderData->all_counters[c+ii]; - i+=theCounters[ii]; - } - if (toPattern(theCounters) == ASTERISK_ENCODING) { - return Range(patternStart, i); - } - patternStart += counters[0] + counters[1]; - } - - return Range(false); -} - -int Code93Reader::toPattern(vector& counters) { - int max = counters.size(); - int sum = 0; - for (int i = 0, e=counters.size(); i> INTEGER_MATH_SHIFT; - if ((scaledShifted & 0xFF) > 0x7F) { - scaledUnshifted++; - } - if (scaledUnshifted < 1 || scaledUnshifted > 4) { - return -1; - } - if ((i & 0x01) == 0) { - for (int j = 0; j < scaledUnshifted; j++) { - pattern = (pattern << 1) | 0x01; - } - } - else - { - pattern <<= scaledUnshifted; - } - } - return pattern; -} - -char Code93Reader::patternToChar(int pattern, ErrorHandler & err_handler) { - for (int i = 0; i < CHARACTER_ENCODINGS_LENGTH; i++) { - if (CHARACTER_ENCODINGS[i] == pattern) { - return ALPHABET[i]; - } - } - err_handler = ErrorHandler(-1); - return 0; -} - -Ref Code93Reader::decodeExtended(string const& encoded, ErrorHandler & err_handler) { - int length = encoded.length(); - string decoded; - for (int i = 0; i < length; i++) { - char c = encoded[i]; - if (c >= 'a' && c <= 'd') { - if (i >= length - 1) { - err_handler = FormatErrorHandler(-1); - return Ref(); - } - char next = encoded[i + 1]; - char decodedChar = '\0'; - switch (c) { - case 'd': - // +A to +Z map to a to z - if (next >= 'A' && next <= 'Z') - { - decodedChar = static_cast(next + 32); - } - else - { - err_handler = FormatErrorHandler(-1); - return Ref(); - } - break; - case 'a': - // $A to $Z map to control codes SH to SB - if (next >= 'A' && next <= 'Z') - { - decodedChar = static_cast(next - 64); - } - else - { - err_handler = FormatErrorHandler(-1); - return Ref(); - } - break; - case 'b': - if (next >= 'A' && next <= 'E') - { - // %A to %E map to control codes ESC to USep - decodedChar = static_cast(next - 38); - } - else if (next >= 'F' && next <= 'J') - { - // %F to %J map to; < = > ? - decodedChar = static_cast(next - 11); - } - else if (next >= 'K' && next <= 'O') - { - // %K to %O map to [ \ ] ^ _ - decodedChar = static_cast(next + 16); - } - else if (next >= 'P' && next <= 'S') - { - // %P to %S map to { | } ~ - decodedChar = static_cast(next + 43); - } - else if (next >= 'T' && next <= 'Z') - { - // %T to %Z all map to DEL (127) - decodedChar = 127; - } - else - { - err_handler = FormatErrorHandler(-1); - return Ref(); - } - break; - case 'c': - // /A to /O map to ! to , and /Z maps to : - if (next >= 'A' && next <= 'O') - { - decodedChar = static_cast(next - 32); - } - else if (next == 'Z') - { - decodedChar = ':'; - } - else - { - err_handler = FormatErrorHandler(-1); - return Ref(); - } - break; - } - decoded.append(1, decodedChar); - // bump up i again since we read two characters - i++; - } - else - { - decoded.append(1, c); - } - } - return Ref(new String(decoded)); -} - -void Code93Reader::checkChecksums(string const& result, ErrorHandler & err_handler) { - int length = result.length(); - checkOneChecksum(result, length - 2, 20, err_handler); - if (err_handler.ErrCode()) return; - checkOneChecksum(result, length - 1, 15, err_handler); - if (err_handler.ErrCode()) return; -} - -void Code93Reader::checkOneChecksum(string const& result, - int checkPosition, - int weightMax, - ErrorHandler & err_handler) { - int weight = 1; - int total = 0; - for (int i = checkPosition - 1; i >= 0; i--) { - total += weight * ALPHABET_STRING.find_first_of(result[i]); - if (++weight > weightMax) { - weight = 1; - } - } - if (result[checkPosition] != ALPHABET[total % 47]) { - err_handler = CheckSumErrorHandler("checkOneChecksum"); - return; - } -} diff --git a/modules/objdetect/src/zxing/oned/code93reader.hpp b/modules/objdetect/src/zxing/oned/code93reader.hpp deleted file mode 100644 index 176d86b42b..0000000000 --- a/modules/objdetect/src/zxing/oned/code93reader.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __CODE_93_READER_H__ -#define __CODE_93_READER_H__ -/* - * Code93Reader.hpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "one_dreader.hpp" -#include "../common/bit_array.hpp" -#include "../result.hpp" -#include "../error_handler.hpp" - -namespace zxing { -namespace oned { - -/** - *

Decodes Code 93 barcodes. This does not support "Full ASCII Code 93" yet.

- * Ported form Java (author Sean Owen) - * @author Lukasz Warchol - */ -class Code93Reader : public OneDReader { -public: - Code93Reader(); - Ref decodeRow(int rowNumber, Ref row); - -private: - std::string decodeRowResult; - std::vector counters; - - Range findAsteriskPattern(Ref row); - - - static int toPattern(std::vector& counters); - static char patternToChar(int pattern, ErrorHandler & err_handler); - static Ref decodeExtended(std::string const& encoded, ErrorHandler & err_handler); - static void checkChecksums(std::string const& result, ErrorHandler & err_handler); - static void checkOneChecksum(std::string const& result, - int checkPosition, - int weightMax, - ErrorHandler & err_handler); -}; - -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/ean13reader.cpp b/modules/objdetect/src/zxing/oned/ean13reader.cpp deleted file mode 100644 index 5225c1ca39..0000000000 --- a/modules/objdetect/src/zxing/oned/ean13reader.cpp +++ /dev/null @@ -1,133 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ean13reader.hpp" -#include "../not_found_exception.hpp" - -#include "one_dconstant.hpp" - -using namespace zxing; -using namespace oned; -using namespace zxing::oned::constant::UPCEAN; -using namespace zxing::oned::constant::EAN13; - -using std::vector; -using zxing::Ref; -using zxing::BitArray; -using zxing::oned::EAN13Reader; - -EAN13Reader::EAN13Reader() : decodeMiddleCounters(4, 0) { } - -int EAN13Reader::decodeMiddle(Ref row, - Range const& startRange, - std::string& resultString) { - vector& counters (decodeMiddleCounters); - counters.clear(); - counters.resize(4); - int end = row->getSize(); - int rowOffset = startRange[1]; - - int lgPatternFound = 0; - - for (int x = 0; x < 6 && rowOffset < end; x++) { -#ifdef USE_PRE_BESTMATCH - DigitResult digitResult = decodeDigit(row, counters, rowOffset, L_AND_G_PATTERNS, _onedReaderData); - int bestMatch = digitResult.bestMatch; - int counterOffset = digitResult.counterOffset; -#else - int bestMatch = decodeDigit(row, counters, rowOffset, L_AND_G_PATTERNS); - -#endif - - // To decrease throw times, use this instead - if (bestMatch < 0) { - return -1; - } - - resultString.append(1, static_cast('0' + bestMatch % 10)); -#ifdef USE_PRE_BESTMATCH - rowOffset += counterOffset; -#else - for (int i = 0, end = counters.size(); i = 10) { - lgPatternFound |= 1 << (5 - x); - } - } - - _onedReaderData->ean13_decode_middle_middle_offset = rowOffset; - _onedReaderData->ean13_decode_middle_middle_string = resultString; - - ErrorHandler err_handler; - determineFirstDigit(resultString, lgPatternFound, err_handler); - if (err_handler.ErrCode()) return -1; - - Range middleRange = findGuardPattern(row, rowOffset, true, MIDDLE_PATTERN, _onedReaderData); - if (middleRange.isValid() == false) { - return -1; - } - rowOffset = middleRange[1]; - - for (int x = 0; x < 6 && rowOffset < end; x++) { -#ifdef USE_PRE_BESTMATCH - DigitResult digitResult = decodeDigit(row, counters, rowOffset, L_PATTERNS, _onedReaderData); - int bestMatch = digitResult.bestMatch; - int counterOffset = digitResult.counterOffset; -#else - int bestMatch = - decodeDigit(row, counters, rowOffset, L_PATTERNS); -#endif - - // To decrease throw times, use this instead - if (bestMatch < 0) { - return -1; - } - - resultString.append(1, static_cast('0' + bestMatch)); -#ifdef USE_PRE_BESTMATCH - rowOffset += counterOffset; -#else - for (int i = 0, end = counters.size(); i < end; i++) { - rowOffset += counters[i]; - } -#endif - } - - _onedReaderData->ean13_checked =true; - _onedReaderData->ean13_lg_pattern_found = lgPatternFound; - _onedReaderData->ean13_decode_middle_final_offset = rowOffset; - _onedReaderData->ean13_decode_middle_final_string = resultString; - - return rowOffset; -} - -void EAN13Reader::determineFirstDigit(std::string& resultString, int lgPatternFound, ErrorHandler & err_handler) { - for (int d = 0; d < 10; d++) { - if (lgPatternFound == FIRST_DIGIT_ENCODINGS[d]) { - resultString.insert((std::string::size_type)0, (std::string::size_type)1, static_cast('0' + d)); - return; - } - } - - err_handler = NotFoundErrorHandler(-1); -} - -zxing::BarcodeFormat EAN13Reader::getBarcodeFormat(){ - return BarcodeFormat::EAN_13; -} diff --git a/modules/objdetect/src/zxing/oned/ean13reader.hpp b/modules/objdetect/src/zxing/oned/ean13reader.hpp deleted file mode 100644 index 370b35cef8..0000000000 --- a/modules/objdetect/src/zxing/oned/ean13reader.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __EAN_13_READER_H__ -#define __EAN_13_READER_H__ - -/* - * EAN13Reader.hpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "upceanreader.hpp" -#include "../result.hpp" -#include "../error_handler.hpp" - -namespace zxing { -namespace oned { - -class EAN13Reader : public UPCEANReader { -private: - std::vector decodeMiddleCounters; - static void determineFirstDigit(std::string& resultString, - int lgPatternFound, ErrorHandler & err_handler); - -public: - EAN13Reader(); - - int decodeMiddle(Ref row, - Range const& startRange, - std::string& resultString ); - - BarcodeFormat getBarcodeFormat(); -}; - -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/ean8reader.cpp b/modules/objdetect/src/zxing/oned/ean8reader.cpp deleted file mode 100644 index 654f0a5513..0000000000 --- a/modules/objdetect/src/zxing/oned/ean8reader.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ean8reader.hpp" -#include "../reader_exception.hpp" - -using std::vector; -using zxing::oned::EAN8Reader; - -// VC++ -using zxing::Ref; -using zxing::BitArray; - -EAN8Reader::EAN8Reader() : decodeMiddleCounters(4, 0) {} - -int EAN8Reader::decodeMiddle(Ref row, - Range const& startRange, - std::string& result){ - vector& counters (decodeMiddleCounters); - counters[0] = 0; - counters[1] = 0; - counters[2] = 0; - counters[3] = 0; - - int end = row->getSize(); - int rowOffset = startRange[1]; - - for (int x = 0; x < 4 && rowOffset < end; x++) { -#ifdef USE_PRE_BESTMATCH - DigitResult digitResult = decodeDigit(row, counters, rowOffset, L_PATTERNS, _onedReaderData); - int bestMatch = digitResult.bestMatch; - int counterOffset = digitResult.counterOffset; -#else - int bestMatch = decodeDigit(row, counters, rowOffset, L_PATTERNS); -#endif - - // To decrease throw times, use this instead - if (bestMatch < 0) { - return -1; - } - - result.append(1, static_cast('0' + bestMatch)); -#ifdef USE_PRE_ROWOFFSET - rowOffset += counterOffset; -#else - for (int i = 0, end = counters.size(); i < end; i++) { - rowOffset += counters[i]; - } -#endif - } - - Range middleRange = findGuardPattern(row, rowOffset, true, MIDDLE_PATTERN, _onedReaderData); - - if (middleRange.isValid() == false) { - return -1; - } - rowOffset = middleRange[1]; - for (int x = 0; x < 4 && rowOffset < end; x++) { -#ifdef USE_PRE_BESTMATCH - DigitResult digitResult = decodeDigit(row, counters, rowOffset, L_PATTERNS, _onedReaderData); - int bestMatch = digitResult.bestMatch; - int counterOffset = digitResult.counterOffset; -#else - int bestMatch = decodeDigit(row, counters, rowOffset, L_PATTERNS); -#endif - - // To decrease throw times, use this instead - if (bestMatch < 0) { - return -1; - } - - result.append(1, static_cast('0' + bestMatch)); -#ifdef USE_PRE_ROWOFFSET - rowOffset += counterOffset; -#else - for (int i = 0, end = counters.size(); i < end; i++) { - rowOffset += counters[i]; - } -#endif - } - return rowOffset; -} - -zxing::BarcodeFormat EAN8Reader::getBarcodeFormat(){ - return BarcodeFormat::EAN_8; -} diff --git a/modules/objdetect/src/zxing/oned/ean8reader.hpp b/modules/objdetect/src/zxing/oned/ean8reader.hpp deleted file mode 100644 index b7dcc06abf..0000000000 --- a/modules/objdetect/src/zxing/oned/ean8reader.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __EAN_8_READER_H__ -#define __EAN_8_READER_H__ - -/* - * EAN8Reader.hpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "upceanreader.hpp" -#include "../result.hpp" - -namespace zxing { -namespace oned { - -class EAN8Reader : public UPCEANReader { -private: - std::vector decodeMiddleCounters; - -public: - EAN8Reader(); - - int decodeMiddle(Ref row, - Range const& startRange, - std::string& resultString); - - BarcodeFormat getBarcodeFormat(); -}; - -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/itfreader.cpp b/modules/objdetect/src/zxing/oned/itfreader.cpp deleted file mode 100644 index 51ce28926e..0000000000 --- a/modules/objdetect/src/zxing/oned/itfreader.cpp +++ /dev/null @@ -1,395 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../zxing.hpp" -#include "itfreader.hpp" -#include "one_dresult_point.hpp" -#include "../common/array.hpp" -#include "../reader_exception.hpp" -#include "../format_exception.hpp" -#include "../not_found_exception.hpp" -#include - -using std::vector; -using zxing::Ref; -using zxing::ArrayRef; -using zxing::Array; -using zxing::Result; -using zxing::FormatException; -using zxing::NotFoundException; -using zxing::oned::ITFReader; - -// VC++ -using zxing::BitArray; - -#include "one_dconstant.hpp" -using namespace zxing; -using namespace oned; - -using namespace zxing::oned::constant::ITF; - -ITFReader::ITFReader() : narrowLineWidth(-1) { -} - - -Ref ITFReader::decodeRow(int rowNumber, Ref row) { - // Find out where the Middle section (payload) starts & ends - - Range startRange = decodeStart(row); - - if (startRange.isValid() == false) { - return Ref(NULL); - } - - Range endRange = decodeEnd(row); - - if (endRange.isValid() == false) { - return Ref(NULL); - } - - - // To speed up get next sets function - row->initAllNextSets(); - - std::string result; - int endStart = decodeMiddle(row, startRange[1], endRange[0], result); - - if (endStart < 0) { - return Ref(NULL); - } - - Ref resultString(new String(result)); - - ArrayRef allowedLengths; - // Java hints stuff missing - if (!allowedLengths) { - allowedLengths = DEFAULT_ALLOWED_LENGTHS; - } - - // To avoid false positives with 2D barcodes (and other patterns), make - // an assumption that the decoded string must be 6, 10 or 14 digits. - int length = resultString->size(); - bool lengthOK = false; - for (int i = 0, e = allowedLengths->size(); i < e; i++) { - if (length == allowedLengths[i]) { - lengthOK = true; - break; - } - } - - if (!lengthOK) { - return Ref(NULL); - } - - ArrayRef< Ref > resultPoints(2); - resultPoints[0] = - Ref(new OneDResultPoint(static_cast(startRange[1]), static_cast(rowNumber))); - resultPoints[1] = - Ref(new OneDResultPoint(static_cast(endRange[0]), static_cast(rowNumber))); - return Ref(new Result(resultString, ArrayRef(), resultPoints, BarcodeFormat::ITF)); -} - -/** - * @param row row of black/white values to search - * @param payloadStart offset of start pattern - * @param resultString {@link StringBuffer} to append decoded chars to - * @throws ReaderException if decoding could not complete successfully - */ -int ITFReader::decodeMiddle(Ref row, - int payloadStart, - int payloadEnd, - std::string& resultString) { - // Digits are interleaved in pairs - 5 black lines for one digit, and the - // 5 - // interleaved white lines for the second digit. - // Therefore, need to scan 10 lines and then - // split these into two arrays - vector counterDigitPair(10, 0); - vector counterBlack(5, 0); - vector counterWhite(5, 0); - - while (payloadStart < payloadEnd) { - - // Get 10 runs of black/white. - bool rp = recordPattern(row, payloadStart, counterDigitPair, _onedReaderData); - - if (rp == false) { - return -1; - } - - // Split them into each array - for (int k = 0; k < 5; k++) { - int twoK = k << 1; - counterBlack[k] = counterDigitPair[twoK]; - counterWhite[k] = counterDigitPair[twoK + 1]; - } - - int bestMatch = decodeDigit(counterBlack); - - - // To decrease throw times, use this instead - if (bestMatch < 0) { - return -1; - } - - resultString.append(1, static_cast('0' + bestMatch)); - bestMatch = decodeDigit(counterWhite); - - // To decrease throw times, use this instead - if (bestMatch < 0) { - return -1; - } - - resultString.append(1, static_cast('0' + bestMatch)); - - for (int i = 0, e = counterDigitPair.size(); i < e; i++) { - payloadStart += counterDigitPair[i]; - } - } - - return 1; -} - -/** - * Identify where the start of the middle / payload section starts. - * - * @param row row of black/white values to search - * @return Array, containing index of start of 'start block' and end of - * 'start block' - * @throws ReaderException - */ -ITFReader::Range ITFReader::decodeStart(Ref row) { - int endStart = skipWhiteSpace(row); - - if (endStart < 0) { - return Range(false); - } - - Range startPattern = findGuardPattern(row, endStart, START_PATTERN_VECTOR, _onedReaderData); - - if (startPattern.isValid() == false) { - return startPattern; - } - - // Determine the width of a narrow line in pixels. We can do this by - // getting the width of the start pattern and dividing by 4 because its - // made up of 4 narrow lines. - narrowLineWidth = (startPattern[1] - startPattern[0]) >> 2; - - bool isValidQZ = validateQuietZone(row, startPattern[0]); - - if (isValidQZ==false) { - return Range(false); - } - return startPattern; -} - -/** - * Identify where the end of the middle / payload section ends. - * - * @param row row of black/white values to search - * @return Array, containing index of start of 'end block' and end of 'end - * block' - * @throws ReaderException - */ - -ITFReader::Range ITFReader::decodeEnd(Ref row) { - // For convenience, reverse the row and then - // search from 'the start' for the end block - BitArray::Reverse r(row); - - - reverseAllPattern(_onedReaderData); - - - // To speed up get next sets function - row->initAllNextSets(); - - int endStart = skipWhiteSpace(row); - Range endPattern = findGuardPattern(row, endStart, END_PATTERN_REVERSED, _onedReaderData); - - if (endPattern.isValid() == false) { - return endPattern; - } - - - // The start & end patterns must be pre/post fixed by a quiet zone. This - // zone must be at least 10 times the width of a narrow line. - // ref: http:// www.barcode-1.net/i25code.html - bool isValidQZ = validateQuietZone(row, endPattern[0]); - - if (isValidQZ==false) { - return Range(false); - } - - // Now recalculate the indices of where the 'endblock' starts & stops to - // accommodate - // the reversed nature of the search - int temp = endPattern[0]; - endPattern[0] = row->getSize() - endPattern[1]; - endPattern[1] = row->getSize() - temp; - - reverseAllPattern(_onedReaderData); - return endPattern; -} - -/** - * The start & end patterns must be pre/post fixed by a quiet zone. This - * zone must be at least 10 times the width of a narrow line. Scan back until - * we either get to the start of the barcode or match the necessary number of - * quiet zone pixels. - * - * Note: Its assumed the row is reversed when using this method to find - * quiet zone after the end pattern. - * - * ref: http:// www.barcode-1.net/i25code.html - * - * @param row bit array representing the scanned barcode. - * @param startPattern index into row of the start or end pattern. - * @throws ReaderException if the quiet zone cannot be found, a ReaderException is thrown. - */ -bool ITFReader::validateQuietZone(Ref row, int startPattern) { - int quietCount = this->narrowLineWidth * 10; // expect to find this many pixels of quiet zone - - for (int i = startPattern - 1; quietCount > 0 && i >= 0; i--) { - if (row->get(i)) { - break; - } - quietCount--; - } - if (quietCount != 0) { - // Unable to find the necessary number of quiet zone pixels. - return false; - } - - return true; -} - -/** - * Skip all whitespace until we get to the first black line. - * - * @param row row of black/white values to search - * @return index of the first black line. - * @throws ReaderException Throws exception if no black lines are found in the row - */ -int ITFReader::skipWhiteSpace(Ref row) { - int width = row->getSize(); - int endStart = row->getNextSet(0); - if (endStart == width) { - return -1; - } - return endStart; -} - -/** - * @param row row of black/white values to search - * @param rowOffset position to start search - * @param pattern pattern of counts of number of black and white pixels that are - * being searched for as a pattern - * @return start/end horizontal offset of guard pattern, as an array of two - * ints - * @throws ReaderException if pattern is not found - */ -ITFReader::Range ITFReader::findGuardPattern(Ref row, - int rowOffset, - vector const& pattern, - ONED_READER_DATA* onedReaderData) { - if (rowOffset == row->getSize()) - { - return Range(false); - } - - int patternLength = pattern.size(); - vector counters(patternLength); - int counterOffset=0; - int patternOffset=0; - bool isWhite= onedReaderData->first_is_white; - - - while (counterOffsetcounter_size-1&&patternOffsetall_counters_offsets[counterOffset]; - isWhite = !isWhite; - } - - if (isWhite){ - counters[0] = 0; - } - else - { - counters[0]= onedReaderData->all_counters[counterOffset]-(rowOffset-patternOffset); - } - int x=rowOffset+counters[0]; - - for (int c = counterOffset; c < onedReaderData->counter_size-patternLength+1; c+=2){ - if (c==counterOffset){ - for (int ii=1; ii < patternLength; ii++){ - counters[ii] = onedReaderData->all_counters[c+ii]; - x+=counters[ii]; - } - } - else - { - for (int ii = 0; ii < patternLength; ii++){ - counters[ii] = onedReaderData->all_counters[c+ii]; - x+=counters[ii]; - } - } - - if (patternMatchVariance(counters, &pattern[0], MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) { - return Range(rowOffset, x); - } - - rowOffset += counters[0]+counters[1]; - } - return Range(false); -} - -/** - * Attempts to decode a sequence of ITF black/white lines into single - * digit. - * - * @param counters the counts of runs of observed black/white/black/... values - * @return The decoded digit - * @throws ReaderException if digit cannot be decoded - */ -int ITFReader::decodeDigit(vector& counters){ - - int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept - int bestMatch = -1; - int max = sizeof(PATTERNS)/sizeof(PATTERNS[0]); - for (int i = 0; i < max; i++) { - int const* pattern = PATTERNS[i]; - int variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE); - if (variance < bestVariance) - { - bestVariance = variance; - bestMatch = i; - } - } - if (bestMatch >= 0) - { - return bestMatch; - } - else - { - return -1; - } -} - -ITFReader::~ITFReader(){} - diff --git a/modules/objdetect/src/zxing/oned/itfreader.hpp b/modules/objdetect/src/zxing/oned/itfreader.hpp deleted file mode 100644 index cf7946b13d..0000000000 --- a/modules/objdetect/src/zxing/oned/itfreader.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __ITF_READER_H__ -#define __ITF_READER_H__ - -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "one_dreader.hpp" -#include "../common/bit_array.hpp" -#include "../result.hpp" - - -namespace zxing { -namespace oned { - -class ITFReader : public OneDReader { -private: - enum {MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 420/1000)}; - enum {MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 780/1000)}; - // Stores the actual narrow line width of the image being decoded. - int narrowLineWidth; - - Range decodeStart(Ref row); - Range decodeEnd(Ref row); - int decodeMiddle(Ref row, int payloadStart, int payloadEnd, std::string& resultString); - bool validateQuietZone(Ref row, int startPattern); - static int skipWhiteSpace(Ref row); - - static Range findGuardPattern(Ref row, int rowOffset, std::vector const& pattern, ONED_READER_DATA* onedReaderData); - static int decodeDigit(std::vector& counters); - - void append(char* s, char c); - -public: - Ref decodeRow(int rowNumber, Ref row); - - ITFReader(); - ~ITFReader(); -}; - -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/multi_format_one_dreader.cpp b/modules/objdetect/src/zxing/oned/multi_format_one_dreader.cpp deleted file mode 100644 index 713a556e7a..0000000000 --- a/modules/objdetect/src/zxing/oned/multi_format_one_dreader.cpp +++ /dev/null @@ -1,162 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../zxing.hpp" -#include "multi_format_one_dreader.hpp" -#include "multi_format_upceanreader.hpp" -#include "code39reader.hpp" -#include "code128reader.hpp" -#include "code93reader.hpp" -#include "code25reader.hpp" -#include "coda_bar_reader.hpp" -#include "itfreader.hpp" -#include "../reader_exception.hpp" -#include "../not_found_exception.hpp" - -using zxing::Ref; -using zxing::Result; -using zxing::oned::MultiFormatOneDReader; - -// VC++ -using zxing::DecodeHints; -using zxing::BitArray; - -// changoran-20160102- add oned reader base on hints -MultiFormatOneDReader::MultiFormatOneDReader(DecodeHints hints) : readers() { - if (hints.containsFormat(BarcodeFormat::EAN_13) || - hints.containsFormat(BarcodeFormat::EAN_8) || - hints.containsFormat(BarcodeFormat::UPC_A) || - hints.containsFormat(BarcodeFormat::UPC_E)) { - readers.push_back(Ref(new MultiFormatUPCEANReader(hints))); - } - - if (hints.containsFormat(BarcodeFormat::CODE_93)) { - readers.push_back(Ref(new Code93Reader())); - } - - if (hints.containsFormat(BarcodeFormat::CODABAR)) { - readers.push_back(Ref(new CodaBarReader())); - } - if (hints.containsFormat(BarcodeFormat::CODE_39)) { - readers.push_back(Ref(new Code39Reader())); - } - if (hints.containsFormat(BarcodeFormat::CODE_128)) { - readers.push_back(Ref(new Code128Reader())); - } - - // ITF === CODE_25 , so we not use it - // if (hints.containsFormat(BarcodeFormat::ITF)) { - // Some mistake in ITF, preserve for later check : valiantliu - // readers.push_back(Ref(new ITFReader())); - // } - - if (hints.containsFormat(BarcodeFormat::CODE_25)) { - readers.push_back(Ref(new Code25Reader())); - } - - /* - if (hints.containsFormat(BarcodeFormat::RSS_14)) { - readers.push_back(Ref(new RSS14Reader())); - } - */ - /* - if (hints.containsFormat(BarcodeFormat::RSS_EXPANDED)) { - readers.push_back(Ref(new RSS14ExpandedReader())); - } - */ - - if (readers.size() == 0) { - readers.push_back(Ref(new MultiFormatUPCEANReader(hints))); - readers.push_back(Ref(new Code39Reader())); - readers.push_back(Ref(new CodaBarReader())); - readers.push_back(Ref(new Code93Reader())); - readers.push_back(Ref(new Code128Reader())); - - // Some mistake in ITF, preserve for later check : valiantliu - // readers.push_back(Ref(new ITFReader())); - // readers.push_back(Ref(new RSS14Reader())); - // readers.push_back(Ref(new RSS14ExpandedReader())); - readers.push_back(Ref(new Code25Reader())); - } - - // -- Add Reader Data : Start - readerData = new ONED_READER_DATA; - - readerData->all_counters = std::vector(0); - readerData->all_counters_offsets = std::vector(0); - readerData->first_is_white = false; - readerData->counter_size = 0; - - readerData->ean13_checked = false; - readerData->ean13_lg_pattern_found = 0; - readerData->ean13_decode_middle_middle_offset = 0; - readerData->ean13_decode_middle_final_offset = 0; - readerData->ean13_decode_middle_middle_string = ""; - readerData->ean13_decode_middle_final_string = ""; - - for (unsigned int k=0; k < readers.size(); k++) - { - readers[k]->setData(readerData); - } - - _onedReaderData = readerData; -} - -MultiFormatOneDReader::~MultiFormatOneDReader() -{ - delete readerData; -} - -#include - -Ref MultiFormatOneDReader::decodeRow(int rowNumber, Ref row) { - - // Just need to check - if (bNeedCheck == true) - { - return decodeRow(rowNumber, row, _lastReaderIdx); - } - - int size = readers.size(); - - for (int i = 0; i < size; i++) { - OneDReader* reader = readers[i]; - - Ref result = reader->decodeRow(rowNumber, row); - - if (result==NULL) { - continue; - } - - _lastReaderIdx = i; - return result; - } - - return Ref(NULL); -} - -Ref MultiFormatOneDReader::decodeRow(int rowNumber, Ref row, int readerIdx) { - - OneDReader* reader = readers[readerIdx]; - - Ref result = reader->decodeRow(rowNumber, row); - - _lastReaderIdx = readerIdx; - return result; - - return Ref(NULL); -} diff --git a/modules/objdetect/src/zxing/oned/multi_format_one_dreader.hpp b/modules/objdetect/src/zxing/oned/multi_format_one_dreader.hpp deleted file mode 100644 index 1282797ceb..0000000000 --- a/modules/objdetect/src/zxing/oned/multi_format_one_dreader.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef __MULTI_FORMAT_ONED_READER_H__ -#define __MULTI_FORMAT_ONED_READER_H__ -/* - * MultiFormatOneDReader.hpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "one_dreader.hpp" -#include "../error_handler.hpp" - -namespace zxing { -namespace oned { -class MultiFormatOneDReader : public OneDReader { -private: - std::vector > readers; - - // -- Add Reader Data - ONED_READER_DATA* readerData; - -public: - MultiFormatOneDReader(DecodeHints hints); - std::string name() { return "oned"; } - - ~MultiFormatOneDReader(); - - Ref decodeRow(int rowNumber, Ref row); - Ref decodeRow(int rowNumber, Ref row, int readerIdx); -}; -} // namespace oned -} // namespace zxing - -#endif // QBAR_AI_QBAR_ZXING_ONED_MULTIFORMATONEDREADER_H_ diff --git a/modules/objdetect/src/zxing/oned/multi_format_upceanreader.cpp b/modules/objdetect/src/zxing/oned/multi_format_upceanreader.cpp deleted file mode 100644 index c1ee28e499..0000000000 --- a/modules/objdetect/src/zxing/oned/multi_format_upceanreader.cpp +++ /dev/null @@ -1,141 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * MultiFormatUPCEANReader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../zxing.hpp" -#include "multi_format_upceanreader.hpp" -#include "ean13reader.hpp" -#include "ean8reader.hpp" -#include "upcereader.hpp" -#include "upcareader.hpp" -#include "one_dresult_point.hpp" -#include "../common/array.hpp" -#include "../reader_exception.hpp" -#include "../not_found_exception.hpp" -#include - -using zxing::NotFoundException; -using zxing::Ref; -using zxing::Result; -using zxing::oned::MultiFormatUPCEANReader; - -// VC++ -using zxing::DecodeHints; -using zxing::BitArray; - -MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers() { - if (hints.containsFormat(BarcodeFormat::EAN_13)) - { - readers.push_back(Ref(new EAN13Reader())); - } - else if (hints.containsFormat(BarcodeFormat::UPC_A)) - { - readers.push_back(Ref(new UPCAReader())); - } - if (hints.containsFormat(BarcodeFormat::EAN_8)) - { - readers.push_back(Ref(new EAN8Reader())); - } - if (hints.containsFormat(BarcodeFormat::UPC_E)) - { - readers.push_back(Ref(new UPCEReader())); - } - if (readers.size() == 0) - { - readers.push_back(Ref(new EAN13Reader())); - // UPC-A is covered by EAN-13 - readers.push_back(Ref(new EAN8Reader())); - readers.push_back(Ref(new UPCEReader())); - } -} - -void MultiFormatUPCEANReader::setData(ONED_READER_DATA* onedReaderData) -{ - for (size_t k = 0; k < readers.size(); k++) - { - readers[k]->setData(onedReaderData); - } - - _onedReaderData = onedReaderData; -} - - -#include - -Ref MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref row) { - // Compute this location once and reuse it on multiple implementations - ErrorHandler err_handler; - UPCEANReader::Range startGuardPattern = UPCEANReader::findStartGuardPattern(row, _onedReaderData, err_handler); - if (err_handler.ErrCode()) return Ref(NULL); - - if (startGuardPattern.isValid() == false) { - return Ref(NULL); - } - - _onedReaderData->ean13_checked = false; - - -#ifdef USE_PRE_BESTMATCH - UPCEANReader::initbestMatchDigit(row, _onedReaderData); -#endif - - for (int i = 0, e = readers.size(); i < e; i++) { - - Ref reader = readers[i]; - Ref result; - result = reader->decodeRow(rowNumber, row, startGuardPattern); - - if (result == NULL) { - continue; - } - - // Special case: a 12-digit code encoded in UPC-A is identical - // to a "0" followed by those 12 digits encoded as EAN-13. Each - // will recognize such a code, UPC-A as a 12-digit string and - // EAN-13 as a 13-digit string starting with "0". Individually - // these are correct and their readers will both read such a - // code and correctly call it EAN-13, or UPC-A, respectively. - // - // In this case, if we've been looking for both types, we'd like - // to call it a UPC-A code. But for efficiency we only run the - // EAN-13 decoder to also read UPC-A. So we special case it - // here, and convert an EAN-13 result to a UPC-A result if - // appropriate. - bool ean13MayBeUPCA = - result->getBarcodeFormat() == BarcodeFormat::EAN_13 && - result->getText()->charAt(0) == '0'; - - // Note: doesn't match Java which uses hints - - bool canReturnUPCA = true; - - if (ean13MayBeUPCA && canReturnUPCA) { - // Transfer the metdata across - Ref resultUPCA (new Result(result->getText()->substring(1), - result->getRawBytes(), - result->getResultPoints(), - BarcodeFormat::UPC_A)); - // needs java metadata stuff - return resultUPCA; - } - return result; - } - - return Ref(NULL); -} diff --git a/modules/objdetect/src/zxing/oned/multi_format_upceanreader.hpp b/modules/objdetect/src/zxing/oned/multi_format_upceanreader.hpp deleted file mode 100644 index 6a5cd6a0b1..0000000000 --- a/modules/objdetect/src/zxing/oned/multi_format_upceanreader.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __MULTI_FORMAT_UPC_EAN_READER_H__ -#define __MULTI_FORMAT_UPC_EAN_READER_H__ -/* - * MultiFormatUPCEANReader.hpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "one_dreader.hpp" -#include "upceanreader.hpp" - -namespace zxing { -namespace oned { - -class UPCEANReader; - -class MultiFormatUPCEANReader : public OneDReader { -private: - std::vector< Ref > readers; - -public: - MultiFormatUPCEANReader(DecodeHints hints); - Ref decodeRow(int rowNumber, Ref row); - void setData(ONED_READER_DATA* onedReaderData); -}; - -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/one_dconstant.hpp b/modules/objdetect/src/zxing/oned/one_dconstant.hpp deleted file mode 100644 index dedf079802..0000000000 --- a/modules/objdetect/src/zxing/oned/one_dconstant.hpp +++ /dev/null @@ -1,384 +0,0 @@ -#ifndef __CODE_CONSTANT_H__ -#define __CODE_CONSTANT_H__ - -#include "../zxing.hpp" - -#define LEN(v) ((int)(sizeof(v)/sizeof(v[0]))) -#define VECTOR_INIT(v) v, v + sizeof(v)/sizeof(v[0]) - -namespace zxing -{ - namespace oned - { - namespace constant - { - namespace Code128 - { - const int CODE_SHIFT = 98; - - const int CODE_CODE_C = 99; - const int CODE_CODE_B = 100; - const int CODE_CODE_A = 101; - - const int CODE_FNC_1 = 102; - const int CODE_FNC_2 = 97; - const int CODE_FNC_3 = 96; - const int CODE_FNC_4_A = 101; - const int CODE_FNC_4_B = 100; - - const int CODE_START_A = 103; - const int CODE_START_B = 104; - const int CODE_START_C = 105; - const int CODE_STOP = 106; - - // Dummy characters used to specify control characters in input - const char ESCAPE_FNC_1 = 0xf1; - const char ESCAPE_FNC_2 = 0xf2; - const char ESCAPE_FNC_3 = 0xf3; - const char ESCAPE_FNC_4 = 0xf4; - - const int CODE_PATTERNS_ONE_SIZE = 6; - - const int CODE_PATTERNS_LENGTH = 107; - const int CODE_PATTERNS[CODE_PATTERNS_LENGTH][6] = { - {2, 1, 2, 2, 2, 2}, /* 0 */ - {2, 2, 2, 1, 2, 2}, - {2, 2, 2, 2, 2, 1}, - {1, 2, 1, 2, 2, 3}, - {1, 2, 1, 3, 2, 2}, - {1, 3, 1, 2, 2, 2}, /* 5 */ - {1, 2, 2, 2, 1, 3}, - {1, 2, 2, 3, 1, 2}, - {1, 3, 2, 2, 1, 2}, - {2, 2, 1, 2, 1, 3}, - {2, 2, 1, 3, 1, 2}, /* 10 */ - {2, 3, 1, 2, 1, 2}, - {1, 1, 2, 2, 3, 2}, - {1, 2, 2, 1, 3, 2}, - {1, 2, 2, 2, 3, 1}, - {1, 1, 3, 2, 2, 2}, /* 15 */ - {1, 2, 3, 1, 2, 2}, - {1, 2, 3, 2, 2, 1}, - {2, 2, 3, 2, 1, 1}, - {2, 2, 1, 1, 3, 2}, - {2, 2, 1, 2, 3, 1}, /* 20 */ - {2, 1, 3, 2, 1, 2}, - {2, 2, 3, 1, 1, 2}, - {3, 1, 2, 1, 3, 1}, - {3, 1, 1, 2, 2, 2}, - {3, 2, 1, 1, 2, 2}, /* 25 */ - {3, 2, 1, 2, 2, 1}, - {3, 1, 2, 2, 1, 2}, - {3, 2, 2, 1, 1, 2}, - {3, 2, 2, 2, 1, 1}, - {2, 1, 2, 1, 2, 3}, /* 30 */ - {2, 1, 2, 3, 2, 1}, - {2, 3, 2, 1, 2, 1}, - {1, 1, 1, 3, 2, 3}, - {1, 3, 1, 1, 2, 3}, - {1, 3, 1, 3, 2, 1}, /* 35 */ - {1, 1, 2, 3, 1, 3}, - {1, 3, 2, 1, 1, 3}, - {1, 3, 2, 3, 1, 1}, - {2, 1, 1, 3, 1, 3}, - {2, 3, 1, 1, 1, 3}, /* 40 */ - {2, 3, 1, 3, 1, 1}, - {1, 1, 2, 1, 3, 3}, - {1, 1, 2, 3, 3, 1}, - {1, 3, 2, 1, 3, 1}, - {1, 1, 3, 1, 2, 3}, /* 45 */ - {1, 1, 3, 3, 2, 1}, - {1, 3, 3, 1, 2, 1}, - {3, 1, 3, 1, 2, 1}, - {2, 1, 1, 3, 3, 1}, - {2, 3, 1, 1, 3, 1}, /* 50 */ - {2, 1, 3, 1, 1, 3}, - {2, 1, 3, 3, 1, 1}, - {2, 1, 3, 1, 3, 1}, - {3, 1, 1, 1, 2, 3}, - {3, 1, 1, 3, 2, 1}, /* 55 */ - {3, 3, 1, 1, 2, 1}, - {3, 1, 2, 1, 1, 3}, - {3, 1, 2, 3, 1, 1}, - {3, 3, 2, 1, 1, 1}, - {3, 1, 4, 1, 1, 1}, /* 60 */ - {2, 2, 1, 4, 1, 1}, - {4, 3, 1, 1, 1, 1}, - {1, 1, 1, 2, 2, 4}, - {1, 1, 1, 4, 2, 2}, - {1, 2, 1, 1, 2, 4}, /* 65 */ - {1, 2, 1, 4, 2, 1}, - {1, 4, 1, 1, 2, 2}, - {1, 4, 1, 2, 2, 1}, - {1, 1, 2, 2, 1, 4}, - {1, 1, 2, 4, 1, 2}, /* 70 */ - {1, 2, 2, 1, 1, 4}, - {1, 2, 2, 4, 1, 1}, - {1, 4, 2, 1, 1, 2}, - {1, 4, 2, 2, 1, 1}, - {2, 4, 1, 2, 1, 1}, /* 75 */ - {2, 2, 1, 1, 1, 4}, - {4, 1, 3, 1, 1, 1}, - {2, 4, 1, 1, 1, 2}, - {1, 3, 4, 1, 1, 1}, - {1, 1, 1, 2, 4, 2}, /* 80 */ - {1, 2, 1, 1, 4, 2}, - {1, 2, 1, 2, 4, 1}, - {1, 1, 4, 2, 1, 2}, - {1, 2, 4, 1, 1, 2}, - {1, 2, 4, 2, 1, 1}, /* 85 */ - {4, 1, 1, 2, 1, 2}, - {4, 2, 1, 1, 1, 2}, - {4, 2, 1, 2, 1, 1}, - {2, 1, 2, 1, 4, 1}, - {2, 1, 4, 1, 2, 1}, /* 90 */ - {4, 1, 2, 1, 2, 1}, - {1, 1, 1, 1, 4, 3}, - {1, 1, 1, 3, 4, 1}, - {1, 3, 1, 1, 4, 1}, - {1, 1, 4, 1, 1, 3}, /* 95 */ - {1, 1, 4, 3, 1, 1}, - {4, 1, 1, 1, 1, 3}, - {4, 1, 1, 3, 1, 1}, - {1, 1, 3, 1, 4, 1}, - {1, 1, 4, 1, 3, 1}, /* 100 */ - {3, 1, 1, 1, 4, 1}, - {4, 1, 1, 1, 3, 1}, - {2, 1, 1, 4, 1, 2}, - {2, 1, 1, 2, 1, 4}, - {2, 1, 1, 2, 3, 2}, /* 105 */ - {2, 3, 3, 1, 1, 1}, - }; - } - - namespace UPCEAN{ - - /** - * Start/end guard pattern. - */ - const int START_END_PATTERN_[] = {1, 1, 1}; - const int START_END_PATTERN_LEN = LEN(START_END_PATTERN_); - - /** - * Pattern marking the middle of a UPC/EAN pattern, separating the two halves. - */ - const int MIDDLE_PATTERN_[] = {1, 1, 1, 1, 1}; - const int MIDDLE_PATTERN_LEN = LEN(MIDDLE_PATTERN_); - - const int L_AND_G_PATTERNS_ONE_SIZE = 4; - - /** - * "Odd", or "L" patterns used to encode UPC/EAN digits. - */ - const int L_PATTERNS_[][4] = { - {3, 2, 1, 1}, // 0 - {2, 2, 2, 1}, // 1 - {2, 1, 2, 2}, // 2 - {1, 4, 1, 1}, // 3 - {1, 1, 3, 2}, // 4 - {1, 2, 3, 1}, // 5 - {1, 1, 1, 4}, // 6 - {1, 3, 1, 2}, // 7 - {1, 2, 1, 3}, // 8 - {3, 1, 1, 2} // 9 - }; - const int L_PATTERNS_LEN = LEN(L_PATTERNS_); - - /** - * "G" patterns used to encode UPC/EAN digits. -- Valiantliu - */ - const int G_PATTERNS_[][4] = { - {1, 1, 2, 3}, // 10 reversed 0 - {1, 2, 2, 2}, // 11 reversed 1 - {2, 2, 1, 2}, // 12 reversed 2 - {1, 1, 4, 1}, // 13 reversed 3 - {2, 3, 1, 1}, // 14 reversed 4 - {1, 3, 2, 1}, // 15 reversed 5 - {4, 1, 1, 1}, // 16 reversed 6 - {2, 1, 3, 1}, // 17 reversed 7 - {3, 1, 2, 1}, // 18 reversed 8 - {2, 1, 1, 3} // 19 reversed 9 - }; - const int G_PATTERNS_LEN = LEN(G_PATTERNS_); - /** - * As above but also including the "even", or "G" patterns used to encode UPC/EAN digits. - */ - const int L_AND_G_PATTERNS_[][4] = { - {3, 2, 1, 1}, // 0 - {2, 2, 2, 1}, // 1 - {2, 1, 2, 2}, // 2 - {1, 4, 1, 1}, // 3 - {1, 1, 3, 2}, // 4 - {1, 2, 3, 1}, // 5 - {1, 1, 1, 4}, // 6 - {1, 3, 1, 2}, // 7 - {1, 2, 1, 3}, // 8 - {3, 1, 1, 2}, // 9 - {1, 1, 2, 3}, // 10 reversed 0 - {1, 2, 2, 2}, // 11 reversed 1 - {2, 2, 1, 2}, // 12 reversed 2 - {1, 1, 4, 1}, // 13 reversed 3 - {2, 3, 1, 1}, // 14 reversed 4 - {1, 3, 2, 1}, // 15 reversed 5 - {4, 1, 1, 1}, // 16 reversed 6 - {2, 1, 3, 1}, // 17 reversed 7 - {3, 1, 2, 1}, // 18 reversed 8 - {2, 1, 1, 3} // 19 reversed 9 - }; - const int L_AND_G_PATTERNS_LEN = LEN(L_AND_G_PATTERNS_); - } - - namespace EAN13 { - const int FIRST_DIGIT_ENCODINGS[10] = { - 0x00, 0x0B, 0x0D, 0xE, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A - }; - } - - namespace Code39{ - const char ALPHABET[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%"; - - /** - * These represent the encodings of characters, as patterns of wide and narrow - * bars. - * The 9 least-significant bits of each int correspond to the pattern of wide - * and narrow, with 1s representing "wide" and 0s representing narrow. - */ - const int CHARACTER_ENCODINGS_LEN = 44; - const int CHARACTER_ENCODINGS[CHARACTER_ENCODINGS_LEN] = { - 0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124, 0x064, // 0-9 - 0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C, 0x04C, 0x01C, // A-J - 0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007, 0x106, 0x046, 0x016, // K-T - 0x181, 0x0C1, 0x1C0, 0x091, 0x190, 0x0D0, 0x085, 0x184, 0x0C4, 0x094, // U-* - 0x0A8, 0x0A2, 0x08A, 0x02A // $-% - }; - - const int ASTERISK_ENCODING = 0x094; - const char ALPHABET_STRING[] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%"; - - const std::string alphabet_string (ALPHABET_STRING); - } - - namespace Code93{ - char const ALPHABET[] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd*"; - const std::string ALPHABET_STRING (ALPHABET); - - /** - * These represent the encodings of characters, as patterns of wide and narrow bars. - * The 9 least-significant bits of each int correspond to the pattern of wide and narrow. - */ - int const CHARACTER_ENCODINGS[] = { - 0x114, 0x148, 0x144, 0x142, 0x128, 0x124, 0x122, 0x150, 0x112, 0x10A, // 0-9 - 0x1A8, 0x1A4, 0x1A2, 0x194, 0x192, 0x18A, 0x168, 0x164, 0x162, 0x134, // A-J - 0x11A, 0x158, 0x14C, 0x146, 0x12C, 0x116, 0x1B4, 0x1B2, 0x1AC, 0x1A6, // K-T - 0x196, 0x19A, 0x16C, 0x166, 0x136, 0x13A, // U-Z - 0x12E, 0x1D4, 0x1D2, 0x1CA, 0x16E, 0x176, 0x1AE, // - - % - 0x126, 0x1DA, 0x1D6, 0x132, 0x15E, // Control chars? $-* - }; - int const CHARACTER_ENCODINGS_LENGTH = - (int)sizeof(CHARACTER_ENCODINGS)/sizeof(CHARACTER_ENCODINGS[0]); - const int ASTERISK_ENCODING = CHARACTER_ENCODINGS[47]; - } - - namespace Code25 { - int const START_PATTERN[4] = { - 1,1,1,1 - }; - int const END_PATTERN[4] = { - 2,1,1 - }; - const int START_PATTERN_A[] = {1, 1}; - const int START_PATTERN_B[] = {1, 1}; - int const NUMBER_ENCODINGS_LEN = 10; - int const NUMBER_ENCODINGS[] = { - 0x6, 0x11, 0x9, 0x18, 0x5, 0x14, 0xC, 0x3, 0x12, 0xA // 0-9 - }; - } - - namespace ITF{ - // Writer - const int START_PATTERN[] = {1, 1, 1, 1}; - const int END_PATTERN[] = {3, 1, 1}; - const int END_PATTERN_LEN = 3; - - // Reader - const int W = 3; // Pixel width of a wide line - const int N = 1; // Pixed width of a narrow line - - const int DEFAULT_ALLOWED_LENGTHS_[] = - { 48, 44, 24, 20, 18, 16, 14, 12, 10, 8, 6 }; - const ArrayRef DEFAULT_ALLOWED_LENGTHS (new Array(VECTOR_INIT(DEFAULT_ALLOWED_LENGTHS_))); - - /** - * Start/end guard pattern. - * - * Note: The end pattern is reversed because the row is reversed before - * searching for the END_PATTERN - */ - const int START_PATTERN_[] = {N, N, N, N}; - const int START_PATTERN_LEN = 4; - const std::vector START_PATTERN_VECTOR (VECTOR_INIT(START_PATTERN_)); - - const int END_PATTERN_REVERSED_[] = {N, N, W}; - const int END_PATTERN_REVERSED_LEN = 3; - const std::vector END_PATTERN_REVERSED (VECTOR_INIT(END_PATTERN_REVERSED_)); - - /** - * Patterns of Wide / Narrow lines to indicate each digit - */ - const int PATTERNS[][5] = { - {N, N, W, W, N}, // 0 - {W, N, N, N, W}, // 1 - {N, W, N, N, W}, // 2 - {W, W, N, N, N}, // 3 - {N, N, W, N, W}, // 4 - {W, N, W, N, N}, // 5 - {N, W, W, N, N}, // 6 - {N, N, N, W, W}, // 7 - {W, N, N, W, N}, // 8 - {N, W, N, W, N} // 9 - }; - - const int PATTERN_ONE_LEN = 5; - - } - - namespace CodaBar{ - // Writer - const char START_END_CHARS[4] = {'A', 'B', 'C', 'D'}; - const char ALT_START_END_CHARS[4] = {'T', 'N', '*', 'E'}; - const char CHARS_WHICH_ARE_TEN_LENGTH_EACH_AFTER_DECODED[4] = {'/', ':', '+', '.'}; - const char DEFAULT_GUARD = START_END_CHARS[0]; - - // Reader - char const ALPHABET_STRING[] = "0123456789-$:/.+ABCD"; - char const* const ALPHABET = ALPHABET_STRING; - - const int ALPHABET_LENGTH = strlen(ALPHABET); - /** - * These represent the encodings of characters, as patterns of wide and narrow bars. The 7 least-significant bits of - * each int correspond to the pattern of wide and narrow, with 1s representing "wide" and 0s representing narrow. - */ - const int CHARACTER_ENCODINGS[] = { - 0x003, 0x006, 0x009, 0x060, 0x012, 0x042, 0x021, 0x024, 0x030, 0x048, // 0-9 - 0x00c, 0x018, 0x045, 0x051, 0x054, 0x015, 0x01A, 0x029, 0x00B, 0x00E, // -$:/.+ABCD - }; - - // minimal number of characters that should be present (inclusing start and stop characters) - // under normal circumstances this should be set to 3, but can be set higher - // as a last-ditch attempt to reduce false positives. - const int MIN_CHARACTER_LENGTH = 3; - - // official start and end patterns - const char STARTEND_ENCODING[] = {'A', 'B', 'C', 'D', 0}; - // some codabar generator allow the codabar string to be closed by every - // character. This will cause lots of false positives! - - // some industries use a checksum standard but this is not part of the original codabar standard - // for more information see : http:// www.mecsw.com/specs/codabar.html - } - } - } -} -#endif diff --git a/modules/objdetect/src/zxing/oned/one_dreader.cpp b/modules/objdetect/src/zxing/oned/one_dreader.cpp deleted file mode 100644 index eff46be5b6..0000000000 --- a/modules/objdetect/src/zxing/oned/one_dreader.cpp +++ /dev/null @@ -1,444 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../zxing.hpp" -#include "../barcode_format.hpp" -#include "one_dreader.hpp" -#include "../reader_exception.hpp" -#include "one_dresult_point.hpp" -#include "../not_found_exception.hpp" -#include -#include - -#include - -using std::vector; -using zxing::Ref; -using zxing::Result; -using zxing::NotFoundException; -using zxing::oned::OneDReader; - -// VC++ -using zxing::BarcodeFormat; - -// VC++ -using zxing::BinaryBitmap; -using zxing::BitArray; -using zxing::DecodeHints; -using zxing::BitMatrix; -using zxing::ErrorHandler; - -OneDReader::OneDReader() { -} - - -Ref OneDReader::decode(Ref image, - DecodeHints hints) { - ErrorHandler err_handler; - Ref rst = doDecode(image, hints, err_handler); - if (err_handler.ErrCode() == 0) - return rst; - else - { - err_handler.Reset(); - bool tryHarder = hints.getTryHarder(); - if (tryHarder && image->isRotateSupported()) - { - Ref rotatedImage(image->rotateCounterClockwise()); - Ref result = doDecode(rotatedImage, hints, err_handler); - if (err_handler.ErrCode()) - return Ref(); - // Doesn't have java metadata stuff - ArrayRef< Ref >& points(result->getResultPoints()); - if (points && !points->empty()) { - int height = rotatedImage->getHeight(); - for (int i = 0; i < points->size(); i++) { - points[i].reset(new OneDResultPoint(height - points[i]->getY() - 1, points[i]->getX())); - } - } - - return result; - } - else - { - return Ref(); - } - } -} - -#include - -Ref OneDReader::doDecode(Ref image, DecodeHints hints, ErrorHandler & err_handler) { - int width = image->getWidth(); - int height = image->getHeight(); - Ref row(new BitArray(width)); - - int middle = height >> 1; - bool tryHarder = hints.getTryHarder(); - int rowStep = (std::max)(1, height >> (tryHarder ? 8 : 5)); - - int maxLines; - if (tryHarder) - { - maxLines = height; // Look at the whole image, not just the center - } - else - { - maxLines = 15; // 15 rows spaced 1/32 apart is roughly the middle half of the image - } - -#ifdef USE_ERROR_CORRECTION - sPreTexts.clear(); - bChecked = false; -#endif - - Ref matrix = image->getBlackMatrix(err_handler); - if (err_handler.ErrCode()) return Ref(); - - // If we need to use getRowRecords or getRowCounterOffsetEnd, we should call initRowCounters first : Valiantliu - matrix->initRowCounters(); - - // -- Attempt - int lastAttempt = -1; - _lastReaderIdx = -1; - bNeedCheck = false; - - for (int x = 0; x < maxLines; x++) { - - // Scanning from the middle out. Determine which row we're looking at next: - int rowStepsAboveOrBelow = (x + 1) >> 1; - bool isAbove = (x & 0x01) == 0; // i.e. is x even? - int rowNumber = middle + rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow); - if (rowNumber < 0 || rowNumber >= height) { - // Oops, if we run off the top or bottom, stop - break; - } - - // Estimate black point for this row and load it: - row = image->getBlackRow(rowNumber, row, err_handler); - if (err_handler.ErrCode()){ - err_handler.Reset(); - continue; - } - - recordAllPattern(matrix, rowNumber, _onedReaderData); - - // To speed up get next sets function - row->initAllNextSets(); - - // While we have the image data in a BitArray, it's fairly cheap to reverse it in place to - // handle decoding upside down barcodes. - int maxAttempt = 2; - int attempts[2] = {0, 1}; - - if (lastAttempt >=0) - { - maxAttempt = 1; - - attempts[0] = lastAttempt; - } - - for (int tA = 0; tA < maxAttempt; tA++) { - int attempt = attempts[tA]; - if (attempt == 1) { - row->reverse(); // reverse the row and continue - - reverseAllPattern(_onedReaderData); - - // To speed up get next sets function - row->initAllNextSets(); - } - - // Java hints stuff missing - - Ref result = decodeRow(rowNumber, row); - - if (result == NULL) { - continue; - } - -#ifdef USE_ERROR_CORRECTION - std::string sCurrBarcodeText = result->getText()->getText(); - - if (sCurrBarcodeText.size() < 14) - // Check result only for UPC-A / UPC-E / ITF / EAN-8, others usually right - { - bChecked = checkResultRight(sPreTexts, sCurrBarcodeText); - - if ((bChecked == false) && (sCurrBarcodeText.size() > 0)) - { - sPreTexts.push_back(sCurrBarcodeText); - - lastAttempt = attempt; - - bNeedCheck = true; - } - - } - // For other barcode format, no need to check - else - { - bChecked = true; - } - - if (bChecked == true) - { - return result; - } -#else - return result; -#endif - } - } - - err_handler = NotFoundErrorHandler("NotFoundErrorHandler"); - return Ref(); -} - - -#ifdef USE_ERROR_CORRECTION -bool OneDReader::checkResultRight(std::vector prevTexts, std::string currText) -{ - // Check if it has a pre result - if ((prevTexts.size() > 0) && (currText.size() > 0)) - { - for (size_t i = 0; i < prevTexts.size(); i++) - { - if (currText == prevTexts.at(i)) - { - return true; - } - } - } - - return false; - -} -#endif - -int OneDReader::patternMatchVariance(vector& counters, - vector const& pattern, - int maxIndividualVariance) { - return patternMatchVariance(counters, &pattern[0], maxIndividualVariance); -} - -int OneDReader::patternMatchVariance(vector& counters, - int const pattern[], - int maxIndividualVariance) { - int numCounters = counters.size(); - unsigned int total = 0; - unsigned int patternLength = 0; - for (int i = 0; i < numCounters; i++) { - total += counters[i]; - patternLength += pattern[i]; - } - if (total < patternLength || patternLength == 0) - { - // If we don't even have one pixel per unit of bar width, assume this is too small - // to reliably match, so fail: - return INT_MAX; - } - // We're going to fake floating-point math in integers. We just need to use more bits. - // Scale up patternLength so that intermediate values below like scaledCounter will have - // more "significant digits" - int unitBarWidth = (total << INTEGER_MATH_SHIFT) / patternLength; - maxIndividualVariance = (maxIndividualVariance * unitBarWidth) >> INTEGER_MATH_SHIFT; - - int totalVariance = 0; - for (int x = 0; x < numCounters; x++) { - int counter = counters[x] << INTEGER_MATH_SHIFT; - int scaledPattern = pattern[x] * unitBarWidth; - int variance = counter > scaledPattern ? counter - scaledPattern : scaledPattern - counter; - if (variance > maxIndividualVariance) { - return INT_MAX; - } - totalVariance += variance; - } - return totalVariance / total; -} - - -// Records the size of successive runs of white and pixels in a row, starting at a given point -// The values are recorded in the given array, and the number of runs records is equal to the size -// of the array. If the row starts on a white pixel at the given start point, then the first count -// recorded is the run of white pixels starting from that point; likewise it is the count of a run -// of black pixels if the row begin on a black pixels at that point. -bool OneDReader::recordPattern(Ref row, - int start, - vector& counters, - ONED_READER_DATA* onedReaderData) { - if (static_cast(onedReaderData->all_counters.size()) != row->getSize()) - recordAllPattern(row, onedReaderData); - - int numCounters = counters.size(); - int counterPosition = 0; - for (int i = 0; i < numCounters; i++) { - counters[i] = 0; - } - int end = row->getSize(); - if (start >= end) { - return false; - } - - int pixel_i = 0; - int all_counters_i = 0; - - // Fix for memory leak by Valiantliu - while (pixel_i < start && all_counters_i < onedReaderData->counter_size-1){ - all_counters_i++; - pixel_i = onedReaderData->all_counters_offsets[all_counters_i]; - } - - if (pixel_i == start){ - for (counterPosition = 0; counterPosition < numCounters; counterPosition++){ - if ((all_counters_i+counterPosition)>=onedReaderData->counter_size) - break; - counters[counterPosition] = onedReaderData->all_counters[all_counters_i+counterPosition]; - } - } - else - { - --all_counters_i; - counters[0]=onedReaderData->all_counters[all_counters_i]-(pixel_i-start); - for (counterPosition=1; counterPosition < numCounters; counterPosition++){ - if ((all_counters_i+counterPosition)>=onedReaderData->counter_size) - break; - counters[counterPosition] = onedReaderData->all_counters[all_counters_i+counterPosition]; - } - } - - if (counters[0]==0) - { - return false; - } - - // If we read fully the last section of pixels and filled up our counters -- or filled - // the last counter but ran off the side of the image, OK. Otherwise, a problem. - if (!(counterPosition == numCounters || - (counterPosition == (numCounters - 1) && counterPosition+all_counters_i == onedReaderData->counter_size-1) - )) - { - return false; - } - - return true; -} - - -void OneDReader::recordAllPattern(Ref matrix, int row_num, ONED_READER_DATA* onedReaderData){ - onedReaderData->counter_size = matrix->getWidth(); - if (static_cast(onedReaderData->all_counters.size()) != onedReaderData->counter_size) - onedReaderData->all_counters.resize(onedReaderData->counter_size, 0); - if (static_cast(onedReaderData->all_counters_offsets.size()) != onedReaderData->counter_size) - onedReaderData->all_counters_offsets.resize(onedReaderData->counter_size, 0); - - COUNTER_TYPE* recorded_counters = matrix->getRowRecords(row_num); - COUNTER_TYPE* recorded_counter_offsets = matrix->getRowRecordsOffset(row_num); - -#ifdef COUNTER_TYPE - for (int i = 0; i < onedReaderData->counter_size; i++){ - onedReaderData->all_counters[i] = static_cast(recorded_counters[i]); - onedReaderData->all_counters_offsets[i] = static_cast(recorded_counter_offsets[i]); - } -#else - memcpy(&onedReaderData->all_counters[0], recorded_counters, onedReaderData->counter_size*sizeof(int)); - memcpy(&onedReaderData->all_counters_offsets[0], recorded_counter_offsets, onedReaderData->counter_size*sizeof(int)); -#endif - - onedReaderData->counter_size = matrix->getRowCounterOffsetEnd(row_num); - onedReaderData->first_is_white = matrix->getRowFirstIsWhite(row_num); - - return; -} - -void OneDReader::recordAllPattern(Ref row, ONED_READER_DATA* onedReaderData){ - onedReaderData->counter_size = row->getSize(); - if (static_cast(onedReaderData->all_counters.size()) != onedReaderData->counter_size) - onedReaderData->all_counters.resize(onedReaderData->counter_size, 0); - if (static_cast(onedReaderData->all_counters_offsets.size()) != onedReaderData->counter_size) - onedReaderData->all_counters_offsets.resize(onedReaderData->counter_size, 0); - - // Modified by Valiantliu : Speed up - memset(&onedReaderData->all_counters[0], 0, onedReaderData->counter_size*sizeof(int)); - memset(&onedReaderData->all_counters_offsets[0], 0, onedReaderData->counter_size*sizeof(int)); - - int end = row->getSize(); - onedReaderData->first_is_white = !row->get(0); - bool isWhite = onedReaderData->first_is_white; - int counterPosition = 0; - int i = 0; - onedReaderData->all_counters_offsets[0] = 0; - - bool* rowBit = row->getRowBoolPtr(); - - while (i < end) { - if (rowBit[i] ^ isWhite) { // that is, exactly one is true - onedReaderData->all_counters[counterPosition]++; - } - else - { - counterPosition++; - if (counterPosition == end) - { - break; - } - else - { - onedReaderData->all_counters[counterPosition] = 1; - isWhite = !isWhite; - onedReaderData->all_counters_offsets[counterPosition]= i; - } - } - - i++; - } - - onedReaderData->counter_size = counterPosition < end? (counterPosition+1):end; - - // If we read fully the last section of pixels and filled up our counters -- or filled - // the last counter but ran off the side of the image, OK. Otherwise, a problem. - if (!(counterPosition == end || (counterPosition == end - 1 && i == end))) { - return; - } -} - -void OneDReader::reverseAllPattern(ONED_READER_DATA* onedReaderData){ - // reverse vector _onedReaderData->all_counters_offsets - int rowsize = onedReaderData->all_counters.size(); - vector all_counters_offset_tmp(onedReaderData->counter_size, 0); - for (int i = 0; i < onedReaderData->counter_size; i++){ - all_counters_offset_tmp[i]=onedReaderData->all_counters_offsets[i]; - } - for (int i=1; i < onedReaderData->counter_size; i++){ - onedReaderData->all_counters_offsets[i]=rowsize-all_counters_offset_tmp[onedReaderData->counter_size-i]; - } - - // reverse vector _onedReaderData->all_counters - for (int i = 0; i < onedReaderData->counter_size/2; i++){ - int tmp=onedReaderData->all_counters[i]; - int reverse_i = onedReaderData->counter_size-i-1; - onedReaderData->all_counters[i]=onedReaderData->all_counters[reverse_i]; - onedReaderData->all_counters[reverse_i] = tmp; - } - - // reverse the bool value: _onedReaderData->first_is_white (if it is necessary) - if (onedReaderData->counter_size%2==0) - onedReaderData->first_is_white = !onedReaderData->first_is_white; -} - -OneDReader::~OneDReader() { -} diff --git a/modules/objdetect/src/zxing/oned/one_dreader.hpp b/modules/objdetect/src/zxing/oned/one_dreader.hpp deleted file mode 100644 index 59e05d1f40..0000000000 --- a/modules/objdetect/src/zxing/oned/one_dreader.hpp +++ /dev/null @@ -1,162 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __ONED_READER_H__ -#define __ONED_READER_H__ - -/* - * OneDReader.hpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../reader.hpp" -#include "../error_handler.hpp" - -// Use error correction for oned barcode -// Added by Skylook -#define USE_PRE_BESTMATCH 1 -#define USE_ERROR_CORRECTION 1 - -namespace zxing { -namespace oned { - -class OneDReader : public Reader { -private: - Ref doDecode(Ref image, DecodeHints hints, ErrorHandler & err_handler); - -protected: - static const int INTEGER_MATH_SHIFT = 8; - - struct Range { - private: - int data[2]; - bool valid; - - public: - Range() { - data[0] = 0; - data[1] = 0; - valid = true; - } - Range(bool valid_){ - data[0] = 0; - data[1] = 1; - valid = valid_; - } - Range(int zero, int one) { - data[0] = zero; - data[1] = one; - valid = true; - } - bool isValid(){ - return valid; - } - int& operator [] (int index) { - return data[index]; - } - int const& operator [] (int index) const { - return data[index]; - } - }; - - static int patternMatchVariance(std::vector& counters, - std::vector const& pattern, - int maxIndividualVariance); - static int patternMatchVariance(std::vector& counters, - int const pattern[], - int maxIndividualVariance); - -protected: - static const int PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << INTEGER_MATH_SHIFT; - -public: - // -- Oned Reader Data : Start -#ifdef USE_PRE_BESTMATCH - struct DigitResultCache - { - int bestMatch[2]; - int counterOffset; - }; - struct DigitResult - { - int bestMatch; - int counterOffset; - }; -#endif - - struct ONED_READER_DATA - { - std::vector all_counters; - std::vector all_counters_offsets; - bool first_is_white; - int counter_size; - - bool ean13_checked; - int ean13_lg_pattern_found; - int ean13_decode_middle_middle_offset; - int ean13_decode_middle_final_offset; - std::string ean13_decode_middle_middle_string; - std::string ean13_decode_middle_final_string; - - std::vector digitResultCache; - }; - - ONED_READER_DATA* _onedReaderData; - - virtual void setData(ONED_READER_DATA* onedReaderData) - { - _onedReaderData = onedReaderData; - }; - // -- Oned Reader Data : End - - OneDReader(); - using Reader::decode; - virtual Ref decode(Ref image, - DecodeHints hints); - - // Implementations must not throw any exceptions. If a barcode is not found on this row, - // a empty ref should be returned e.g. return Ref(); - virtual Ref decodeRow(int rowNumber, Ref row) = 0; - // virtual Ref decodeRow(int rowNumber, Ref row, int readerIdx) = 0; - - static bool recordPattern(Ref row, - int start, - std::vector& counters, - ONED_READER_DATA* onedReaderData); - -#ifdef USE_ERROR_CORRECTION - bool checkResultRight(std::vector prevText, std::string currText); -#endif - - static void recordAllPattern(Ref row, ONED_READER_DATA* onedReaderData); - static void reverseAllPattern(ONED_READER_DATA* onedReaderData); - static void recordAllPattern(Ref matrix, int row_num, ONED_READER_DATA* onedReaderData); - -#ifdef USE_ERROR_CORRECTION - bool bChecked; - Ref preResult; - std::vector sPreTexts; - - int _lastReaderIdx; - bool bNeedCheck; -#endif - - virtual ~OneDReader(); -}; - -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/one_dresult_point.cpp b/modules/objdetect/src/zxing/oned/one_dresult_point.cpp deleted file mode 100644 index 76094ac7f1..0000000000 --- a/modules/objdetect/src/zxing/oned/one_dresult_point.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * OneDResultPoint.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "one_dresult_point.hpp" - -namespace zxing { -namespace oned { - -OneDResultPoint::OneDResultPoint(float posX, float posY) : ResultPoint(posX, posY) { -} -} // namespace oned -} // namespace zxing diff --git a/modules/objdetect/src/zxing/oned/one_dresult_point.hpp b/modules/objdetect/src/zxing/oned/one_dresult_point.hpp deleted file mode 100644 index 34dab79029..0000000000 --- a/modules/objdetect/src/zxing/oned/one_dresult_point.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __ONED_RESULT_POINT_H__ -#define __ONED_RESULT_POINT_H__ -/* - * OneDResultPoint.hpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "../result_point.hpp" -#include - -namespace zxing { -namespace oned { - -class OneDResultPoint : public ResultPoint { -public: - OneDResultPoint(float posX, float posY); -}; -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/upcareader.cpp b/modules/objdetect/src/zxing/oned/upcareader.cpp deleted file mode 100644 index ff0e2c07ea..0000000000 --- a/modules/objdetect/src/zxing/oned/upcareader.cpp +++ /dev/null @@ -1,79 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * UPCAReader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "upcareader.hpp" -#include "../format_exception.hpp" - -using zxing::oned::UPCAReader; -using zxing::Ref; -using zxing::Result; - -// VC++ -using zxing::BitArray; -using zxing::BinaryBitmap; -using zxing::DecodeHints; -using zxing::FormatException; - -UPCAReader::UPCAReader() : ean13Reader() {} - -Ref UPCAReader::decodeRow(int rowNumber, Ref row) { - return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row)); -} - -Ref UPCAReader::decodeRow(int rowNumber, - Ref row, - Range const& startGuardRange) { - return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange)); -} - -Ref UPCAReader::decode(Ref image, DecodeHints hints) { - return maybeReturnResult(ean13Reader.decode(image, hints)); -} - -int UPCAReader::decodeMiddle(Ref row, - Range const& startRange, - std::string& resultString) { - - if (_onedReaderData->ean13_checked){ - resultString = _onedReaderData->ean13_decode_middle_final_string; - return _onedReaderData->ean13_decode_middle_final_offset; - } - - return ean13Reader.decodeMiddle(row, startRange, resultString); -} - -Ref UPCAReader::maybeReturnResult(Ref result) { - const std::string& text = (result->getText())->getText(); - if (text[0] == '0') - { - Ref resultString(new String(text.substr(1))); - Ref res(new Result(resultString, result->getRawBytes(), result->getResultPoints(), - BarcodeFormat::UPC_A)); - return res; - } - else - { - return Ref(); - } -} - -zxing::BarcodeFormat UPCAReader::getBarcodeFormat(){ - return BarcodeFormat::UPC_A; -} diff --git a/modules/objdetect/src/zxing/oned/upcareader.hpp b/modules/objdetect/src/zxing/oned/upcareader.hpp deleted file mode 100644 index fdfae63bb7..0000000000 --- a/modules/objdetect/src/zxing/oned/upcareader.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __UPCA_READER_H__ -#define __UPCA_READER_H__ -/* - * UPCAReader.hpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ean13reader.hpp" -#include "../decode_hints.hpp" -#include "../error_handler.hpp" - -namespace zxing { -namespace oned { - -class UPCAReader : public UPCEANReader { -private: - EAN13Reader ean13Reader; - static Ref maybeReturnResult(Ref result); - -public: - UPCAReader(); - - int decodeMiddle(Ref row, Range const& startRange, std::string& resultString); - - Ref decodeRow(int rowNumber, Ref row); - Ref decodeRow(int rowNumber, Ref row, Range const& startGuardRange); - Ref decode(Ref image, DecodeHints hints); - - BarcodeFormat getBarcodeFormat(); -}; - -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/upceanreader.cpp b/modules/objdetect/src/zxing/oned/upceanreader.cpp deleted file mode 100644 index 9c6d405293..0000000000 --- a/modules/objdetect/src/zxing/oned/upceanreader.cpp +++ /dev/null @@ -1,433 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * UPCEANReader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../zxing.hpp" -#include "upceanreader.hpp" -#include "one_dresult_point.hpp" -#include "../reader_exception.hpp" -#include "../format_exception.hpp" -#include "../not_found_exception.hpp" -#include "../checksum_exception.hpp" - -#include "one_dconstant.hpp" - -using std::vector; -using std::string; - -using zxing::Ref; -using zxing::Result; -using zxing::NotFoundException; -using zxing::ChecksumException; -using zxing::FormatException; -using zxing::oned::UPCEANReader; -using zxing::ErrorHandler; - -// VC++ -using zxing::BitArray; -using zxing::String; - -using namespace zxing::oned::constant::UPCEAN; - -const int UPCEANReader::MAX_AVG_VARIANCE = static_cast(PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.48f); -const int UPCEANReader::MAX_INDIVIDUAL_VARIANCE = static_cast(PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.7f); - -#define VECTOR_INIT(v) v, v + sizeof(v)/sizeof(v[0]) - -const vector -UPCEANReader::START_END_PATTERN (VECTOR_INIT(START_END_PATTERN_)); - -const vector -UPCEANReader::MIDDLE_PATTERN (VECTOR_INIT(MIDDLE_PATTERN_)); -const vector -UPCEANReader::L_PATTERNS (VECTOR_INIT(L_PATTERNS_)); -const vector -UPCEANReader::G_PATTERNS (VECTOR_INIT(G_PATTERNS_)); -const vector -UPCEANReader::L_AND_G_PATTERNS (VECTOR_INIT(L_AND_G_PATTERNS_)); - - -UPCEANReader::UPCEANReader() { - // -- To remember decodeDigit result for L_PATTERNS & L_AND_G_PATTERNS -} - -Ref UPCEANReader::decodeRow(int rowNumber, Ref row) { - ErrorHandler err_handler; - - Ref rst = decodeRow(rowNumber, row, findStartGuardPattern(row, _onedReaderData, err_handler)); - if (err_handler.ErrCode()) return Ref(); - return rst; -} - -#ifdef USE_PRE_BESTMATCH -int UPCEANReader::getCounterOffset(vector counters) -{ - int counterOffset = 0; - - for (int i = 0, e = counters.size(); i < e; i++) { - counterOffset += counters[i]; - } - - return counterOffset; -} -#endif - -#ifdef USE_PRE_BESTMATCH -int UPCEANReader::initbestMatchDigit(Ref row, ONED_READER_DATA* onedReaderData) -{ - // -- To remember decodeDigit result for L_PATTERNS & L_AND_G_PATTERNS - size_t rowLength = row->getSize(); - if (rowLength > onedReaderData->digitResultCache.size()) - { - onedReaderData->digitResultCache.resize(rowLength); - } - - for (size_t i = 0; i < onedReaderData->digitResultCache.size(); i++) - { - onedReaderData->digitResultCache[i].bestMatch[0] = -2; - onedReaderData->digitResultCache[i].bestMatch[1] = -2; - onedReaderData->digitResultCache[i].counterOffset = -1; - } - - return 0; -} -#endif - -Ref UPCEANReader::decodeRow(int rowNumber, - Ref row, - Range const& startGuardRange) { - - string& result = decodeRowStringBuffer; - result.clear(); - int endStart = decodeMiddle(row, startGuardRange, result); - - if (endStart < 0) { - return Ref(NULL); - } - - Range endRange = decodeEnd(row, endStart); - - if (endRange.isValid() == false) - { - return Ref(NULL); - } - - // Make sure there is a quiet zone at least as big as the end pattern after the barcode. - // The spec might want more whitespace, but in practice this is the maximum we can count on. - - int end = endRange[1]; - int quietEnd = end + (end - endRange[0]); - ErrorHandler err_handler; - if (quietEnd >= row->getSize() || !row->isRange(end, quietEnd, false, err_handler)) { - return Ref(NULL); - } - if (err_handler.ErrCode()) return Ref(NULL); - - // https:// code.google.com/p/zxing/issues/detail?id=1736 - // UPC/EAN should never be less than 8 chars anyway - if (result.length() < 8) { - return Ref(NULL); - } - - Ref resultString (new String(result)); - if (!checkChecksum(resultString)) { - return Ref(NULL); - } - - float left = static_cast(startGuardRange[1] + startGuardRange[0]) / 2.0f; - float right = static_cast(endRange[1] + endRange[0]) / 2.0f; - BarcodeFormat format = getBarcodeFormat(); - ArrayRef< Ref > resultPoints(2); - resultPoints[0] = Ref(new OneDResultPoint(left, static_cast(rowNumber))); - resultPoints[1] = Ref(new OneDResultPoint(right, static_cast(rowNumber))); - Ref decodeResult(new Result(resultString, ArrayRef(), resultPoints, format)); - // Java extension and man stuff - return decodeResult; -} - -UPCEANReader::Range UPCEANReader::findStartGuardPattern(Ref row, ONED_READER_DATA* onedReaderData, ErrorHandler &err_handler) { - bool foundStart = false; - Range startRange; - int nextStart = 0; - vector counters(START_END_PATTERN.size(), 0); - - while (!foundStart) { - for (size_t i = 0; i < START_END_PATTERN.size(); ++i) { - counters[i] = 0; - } - startRange = findGuardPattern(row, nextStart, false, START_END_PATTERN, counters, onedReaderData); - if (startRange.isValid() == false) { - return startRange; - } - - int start = startRange[0]; - nextStart = startRange[1]; - // Make sure there is a quiet zone at least as big as the start pattern before the barcode. - // If this check would run off the left edge of the image, do not accept this barcode, - // as it is very likely to be a false positive. - int quietStart = start - (nextStart - start); - if (quietStart >= 0) { - foundStart = row->isRange(quietStart, start, false, err_handler); - if (err_handler.ErrCode()) return startRange; - } - } - return startRange; -} - -UPCEANReader::Range UPCEANReader::findGuardPattern(Ref row, - int rowOffset, - bool whiteFirst, - vector const& pattern, - ONED_READER_DATA* onedReaderData) { - vector counters (pattern.size(), 0); - return findGuardPattern(row, rowOffset, whiteFirst, pattern, counters, onedReaderData); -} - -UPCEANReader::Range UPCEANReader::findGuardPattern(Ref row, - int rowOffset, - bool whiteFirst, - vector const& pattern, - vector& counters, - ONED_READER_DATA* onedReaderData) { - int patternLength = pattern.size(); - int patternStart = whiteFirst ? row->getNextUnset(rowOffset) : row->getNextSet(rowOffset); - if (patternStart == row->getSize()) - { - return UPCEANReader::Range(false); - } - int counterOffset = 0; - int patternOffset = 0; - - while (counterOffsetcounter_size-1&&patternOffsetall_counters_offsets[counterOffset]; - } - - for (int c = counterOffset; c < onedReaderData->counter_size - patternLength + 1; c += 2){ - int x = patternStart; - if (c == counterOffset){ - counters[0] = onedReaderData->all_counters[c] - (patternStart - patternOffset); - x += counters[0]; - for (int ii = 1; ii < patternLength; ii++) { - counters[ii] = onedReaderData->all_counters[c+ii]; - x += counters[ii]; - } - } - else - { - for (int ii = 0; ii < patternLength; ii++){ - counters[ii] = onedReaderData->all_counters[c + ii]; - x += counters[ii]; - } - } - - if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) { - return Range(patternStart, x); - } - patternStart += counters[0] + counters[1]; - } - - return UPCEANReader::Range(false); -} - -UPCEANReader::Range UPCEANReader::decodeEnd(Ref row, int endStart) { - return findGuardPattern(row, endStart, false, START_END_PATTERN, _onedReaderData); -} - -#ifdef USE_PRE_BESTMATCH -UPCEANReader::DigitResult UPCEANReader::decodeDigit(Ref row, - vector & counters, - int rowOffset, - vector const& patterns, - ONED_READER_DATA* onedReaderData) { - - DigitResult digitResult; - - // -- Added by Valiantliu - // -- Speed up if we already have the result - int idxLG = -1; - if (patterns.size() == L_PATTERNS.size()) - { - idxLG = 0; - } - else if (patterns.size() == L_AND_G_PATTERNS.size()) - { - idxLG = 1; - } - else - { - std::cout<<"******************** ERROR HERE!!"<digitResultCache[rowOffset].bestMatch[idxLG]; - int preCounterOffset = onedReaderData->digitResultCache[rowOffset].counterOffset; - - // -- Already has result - if (preBestMatch > -2 && preCounterOffset > -1) - { - digitResult.bestMatch = preBestMatch; - digitResult.counterOffset = preCounterOffset; - - return digitResult; - } - - bool rp = recordPattern(row, rowOffset, counters, onedReaderData); - - if (rp == false) { - digitResult.bestMatch = -1; - digitResult.counterOffset = preCounterOffset; - - return digitResult; - } - - int counterOffset = getCounterOffset(counters); - - int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept - int bestMatch = -1; - - int max = patterns.size(); - - for (int i = 0; i < max; i++) { - int const* pattern(patterns[i]); - int variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE); - if (variance < bestVariance) { - bestVariance = variance; - bestMatch = i; - } - } - onedReaderData->digitResultCache[rowOffset].bestMatch[idxLG] = bestMatch; - - // -- Added by Valiantliu - onedReaderData->digitResultCache[rowOffset].counterOffset = counterOffset; - - digitResult.bestMatch = bestMatch; - digitResult.counterOffset = counterOffset; - - return digitResult; -} -#else -int UPCEANReader::decodeDigit(Ref row, - vector & counters, - int rowOffset, - vector const& patterns, - ErrorHandler & err_handler) { - recordPattern(row, rowOffset, counters); - int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept - int bestMatch = -1; - int max = patterns.size(); - for (int i = 0; i < max; i++) { - int const* pattern(patterns[i]); - int variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE); - if (variance < bestVariance) { - bestVariance = variance; - bestMatch = i; - } - } - - if (bestMatch >= 0) - { - return bestMatch; - } - else - { - err_handler = NotFoundErrorHandler(-1); - return -1; - } -} -#endif - -/** - * @return {@link #checkStandardUPCEANChecksum(String)} - */ -bool UPCEANReader::checkChecksum(Ref const& s) { - return checkStandardUPCEANChecksum(s); -} - -/** - * Computes the UPC/EAN checksum on a string of digits, and reports - * whether the checksum is correct or not. - * - * @param s string of digits to check - * @return true iff string of digits passes the UPC/EAN checksum algorithm - */ -bool UPCEANReader::checkStandardUPCEANChecksum(Ref const& s_) { - std::string const& s (s_->getText()); - int length = s.length(); - if (length == 0) { - return false; - } - - int sum = 0; - for (int i = length - 2; i >= 0; i -= 2) { - int digit = static_cast(s[i]) - static_cast('0'); - if (digit < 0 || digit > 9) { - return false; - } - sum += digit; - } - sum *= 3; - for (int i = length - 1; i >= 0; i -= 2) { - int digit = static_cast(s[i]) - static_cast('0'); - if (digit < 0 || digit > 9) { - return false; - } - sum += digit; - } - return sum % 10 == 0; -} - -/** - * @return {@link #getChecksum(String)} - */ -int UPCEANReader::getChecksum(Ref const& s) { - return getStandardUPCEANChecksum(s); -} - -int UPCEANReader::getStandardUPCEANChecksum(Ref const& s_) -{ - std::string const& s (s_->getText()); - int length = s.length(); - if (length == 0) { - return false; - } - - int sum = 0; - for (int i = length - 1; i >= 0; i -= 2) { - int digit = static_cast(s[i]) - static_cast('0'); - if (digit < 0 || digit > 9) { - return -1; - } - sum += digit; - } - sum *= 3; - for (int i = length - 2; i >= 0; i -= 2) { - int digit = static_cast(s[i]) - static_cast('0'); - if (digit < 0 || digit > 9) { - return -1; - } - sum += digit; - } - return (10 - sum % 10); -} - -UPCEANReader::~UPCEANReader() { -} diff --git a/modules/objdetect/src/zxing/oned/upceanreader.hpp b/modules/objdetect/src/zxing/oned/upceanreader.hpp deleted file mode 100644 index 79aa30730e..0000000000 --- a/modules/objdetect/src/zxing/oned/upceanreader.hpp +++ /dev/null @@ -1,117 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __UPC_EAN_READER_H__ -#define __UPC_EAN_READER_H__ - -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "one_dreader.hpp" -#include "../common/bit_array.hpp" -#include "../result.hpp" -#include "../error_handler.hpp" - -namespace zxing { -namespace oned { - -#define USE_PRE_ROWOFFSET 1 - -class UPCEANReader : public OneDReader { -public: - static bool checkStandardUPCEANChecksum(Ref const& s); - static int getStandardUPCEANChecksum(Ref const& s); - -#ifdef USE_PRE_BESTMATCH - static int getCounterOffset(std::vector counters); -#endif - -private: - std::string decodeRowStringBuffer; - - static const int MAX_AVG_VARIANCE; - static const int MAX_INDIVIDUAL_VARIANCE; - -#ifdef USE_PRE_BESTMATCH - - static int initbestMatchDigit(Ref row, ONED_READER_DATA* onedReaderData); - -#else -#endif - - static Range findStartGuardPattern(Ref row, - ONED_READER_DATA* onedReaderData, - ErrorHandler &err_handler); - - virtual Range decodeEnd(Ref row, int endStart); - - static Range findGuardPattern(Ref row, - int rowOffset, - bool whiteFirst, - std::vector const& pattern, - std::vector& counters, - ONED_READER_DATA* onedReaderData); - - -protected: - static const std::vector START_END_PATTERN; - static const std::vector MIDDLE_PATTERN; - - static const std::vector L_PATTERNS; - static const std::vector G_PATTERNS; - static const std::vector L_AND_G_PATTERNS; - - static Range findGuardPattern(Ref row, - int rowOffset, - bool whiteFirst, - std::vector const& pattern, - ONED_READER_DATA* onedReaderData); - -public: - UPCEANReader(); - - virtual int decodeMiddle(Ref row, - Range const& startRange, - std::string& resultString) = 0; - - virtual Ref decodeRow(int rowNumber, Ref row); - virtual Ref decodeRow(int rowNumber, Ref row, Range const& range); - -#ifdef USE_PRE_BESTMATCH - static DigitResult decodeDigit(Ref row, - std::vector& counters, - int rowOffset, - std::vector const& patterns, - ONED_READER_DATA* onedReaderData); - -#else - static int decodeDigit(Ref row, - std::vector& counters, - int rowOffset, - std::vector const& patterns); -#endif - - virtual bool checkChecksum(Ref const& s); - virtual int getChecksum(Ref const& s); - - virtual BarcodeFormat getBarcodeFormat() = 0; - virtual ~UPCEANReader(); - - friend class MultiFormatUPCEANReader; -}; - -} // namespace oned -} // namespace zxing - -#endif diff --git a/modules/objdetect/src/zxing/oned/upcereader.cpp b/modules/objdetect/src/zxing/oned/upcereader.cpp deleted file mode 100644 index 484dd8b651..0000000000 --- a/modules/objdetect/src/zxing/oned/upcereader.cpp +++ /dev/null @@ -1,188 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../zxing.hpp" -#include "upcereader.hpp" -#include "../reader_exception.hpp" - -using std::string; -using std::vector; -using zxing::Ref; -using zxing::String; -using zxing::oned::UPCEReader; - -// VC++ -using zxing::BitArray; - -#define VECTOR_INIT(v) v, v + sizeof(v)/sizeof(v[0]) - -namespace { -/** - * The pattern that marks the middle, and end, of a UPC-E pattern. - * There is no "second half" to a UPC-E barcode. - */ -const int MIDDLE_END_PATTERN_[6] = {1, 1, 1, 1, 1, 1}; -const vector MIDDLE_END_PATTERN (VECTOR_INIT(MIDDLE_END_PATTERN_)); - - -/** - * See {@link #L_AND_G_PATTERNS}; these values similarly represent patterns of - * even-odd parity encodings of digits that imply both the number system (0 or 1) - * used, and the check digit. - */ -const int NUMSYS_AND_CHECK_DIGIT_PATTERNS[2][10] = { - {0x38, 0x34, 0x32, 0x31, 0x2C, 0x26, 0x23, 0x2A, 0x29, 0x25}, - {0x07, 0x0B, 0x0D, 0x0E, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A} -}; -} // namespace - -UPCEReader::UPCEReader() { -} - -int UPCEReader::decodeMiddle(Ref row, Range const& startRange, string& result) { - - if (_onedReaderData->ean13_checked){ - result = _onedReaderData->ean13_decode_middle_middle_string; - int rowOffset = _onedReaderData->ean13_decode_middle_middle_offset; - int lgPatternFound = _onedReaderData->ean13_lg_pattern_found; - determineNumSysAndCheckDigit(result, lgPatternFound); - return rowOffset; - } - vector& counters (decodeMiddleCounters); - counters.clear(); - counters.resize(4); - int end = row->getSize(); - int rowOffset = startRange[1]; - - int lgPatternFound = 0; - - for (int x = 0; x < 6 && rowOffset < end; x++) { -#ifdef USE_PRE_BESTMATCH - DigitResult digitResult = decodeDigit(row, counters, rowOffset, L_AND_G_PATTERNS, _onedReaderData); - int bestMatch = digitResult.bestMatch; - int counterOffset = digitResult.counterOffset; -#else - int bestMatch = decodeDigit(row, counters, rowOffset, L_AND_G_PATTERNS); -#endif - - // To decrease throw times, use this instead - if (bestMatch < 0) { - return -1; - } - - result.append(1, static_cast('0' + bestMatch % 10)); - -#ifdef USE_PRE_BESTMATCH - rowOffset += counterOffset; -#else - for (int i = 0, e = counters.size(); i < e; i++) { - rowOffset += counters[i]; - } -#endif - if (bestMatch >= 10) { - lgPatternFound |= 1 << (5 - x); - } - } - - determineNumSysAndCheckDigit(result, lgPatternFound); - - return rowOffset; -} - -UPCEReader::Range UPCEReader::decodeEnd(Ref row, int endStart) { - return findGuardPattern(row, endStart, true, MIDDLE_END_PATTERN, _onedReaderData); -} - -bool UPCEReader::checkChecksum(Ref const& s){ - // Special check for UPC-E - // System code must be 0 or 1 - // http:// www.barcodeisland.com/upce.phtml - // By Skylook - - string const& upce(s->getText()); - char firstChar = upce[0]; - - // Additionally, UPC-E may only be used if the number system is 0 or 1. - if (firstChar == '0' || firstChar == '1') - { - Ref sa = convertUPCEtoUPCA(s); - return UPCEANReader::checkChecksum(sa); - } - else - { - return false; - } -} - - -bool UPCEReader::determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound) { - for (int numSys = 0; numSys <= 1; numSys++) { - for (int d = 0; d < 10; d++) { - if (lgPatternFound == NUMSYS_AND_CHECK_DIGIT_PATTERNS[numSys][d]) { - resultString.insert((string::size_type)0, (string::size_type)1, static_cast('0' + numSys)); - resultString.append(1, static_cast('0' + d)); - return true; - } - } - } - return false; -} - -/** - * Expands a UPC-E value back into its full, equivalent UPC-A code value. - * - * @param upce UPC-E code as string of digits - * @return equivalent UPC-A code as string of digits - */ -Ref UPCEReader::convertUPCEtoUPCA(Ref const& upce_) { - - string const& upce(upce_->getText()); - string result; - result.append(1, upce[0]); - char lastChar = upce[6]; - switch (lastChar) { - case '0': - case '1': - case '2': - result.append(upce.substr(1, 2)); - result.append(1, lastChar); - result.append("0000"); - result.append(upce.substr(3, 3)); - break; - case '3': - result.append(upce.substr(1, 3)); - result.append("00000"); - result.append(upce.substr(4, 2)); - break; - case '4': - result.append(upce.substr(1, 4)); - result.append("00000"); - result.append(1, upce[5]); - break; - default: - result.append(upce.substr(1, 5)); - result.append("0000"); - result.append(1, lastChar); - break; - } - result.append(1, upce[7]); - return Ref(new String(result)); -} - -zxing::BarcodeFormat UPCEReader::getBarcodeFormat() { - return BarcodeFormat::UPC_E; -} diff --git a/modules/objdetect/src/zxing/oned/upcereader.hpp b/modules/objdetect/src/zxing/oned/upcereader.hpp deleted file mode 100644 index 6d6c72a5ac..0000000000 --- a/modules/objdetect/src/zxing/oned/upcereader.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __UPC_E_READER_H__ -#define __UPC_E_READER_H__ - -/* - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http:// www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "upceanreader.hpp" -#include "../result.hpp" - -namespace zxing { -namespace oned { - -class UPCEReader : public UPCEANReader { -private: - std::vector decodeMiddleCounters; - static bool determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound); - -protected: - Range decodeEnd(Ref row, int endStart); - bool checkChecksum(Ref const& s); - -public: - UPCEReader(); - - int decodeMiddle(Ref row, Range const& startRange, std::string& resultString); - static Ref convertUPCEtoUPCA(Ref const& upce); - - BarcodeFormat getBarcodeFormat(); -}; - -} -} - -#endif diff --git a/modules/objdetect/src/zxing/pdf417/decoder/bit_matrix_parser.cpp b/modules/objdetect/src/zxing/pdf417/decoder/bit_matrix_parser.cpp index c1040cdce7..6276a97891 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/bit_matrix_parser.cpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/bit_matrix_parser.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2008-2012 ZXing authors All rights reserved. @@ -87,12 +97,12 @@ ErrorHandler BitMatrixParser::readCodewords(ArrayRef & ret_array) } // Process Row err_handler = processRow(rowNumber, codewords, next, next); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; rowNumber++; } err_handler = trimArray(erasures_, eraseCount_, erasures_); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; err_handler = trimArray(codewords, next, ret_array); return err_handler; @@ -182,7 +192,7 @@ ErrorHandler BitMatrixParser::processRow(int rowNumber, ArrayRef codewords, } } // 2012-06-22 hfn: verify whether outer columns are still okay: - if (!VerifyOuterColumns(rowNumber)) + if (!verifyOuterColumns(rowNumber)) { return FormatErrorHandler("BitMatrixParser::processRow(PDF417): outer columns corrupted!"); } @@ -283,18 +293,18 @@ int BitMatrixParser::findCodewordIndex(int64_t symbol) /* * 2012-06-22 hfn additional verification of outer columns */ -bool BitMatrixParser::VerifyOuterColumns(int rownumber) +bool BitMatrixParser::verifyOuterColumns(int rownumber) { - return IsEqual(aLeftColumnTriple_[0], aRightColumnTriple_[1], rownumber) - && IsEqual(aLeftColumnTriple_[1], aRightColumnTriple_[2], rownumber) - && IsEqual(aLeftColumnTriple_[2], aRightColumnTriple_[0], rownumber); + return isEqual(aLeftColumnTriple_[0], aRightColumnTriple_[1], rownumber) + && isEqual(aLeftColumnTriple_[1], aRightColumnTriple_[2], rownumber) + && isEqual(aLeftColumnTriple_[2], aRightColumnTriple_[0], rownumber); } /* * Verifies whether two codewords are equal or at least one of the codewords has not * been recognized. */ -bool BitMatrixParser::IsEqual(int &a, int &b, int rownumber) +bool BitMatrixParser::isEqual(int &a, int &b, int rownumber) { int ret = (a == b) || (a == -1) || (b == -1); if (!ret) { diff --git a/modules/objdetect/src/zxing/pdf417/decoder/bit_matrix_parser.hpp b/modules/objdetect/src/zxing/pdf417/decoder/bit_matrix_parser.hpp index 4e41852026..06b67b2b08 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/bit_matrix_parser.hpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/bit_matrix_parser.hpp @@ -1,5 +1,15 @@ -#ifndef __BIT_MATRIX_PARSER__PDF_H__ -#define __BIT_MATRIX_PARSER__PDF_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_PDF417_DECODER_BIT_MATRIX_PARSER_HPP__ +#define __ZXING_PDF417_DECODER_BIT_MATRIX_PARSER_HPP__ /* * BitMatrixParser.hpp / PDF417 @@ -65,7 +75,7 @@ public: static int getCodeword(int64_t symbol, int *pi = NULL); private: - bool VerifyOuterColumns(int rownumber); + bool verifyOuterColumns(int rownumber); static zxing::ErrorHandler trimArray(ArrayRef array, int size, ArrayRef & ret_array); static int findCodewordIndex(int64_t symbol); @@ -76,11 +86,11 @@ private: ArrayRef codewords, int next, int &ret_next); protected: - bool IsEqual(int &a, int &b, int rownumber); + bool isEqual(int &a, int &b, int rownumber); }; } // namespace decoder } // namespace pdf417 } // namespace zxing -#endif // __BIT_MATRIX_PARSER__PDF_H__ +#endif // __ZXING_PDF417_DECODER_BIT_MATRIX_PARSER_HPP__ diff --git a/modules/objdetect/src/zxing/pdf417/decoder/decoded_bit_stream_parser.cpp b/modules/objdetect/src/zxing/pdf417/decoder/decoded_bit_stream_parser.cpp index 7734dfadf2..c490fc5d48 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/decoded_bit_stream_parser.cpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/decoded_bit_stream_parser.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2010, 2012 ZXing authors All rights reserved. @@ -96,7 +106,7 @@ Ref DecodedBitStreamParser::decode(ArrayRef codewords, Error break; case NUMERIC_COMPACTION_MODE_LATCH: codeIndex = numericCompaction(codewords, codeIndex, result, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return Ref(); break; case MODE_SHIFT_TO_BYTE_COMPACTION_MODE: @@ -588,7 +598,7 @@ int DecodedBitStreamParser::numericCompaction(ArrayRef codewords, // current Numeric Compaction mode grouping as described in 5.4.4.2, // and then to start a new one grouping. Ref s = decodeBase900toBase10(numericCodewords, count, err_handler); - if (err_handler.ErrCode() || s == NULL) + if (err_handler.errCode() || s == NULL) { return -1; } diff --git a/modules/objdetect/src/zxing/pdf417/decoder/decoded_bit_stream_parser.hpp b/modules/objdetect/src/zxing/pdf417/decoder/decoded_bit_stream_parser.hpp index 389ecc62a6..5f0b81382b 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/decoded_bit_stream_parser.hpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/decoded_bit_stream_parser.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __DECODED_BIT_STREAM_PARSER_PD_H__ -#define __DECODED_BIT_STREAM_PARSER_PD_H__ +#ifndef __ZXING_PDF417_DECODER_DECODED_BIT_STREAM_PARSER_HPP__ +#define __ZXING_PDF417_DECODER_DECODED_BIT_STREAM_PARSER_HPP__ /* * Copyright 2010 ZXing authors All rights reserved. @@ -80,4 +90,4 @@ public: } // namespace pdf417 } // namespace zxing -#endif // __DECODED_BIT_STREAM_PARSER_PD_H__ +#endif // __ZXING_PDF417_DECODER_DECODED_BIT_STREAM_PARSER_HPP__ diff --git a/modules/objdetect/src/zxing/pdf417/decoder/decoder.cpp b/modules/objdetect/src/zxing/pdf417/decoder/decoder.cpp index 917afddbf7..901b881168 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/decoder.cpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/decoder.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2010, 2012 ZXing authors All rights reserved. @@ -51,7 +61,7 @@ Ref Decoder::decode(Ref bits, DecodeHints const& hints ArrayRef codewords; err_handler = parser.readCodewords(codewords); - if (err_handler.ErrCode() || codewords == NULL) { + if (err_handler.errCode() || codewords == NULL) { err_handler = FormatErrorHandler("PDF:Decoder:decode: cannot read codewords"); return Ref(); } @@ -61,15 +71,15 @@ Ref Decoder::decode(Ref bits, DecodeHints const& hints ArrayRef erasures = parser.getErasures(); correctErrors(codewords, erasures, numECCodewords, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); verifyCodewordCount(codewords, numECCodewords, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); // Decode the codewords DecodedBitStreamParser dbs_parser; Ref rst = dbs_parser.decode(codewords, err_handler); - if (err_handler.ErrCode() || NULL == rst){ + if (err_handler.errCode() || NULL == rst){ err_handler = FormatErrorHandler("PDF:Decoder:decode: cannot read codewords"); return Ref(); } @@ -100,7 +110,7 @@ void Decoder::verifyCodewordCount(ArrayRef codewords, int numECCodewords, E return; } if (numberOfCodewords == 0) { - // Reset to the length of the array - 8 (Allow for at least level 3 Error Correction (8 Error Codewords) + // reset to the length of the array - 8 (Allow for at least level 3 Error Correction (8 Error Codewords) if (numECCodewords < cwsize) { codewords[0] = cwsize - numECCodewords; } @@ -129,7 +139,7 @@ void Decoder::correctErrors(ArrayRef codewords, Ref errorCorrection(new ErrorCorrection); errorCorrection->decode(codewords, numECCodewords, erasures, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return; // 2012-06-27 HFN if, despite of error correction, there are still codewords with invalid diff --git a/modules/objdetect/src/zxing/pdf417/decoder/decoder.hpp b/modules/objdetect/src/zxing/pdf417/decoder/decoder.hpp index 89602dab62..cc864837b7 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/decoder.hpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/decoder.hpp @@ -1,5 +1,15 @@ -#ifndef __DECOCER_PDF_H__ -#define __DECOCER_PDF_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_PDF417_DECODER_DECOCER_HPP__ +#define __ZXING_PDF417_DECODER_DECOCER_HPP__ /* * Decoder.hpp @@ -58,4 +68,4 @@ public: } // namespace pdf417 } // namespace zxing -#endif // __DECOCER_PDF_H__ +#endif // __ZXING_PDF417_DECODER_DECOCER_HPP__ diff --git a/modules/objdetect/src/zxing/pdf417/decoder/ec/error_correction.cpp b/modules/objdetect/src/zxing/pdf417/decoder/ec/error_correction.cpp index 1cab480877..4f58083442 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/ec/error_correction.cpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/ec/error_correction.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2012 ZXing authors @@ -50,7 +60,7 @@ void ErrorCorrection::decode(ArrayRef received, ErrorHandler & err_handler) { Ref poly (new ModulusPoly(field_, received, err_handler)); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; ArrayRef S(new Array(numECCodewords)); bool error = false; @@ -71,33 +81,33 @@ void ErrorCorrection::decode(ArrayRef received, one_minus_b_x[1]=field_.subtract(0, b); one_minus_b_x[0] = 1; Ref term (new ModulusPoly(field_, one_minus_b_x, err_handler)); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; knownErrors = knownErrors->multiply(term, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } Ref syndrome (new ModulusPoly(field_, S, err_handler)); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; Ref tmp = field_.buildMonomial(numECCodewords, 1, err_handler); - if (err_handler.ErrCode() || tmp == NULL) return; + if (err_handler.errCode() || tmp == NULL) return; vector > sigmaOmega (runEuclideanAlgorithm(tmp, syndrome, numECCodewords, err_handler)); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; Ref sigma = sigmaOmega[0]; Ref omega = sigmaOmega[1]; ArrayRef errorLocations = findErrorLocations(sigma, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; ArrayRef errorMagnitudes = findErrorMagnitudes(omega, sigma, errorLocations, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; for (int i = 0; i < errorLocations->size(); i++) { int ret_val = field_.log(errorLocations[i], err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; int position = received->size() - 1 - ret_val; if (position < 0) { @@ -140,33 +150,33 @@ vector > ErrorCorrection::runEuclideanAlgorithm(Ref q (field_.getZero()); int denominatorLeadingTerm = rLast->getCoefficient(rLast->getDegree()); int dltInverse = field_.inverse(denominatorLeadingTerm, err_handler); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); while (r->getDegree() >= rLast->getDegree() && !r->isZero()) { int degreeDiff = r->getDegree() - rLast->getDegree(); int scale = field_.multiply(r->getCoefficient(r->getDegree()), dltInverse); Ref tmp = field_.buildMonomial(degreeDiff, scale, err_handler); - if (err_handler.ErrCode() || tmp == NULL) return vector >(); + if (err_handler.errCode() || tmp == NULL) return vector >(); q = q->add(tmp, err_handler); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); Ref tmp1 = rLast->multiplyByMonomial(degreeDiff, scale, err_handler); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); r = r->subtract(tmp1, err_handler); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); } Ref tmp1 = q->multiply(tLast, err_handler); - if (err_handler.ErrCode() || tmp1 == NULL) return vector >(); + if (err_handler.errCode() || tmp1 == NULL) return vector >(); tmp1 = tmp1->subtract(tLastLast, err_handler); - if (err_handler.ErrCode() || tmp1 == NULL) return vector >(); + if (err_handler.errCode() || tmp1 == NULL) return vector >(); t = tmp1->negative(err_handler); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); } int sigmaTildeAtZero = t->getCoefficient(0); @@ -176,13 +186,13 @@ vector > ErrorCorrection::runEuclideanAlgorithm(Ref >(); + if (err_handler.errCode()) return vector >(); Ref sigma (t->multiply(inverse, err_handler)); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); Ref omega (r->multiply(inverse, err_handler)); - if (err_handler.ErrCode()) return vector >(); + if (err_handler.errCode()) return vector >(); vector > v(2); v[0] = sigma; @@ -198,7 +208,7 @@ ArrayRef ErrorCorrection::findErrorLocations(Ref errorLocator, for (int i = 1; i < field_.getSize() && e < numErrors; i++) { if (errorLocator->evaluateAt(i) == 0) { result[e] = field_.inverse(i, err_handler); - if (err_handler.ErrCode()) return ArrayRef(); + if (err_handler.errCode()) return ArrayRef(); e++; } @@ -223,18 +233,18 @@ ArrayRef ErrorCorrection::findErrorMagnitudes(Ref errorEvaluat field_.multiply(i, errorLocator->getCoefficient(i)); } Ref formalDerivative (new ModulusPoly(field_, formalDerivativeCoefficients, err_handler)); - if (err_handler.ErrCode()) return ArrayRef(); + if (err_handler.errCode()) return ArrayRef(); // This is directly applying Forney's Formula int s = errorLocations->size(); ArrayRef result(new Array(s)); for (i = 0; i < s; i++) { int xiInverse = field_.inverse(errorLocations[i], err_handler); - if (err_handler.ErrCode()) return ArrayRef(); + if (err_handler.errCode()) return ArrayRef(); int numerator = field_.subtract(0, errorEvaluator->evaluateAt(xiInverse)); int denominator = field_.inverse(formalDerivative->evaluateAt(xiInverse), err_handler); - if (err_handler.ErrCode()) return ArrayRef(); + if (err_handler.errCode()) return ArrayRef(); result[i] = field_.multiply(numerator, denominator); } diff --git a/modules/objdetect/src/zxing/pdf417/decoder/ec/error_correction.hpp b/modules/objdetect/src/zxing/pdf417/decoder/ec/error_correction.hpp index abca996281..2d90602d87 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/ec/error_correction.hpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/ec/error_correction.hpp @@ -1,7 +1,17 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __ERROR_CORRECTION_PDF_H__ -#define __ERROR_CORRECTION_PDF_H__ +#ifndef __ZXING_PDF417_DECODER_EC_ERROR_CORRECTION_HPP__ +#define __ZXING_PDF417_DECODER_EC_ERROR_CORRECTION_HPP__ /* * Copyright 2012 ZXing authors * @@ -69,4 +79,4 @@ private: } // namespace pdf417 } // namespace zxing -#endif /* __ERROR_CORRECTION_PDF_H__ */ +#endif // __ZXING_PDF417_DECODER_EC_ERROR_CORRECTION_HPP__ diff --git a/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_gf.cpp b/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_gf.cpp index 02e9392c0b..199532bbe3 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_gf.cpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_gf.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2012 ZXing authors @@ -49,10 +59,10 @@ ModulusGF::ModulusGF(int modulus, int generator, ErrorHandler & err_handler) ArrayRefaZero(new Array(1)), aOne(new Array(1)); aZero[0] = 0; aOne[0] = 1; zero_ = new ModulusPoly(*this, aZero, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; one_ = new ModulusPoly(*this, aOne, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } Ref ModulusGF::getZero() { @@ -76,7 +86,7 @@ Ref ModulusGF::buildMonomial(int degree, int coefficient, ErrorHand ArrayRef coefficients(new Array(nCoefficients)); coefficients[0] = coefficient; Ref result(new ModulusPoly(*this, coefficients, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return result; } diff --git a/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_gf.hpp b/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_gf.hpp index 60b370e839..306d197ff5 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_gf.hpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_gf.hpp @@ -1,5 +1,15 @@ -#ifndef __MODULUS_GF_PDF_H__ -#define __MODULUS_GF_PDF_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_PDF417_DECODER_EC_MODULUS_GF_HPP__ +#define __ZXING_PDF417_DECODER_EC_MODULUS_GF_HPP__ /* * Copyright 2012 ZXing authors * @@ -73,4 +83,4 @@ public: } // namespace pdf417 } // namespace zxing -#endif /* __MODULUS_GF_PDF_H__ */ +#endif // __ZXING_PDF417_DECODER_EC_MODULUS_GF_HPP__ diff --git a/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_poly.cpp b/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_poly.cpp index e1ffaa8c31..901d7efca3 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_poly.cpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_poly.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2012 ZXing authors @@ -148,7 +158,7 @@ Ref ModulusPoly::add(Ref other, ErrorHandler & err_han } Ref tmp(new ModulusPoly(field_, sumDiff, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return tmp; } @@ -163,10 +173,10 @@ Ref ModulusPoly::subtract(Ref other, ErrorHandler & er } Ref tmp = other->negative(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); tmp = add(tmp, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return tmp; } @@ -192,7 +202,7 @@ Ref ModulusPoly::multiply(Ref other, ErrorHandler & er } Ref tmp(new ModulusPoly(field_, product, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return tmp; } @@ -205,7 +215,7 @@ Ref ModulusPoly::negative(ErrorHandler & err_handler) { } Ref tmp(new ModulusPoly(field_, negativeCoefficients, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return tmp; } @@ -224,7 +234,7 @@ Ref ModulusPoly::multiply(int scalar, ErrorHandler & err_handler) { } Reftmp(new ModulusPoly(field_, product, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return tmp; } @@ -244,7 +254,7 @@ Ref ModulusPoly::multiplyByMonomial(int degree, int coefficient, Er } Ref tmp(new ModulusPoly(field_, product, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return tmp; } @@ -264,22 +274,22 @@ std::vector > ModulusPoly::divide(Ref other, Error int denominatorLeadingTerm = other->getCoefficient(other->getDegree()); int inverseDenominatorLeadingTerm = field_.inverse(denominatorLeadingTerm, err_handler); - if (err_handler.ErrCode()) return std::vector >(); + if (err_handler.errCode()) return std::vector >(); while (remainder->getDegree() >= other->getDegree() && !remainder->isZero()) { int degreeDifference = remainder->getDegree() - other->getDegree(); int scale = field_.multiply(remainder->getCoefficient(remainder->getDegree()), inverseDenominatorLeadingTerm); Ref term (other->multiplyByMonomial(degreeDifference, scale, err_handler)); - if (err_handler.ErrCode()) return std::vector >(); + if (err_handler.errCode()) return std::vector >(); Ref iterationQuotient (field_.buildMonomial(degreeDifference, scale, err_handler)); - if (err_handler.ErrCode()) return std::vector >(); + if (err_handler.errCode()) return std::vector >(); quotient = quotient->add(iterationQuotient, err_handler); - if (err_handler.ErrCode()) return std::vector >(); + if (err_handler.errCode()) return std::vector >(); remainder = remainder->subtract(term, err_handler); - if (err_handler.ErrCode()) return std::vector >(); + if (err_handler.errCode()) return std::vector >(); } std::vector > result(2); diff --git a/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_poly.hpp b/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_poly.hpp index 92a90723ea..6f41221112 100644 --- a/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_poly.hpp +++ b/modules/objdetect/src/zxing/pdf417/decoder/ec/modulus_poly.hpp @@ -1,5 +1,15 @@ -#ifndef __MODULUS_GFPOLY_PDF_H__ -#define __MODULUS_GFPOLY_PDF_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_PDF417_DECODER_EC_MODULUS_GFPOLY_HPP__ +#define __ZXING_PDF417_DECODER_EC_MODULUS_GFPOLY_HPP__ /* * Copyright 2012 ZXing authors @@ -63,4 +73,4 @@ public: } // namespace pdf417 } // namespace zxing -#endif /* __MODULUS_GFPOLY_PDF_H__ */ +#endif // __ZXING_PDF417_DECODER_EC_MODULUS_GFPOLY_HPP__ diff --git a/modules/objdetect/src/zxing/pdf417/detector/detector.cpp b/modules/objdetect/src/zxing/pdf417/detector/detector.cpp index e6ebe1a708..7989b3cd0d 100644 --- a/modules/objdetect/src/zxing/pdf417/detector/detector.cpp +++ b/modules/objdetect/src/zxing/pdf417/detector/detector.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2010 ZXing authors All rights reserved. @@ -92,7 +102,7 @@ ErrorHandler Detector::detect(DecodeHints const& hints, Ref & de // Fetch the 1 bit matrix once up front. ErrorHandler err_handler; Ref matrix = image_->getBlackMatrix(err_handler); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; // Try to find the vertices assuming the image is upright. const int rowStep = 8; @@ -103,13 +113,13 @@ ErrorHandler Detector::detect(DecodeHints const& hints, Ref & de vertices = findVertices180(matrix, rowStep); if (vertices) { err_handler = correctVertices(matrix, vertices, true); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; } } else { err_handler = correctVertices(matrix, vertices, false); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; } @@ -146,7 +156,7 @@ ErrorHandler Detector::detect(DecodeHints const& hints, Ref & de // Deskew and sample lines from image. Ref linesMatrix = sampleLines(vertices, dimension, yDimension, err_handler); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; ArrayRef< Ref > points(4); points[0] = vertices[5]; @@ -174,7 +184,7 @@ ErrorHandler Detector::detect(DecodeHints const& hints, Ref & de * vertices[6] x, y top right codeword area * vertices[7] x, y bottom right codeword area */ -ArrayRef< Ref > Detector::FindRowsWithPattern(Ref matrix, +ArrayRef< Ref > Detector::findRowsWithPattern(Ref matrix, int startRow, int startColumn, const int pattern[], const int patternSize){ @@ -252,14 +262,14 @@ ArrayRef< Ref > Detector::FindRowsWithPattern(Ref matrix return result; } -ArrayRef< Ref > Detector::FindVerticesNew(Ref matrix) +ArrayRef< Ref > Detector::findVerticesNew(Ref matrix) { int startRow = 0; int startColumn = 0; ArrayRef< Ref > result(16); copyToResult(result, - FindRowsWithPattern(matrix, startRow, startColumn, + findRowsWithPattern(matrix, startRow, startColumn, START_PATTERN, START_PATTERN_LENGTH), INDEXES_START_PATTERN, INDEXES_START_PATTERN_LENGTH); @@ -267,7 +277,7 @@ ArrayRef< Ref > Detector::FindVerticesNew(Ref matrix) startColumn = static_cast(result[4]->getX()); startRow = static_cast(result[4]->getY()); } - copyToResult(result, FindRowsWithPattern(matrix, startRow, startColumn, + copyToResult(result, findRowsWithPattern(matrix, startRow, startColumn, STOP_PATTERN, STOP_PATTERN_LENGTH), INDEXES_STOP_PATTERN, INDEXES_STOP_PATTERN_LENGTH); if (result[0] && result[1] && result[2] && result[3]) return result; @@ -562,13 +572,13 @@ ErrorHandler Detector::correctVertices(Ref matrix, findWideBarTopBottom(matrix, vertices, 2, 11, 7, 18, upsideDown ? 1 : -1); findWideBarTopBottom(matrix, vertices, 3, 11, 7, 18, upsideDown ? -1 : 1); err_handler = findCrossingPoint(vertices, 12, 4, 5, 8, 10, matrix); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; err_handler = findCrossingPoint(vertices, 13, 4, 5, 9, 11, matrix); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; err_handler = findCrossingPoint(vertices, 14, 6, 7, 8, 10, matrix); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; err_handler = findCrossingPoint(vertices, 15, 6, 7, 9, 11, matrix); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; } return err_handler; @@ -819,7 +829,7 @@ Ref Detector::sampleLines(ArrayRef< Ref > const& vertice Ref bitstmp = image_->getBlackMatrix(err_handler); Ref linesMatrix = GridSampler::getInstance().sampleGrid(bitstmp, sampleDimensionX, sampleDimensionY, transform, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return linesMatrix; diff --git a/modules/objdetect/src/zxing/pdf417/detector/detector.hpp b/modules/objdetect/src/zxing/pdf417/detector/detector.hpp index 2ea576b663..cd905825c9 100644 --- a/modules/objdetect/src/zxing/pdf417/detector/detector.hpp +++ b/modules/objdetect/src/zxing/pdf417/detector/detector.hpp @@ -1,5 +1,15 @@ -#ifndef __DETECTOR_H__ -#define __DETECTOR_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_PDF417_DETECTOR_DETECTOR_HPP__ +#define __ZXING_PDF417_DETECTOR_DETECTOR_HPP__ /* * Detector.hpp @@ -105,11 +115,11 @@ private: Ref sampleLines(ArrayRef< Ref > const& vertices, int dimensionY, int dimension, ErrorHandler & err_handler); - ArrayRef< Ref > FindRowsWithPattern(Ref matrix, + ArrayRef< Ref > findRowsWithPattern(Ref matrix, int startRow, int startColumn, const int pattern[], const int patternSize); - ArrayRef< Ref > FindVerticesNew(Ref matrix); + ArrayRef< Ref > findVerticesNew(Ref matrix); void copyToResult(ArrayRef< Ref > result, ArrayRef< Ref > tmpResult, const int* destinationIndexes, int iLength); @@ -126,4 +136,4 @@ public: } // namespace pdf417 } // namespace zxing -#endif // __DETECTOR_H__ +#endif // __ZXING_PDF417_DETECTOR_DETECTOR_HPP__ diff --git a/modules/objdetect/src/zxing/pdf417/detector/lines_sampler.cpp b/modules/objdetect/src/zxing/pdf417/detector/lines_sampler.cpp index 979e8ebfb3..ffe1313c80 100644 --- a/modules/objdetect/src/zxing/pdf417/detector/lines_sampler.cpp +++ b/modules/objdetect/src/zxing/pdf417/detector/lines_sampler.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2010, 2012 ZXing authors All rights reserved. @@ -131,7 +141,7 @@ m_vcVotes(vcVotes) } } -int PossibleCodeWords::GetNextPossible(std::vector > &vcCodeWords) +int PossibleCodeWords::getNextPossible(std::vector > &vcCodeWords) { int iListSize = m_vcBadPointList.size(); vcCodeWords = m_vcCodeWords; @@ -209,7 +219,7 @@ LinesSampler::LinesSampler(Ref linesMatrix, int dimension) RATIOS_TABLE = init_ratios_table(); } -void LinesSampler::SetLineMatrix(Ref linesMatrix) +void LinesSampler::setLineMatrix(Ref linesMatrix) { linesMatrix_ = linesMatrix; } @@ -232,7 +242,7 @@ ErrorHandler LinesSampler::sample(Ref & bit_matrix) { vector > codewords(linesMatrix_->getHeight()); vector > clusterNumbers(linesMatrix_->getHeight()); err_handler = linesMatrixToCodewords(clusterNumbers, symbolsPerLine, symbolWidths, linesMatrix_, codewords); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; vector > > votes = distributeVotes(symbolsPerLine, codewords, clusterNumbers); @@ -267,7 +277,7 @@ ErrorHandler LinesSampler::sample(Ref & bit_matrix) { // XXX Ref grid(new BitMatrix(dimension_, detectedCodeWords.size(), err_handler)); - if (err_handler.ErrCode()) return err_handler; + if (err_handler.errCode()) return err_handler; codewordsToBitMatrix(detectedCodeWords, grid); @@ -275,13 +285,13 @@ ErrorHandler LinesSampler::sample(Ref & bit_matrix) { return err_handler; } -Ref LinesSampler::GetNextPossibleGrid(ErrorHandler & err_handler) +Ref LinesSampler::getNextPossibleGrid(ErrorHandler & err_handler) { if (m_ptPossibleCodeWords == NULL) return Ref(); vector > detectedCodeWords; - if (m_ptPossibleCodeWords->GetNextPossible(detectedCodeWords)) return Ref(); + if (m_ptPossibleCodeWords->getNextPossible(detectedCodeWords)) return Ref(); Ref grid(new BitMatrix(dimension_, detectedCodeWords.size(), err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); codewordsToBitMatrix(detectedCodeWords, grid); return grid; } @@ -416,7 +426,7 @@ void LinesSampler::computeSymbolWidths(vector &symbolWidths, const int sy symbolWidths.push_back(currentWidth); } -int LinesSampler::GetBitCountSum(const vector &vcModuleBitCount) +int LinesSampler::getBitCountSum(const vector &vcModuleBitCount) { int iBitCountSum = 0; for (size_t i = 0; i < vcModuleBitCount.size(); ++i) @@ -426,9 +436,9 @@ int LinesSampler::GetBitCountSum(const vector &vcModuleBitCount) return iBitCountSum; } -vector LinesSampler::SampleBitCounts(const vector &vcModuleBitCount) +vector LinesSampler::sampleBitCounts(const vector &vcModuleBitCount) { - float fBitCountSum = GetBitCountSum(vcModuleBitCount); + float fBitCountSum = getBitCountSum(vcModuleBitCount); vector vcResult( LinesSampler::BARS_IN_SYMBOL); int iBitCountIndex = 0; int iSumPreviousBits = 0; @@ -446,7 +456,7 @@ vector LinesSampler::SampleBitCounts(const vector &vcModuleBitCount) return vcResult; } -int LinesSampler::GetBitValue(const vector &vcModuleBitCount) +int LinesSampler::getBitValue(const vector &vcModuleBitCount) { int iResult = 0; for (size_t i = 0; i < vcModuleBitCount.size(); ++i) @@ -561,9 +571,9 @@ ErrorHandler LinesSampler::linesMatrixToCodewords(vector >& clusterN { vcModuleBitCount.push_back(barWidths[cwStart + j]); } - vcModuleBitCount = SampleBitCounts(vcModuleBitCount); + vcModuleBitCount = sampleBitCounts(vcModuleBitCount); - int iSymbol = GetBitValue(vcModuleBitCount); + int iSymbol = getBitValue(vcModuleBitCount); bool bFound = std::binary_search(BitMatrixParser::SYMBOL_TABLE, BitMatrixParser::SYMBOL_TABLE + BitMatrixParser::SYMBOL_TABLE_LENGTH, iSymbol); if (bFound) { diff --git a/modules/objdetect/src/zxing/pdf417/detector/lines_sampler.hpp b/modules/objdetect/src/zxing/pdf417/detector/lines_sampler.hpp index 28a217cf7d..f79122ac60 100644 --- a/modules/objdetect/src/zxing/pdf417/detector/lines_sampler.hpp +++ b/modules/objdetect/src/zxing/pdf417/detector/lines_sampler.hpp @@ -1,5 +1,15 @@ -#ifndef __LINESSAMPLER_H__ -#define __LINESSAMPLER_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_PDF417_DETECTOR_LINES_SAMPLER_HPP__ +#define __ZXING_PDF417_DETECTOR_LINES_SAMPLER_HPP__ /* * Copyright 2010 ZXing authors All rights reserved. @@ -33,7 +43,7 @@ public: PossibleCodeWords(const std::vector > > &vcVotes, int iRowCount); ~PossibleCodeWords() {}; - int GetNextPossible(std::vector > &vcCodeWords); + int getNextPossible(std::vector > &vcCodeWords); private: int m_iHeight; @@ -86,9 +96,9 @@ private: int round(float d); Point intersection(Line a, Line b); - int GetBitCountSum(const std::vector &vcModuleBitCount); - std::vector SampleBitCounts(const std::vector &vcModuleBitCount); - int GetBitValue(const std::vector &vcModuleBitCount); + int getBitCountSum(const std::vector &vcModuleBitCount); + std::vector sampleBitCounts(const std::vector &vcModuleBitCount); + int getBitValue(const std::vector &vcModuleBitCount); public: LinesSampler(Ref linesMatrix, int dimension); @@ -100,13 +110,13 @@ public: m_ptPossibleCodeWords = NULL; } } - void SetLineMatrix(Ref linesMatrix); + void setLineMatrix(Ref linesMatrix); ErrorHandler sample(Ref & bit_matrix); - Ref GetNextPossibleGrid(ErrorHandler &err_handler); + Ref getNextPossibleGrid(ErrorHandler &err_handler); }; } // namespace detector } // namespace pdf417 } // namespace zxing -#endif // __LINESSAMPLER_H__ +#endif // __ZXING_PDF417_DETECTOR_LINES_SAMPLER_HPP__ diff --git a/modules/objdetect/src/zxing/pdf417/pdf417reader.cpp b/modules/objdetect/src/zxing/pdf417/pdf417reader.cpp index 78d492a15c..256e56f85e 100644 --- a/modules/objdetect/src/zxing/pdf417/pdf417reader.cpp +++ b/modules/objdetect/src/zxing/pdf417/pdf417reader.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2010 ZXing authors All rights reserved. @@ -47,7 +57,7 @@ Ref PDF417Reader::decode(Ref image, DecodeHints hints) { Ref detectorResult; ErrorHandler err_handler; err_handler = detector.detect(hints, detectorResult); - if (err_handler.ErrCode() || detectorResult == NULL) { + if (err_handler.errCode() || detectorResult == NULL) { reader_call_path_ += "1"; // detect fail return Ref(); } @@ -67,7 +77,7 @@ Ref PDF417Reader::decode(Ref image, DecodeHints hints) { Ref linesGrid; err_handler = oLinesSampler.sample(linesGrid); - if (err_handler.ErrCode()) { + if (err_handler.errCode()) { reader_call_path_ += "2"; // sample fail return Ref(); } @@ -75,7 +85,7 @@ Ref PDF417Reader::decode(Ref image, DecodeHints hints) { if (!linesGrid) { Ref linesMatrixRotate(new BitMatrix(detectorResult->getBits()->getWidth(), detectorResult->getBits()->getHeight(), err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); for (int i = 0; igetBits()->getHeight(); i++) { for (int j = 0; j < linesMatrixRotate->getWidth(); j++) @@ -84,10 +94,10 @@ Ref PDF417Reader::decode(Ref image, DecodeHints hints) { linesMatrixRotate->set(j, detectorResult->getBits()->getHeight() - i - 1); } } - oLinesSampler.SetLineMatrix(linesMatrixRotate); + oLinesSampler.setLineMatrix(linesMatrixRotate); err_handler = oLinesSampler.sample(linesGrid); - if (!linesGrid || err_handler.ErrCode()) { + if (!linesGrid || err_handler.errCode()) { err_handler = NotFoundErrorHandler("LinesSampler Faileds!"); reader_call_path_ += "3"; // sample fail return Ref(); @@ -99,11 +109,11 @@ Ref PDF417Reader::decode(Ref image, DecodeHints hints) { // decoderResult = decoder.decode(detectorResult->getBits(), hints); ErrorHandler err_handler_; decoderResult = decoder.decode(linesGrid, hints, err_handler_); - if (err_handler_.ErrCode()) { - std::string cell_result = "zxing::ReaderException: " + err_handler_.ErrMsg(); - err_handler_.Reset(); - linesGrid = oLinesSampler.GetNextPossibleGrid(err_handler_); - if (err_handler_.ErrCode()) return Ref(); + if (err_handler_.errCode()) { + std::string cell_result = "zxing::ReaderException: " + err_handler_.errMsg(); + err_handler_.reset(); + linesGrid = oLinesSampler.getNextPossibleGrid(err_handler_); + if (err_handler_.errCode()) return Ref(); // retry logic if (!linesGrid || i == MAX_DECODE_FAIL_RETRY - 1){ err_handler_ = ReaderErrorHandler(cell_result); @@ -129,14 +139,14 @@ Ref PDF417Reader::extractPureBits(Ref image, ErrorHandler ArrayRef rightBottomBlack = image->getBottomRightOnBit(); int nModuleSize = moduleSize(leftTopBlack, image, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); int top = leftTopBlack[1]; int bottom = rightBottomBlack[1]; int left = findPatternStart(leftTopBlack[0], top, image, err_handler); - if (err_handler.ErrCode()) Ref(); + if (err_handler.errCode()) Ref(); int right = findPatternEnd(leftTopBlack[0], top, image, err_handler); - if (err_handler.ErrCode()) Ref(); + if (err_handler.errCode()) Ref(); int matrixWidth = (right - left + 1) / nModuleSize; int matrixHeight = (bottom - top + 1) / nModuleSize; @@ -154,7 +164,7 @@ Ref PDF417Reader::extractPureBits(Ref image, ErrorHandler // Now just read off the bits Ref bits(new BitMatrix(matrixWidth, matrixHeight, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); for (int y = 0; y < matrixHeight; y++) { int iOffset = top + y * nModuleSize; for (int x = 0; x < matrixWidth; x++) { diff --git a/modules/objdetect/src/zxing/pdf417/pdf417reader.hpp b/modules/objdetect/src/zxing/pdf417/pdf417reader.hpp index 02b86d090a..97dd2fa0a4 100644 --- a/modules/objdetect/src/zxing/pdf417/pdf417reader.hpp +++ b/modules/objdetect/src/zxing/pdf417/pdf417reader.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __PDF417_READER_H__ -#define __PDF417_READER_H__ +#ifndef __ZXING_PDF417_PDF417READER_HPP__ +#define __ZXING_PDF417_PDF417READER_HPP__ /* * PDF417Reader.hpp @@ -49,4 +59,4 @@ public: } // namespace pdf417 } // namespace zxing -#endif // __PDF417_READER_H__ +#endif // __ZXING_PDF417_PDF417READER_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/decoder/bit_matrix_parser.cpp b/modules/objdetect/src/zxing/qrcode/decoder/bit_matrix_parser.cpp index 0e4be41758..fa8a105c42 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/bit_matrix_parser.cpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/bit_matrix_parser.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * BitMatrixParser.cpp * zxing @@ -99,7 +109,7 @@ Version *BitMatrixParser::readVersion(ErrorHandler & err_handler) { if (provisionalVersion <= 6) { Version * version = Version::getVersionForNumber(provisionalVersion, err_handler); - if (err_handler.ErrCode()) return NULL; + if (err_handler.errCode()) return NULL; return version; } @@ -133,7 +143,7 @@ Version *BitMatrixParser::readVersion(ErrorHandler & err_handler) { } int a = parsedVersion_->getDimensionForVersion(err_handler); - if (err_handler.ErrCode()) return NULL; + if (err_handler.errCode()) return NULL; // if (parsedVersion_ != 0 && parsedVersion_->getDimensionForVersion(err_handler) == dimension) { if (parsedVersion_ != 0 && a == dimension) { @@ -155,21 +165,21 @@ Version *BitMatrixParser::readVersion(ErrorHandler & err_handler) { ArrayRef BitMatrixParser::readCodewords(ErrorHandler & err_handler) { Ref formatInfo = readFormatInformation(err_handler); - if (err_handler.ErrCode()) return ArrayRef(); + if (err_handler.errCode()) return ArrayRef(); Version *version = readVersion(err_handler); - if (err_handler.ErrCode()) return ArrayRef(); + if (err_handler.errCode()) return ArrayRef(); // Get the data mask for the format used in this QR Code. This will exclude // some bits from reading as we wind through the bit matrix. DataMask &dataMask = DataMask::forReference(static_cast(formatInfo->getDataMask()), err_handler); - if (err_handler.ErrCode()) return ArrayRef(); + if (err_handler.errCode()) return ArrayRef(); int dimension = bitMatrix_->getHeight(); dataMask.unmaskBitMatrix(*bitMatrix_, dimension); Ref functionPattern = version->buildFunctionPattern(err_handler); - if (err_handler.ErrCode()) return ArrayRef(); + if (err_handler.errCode()) return ArrayRef(); bool readingUp = true; ArrayRef result(version->getTotalCodewords()); @@ -221,7 +231,7 @@ ArrayRef BitMatrixParser::readCodewords(ErrorHandler & err_handler) } /** - * Revert the mask removal done while reading the code words. The bit matrix should revert to its original state. + * revert the mask removal done while reading the code words. The bit matrix should revert to its original state. */ void BitMatrixParser::remask() { if (parsedFormatInfo_ == NULL) @@ -230,7 +240,7 @@ void BitMatrixParser::remask() { } ErrorHandler err_handler; DataMask& dataMask = DataMask::forReference(parsedFormatInfo_->getDataMask(), err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; int dimension = bitMatrix_->getHeight(); dataMask.unmaskBitMatrix(*bitMatrix_, dimension); } diff --git a/modules/objdetect/src/zxing/qrcode/decoder/bit_matrix_parser.hpp b/modules/objdetect/src/zxing/qrcode/decoder/bit_matrix_parser.hpp index e429ec4b30..4fb18303ea 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/bit_matrix_parser.hpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/bit_matrix_parser.hpp @@ -1,5 +1,15 @@ -#ifndef __BIT_MATRIX_PARSER_H__ -#define __BIT_MATRIX_PARSER_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_QRCODE_DECODER_BIT_MATRIX_PARSER_HPP__ +#define __ZXING_QRCODE_DECODER_BIT_MATRIX_PARSER_HPP__ /* * BitMatrixParser.hpp @@ -67,4 +77,4 @@ private: } // namespace qrcode } // namespace zxing -#endif // __BIT_MATRIX_PARSER_H__ +#endif // __ZXING_QRCODE_DECODER_BIT_MATRIX_PARSER_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/decoder/data_block.cpp b/modules/objdetect/src/zxing/qrcode/decoder/data_block.cpp index f8cd4081e6..93ca743e3e 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/data_block.cpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/data_block.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * DataBlock.cpp * zxing diff --git a/modules/objdetect/src/zxing/qrcode/decoder/data_block.hpp b/modules/objdetect/src/zxing/qrcode/decoder/data_block.hpp index 3b27319ea6..23a17b9100 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/data_block.hpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/data_block.hpp @@ -1,5 +1,15 @@ -#ifndef __DATA_BLOCK_H__ -#define __DATA_BLOCK_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_QRCODE_DECODER_DATA_BLOCK_HPP__ +#define __ZXING_QRCODE_DECODER_DATA_BLOCK_HPP__ /* * DataBlock.hpp @@ -46,4 +56,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // __DATA_BLOCK_H__ +#endif // __ZXING_QRCODE_DECODER_DATA_BLOCK_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/decoder/data_mask.cpp b/modules/objdetect/src/zxing/qrcode/decoder/data_mask.cpp index ac8c5ec920..f2e60af5fe 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/data_mask.cpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/data_mask.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * DataMask.cpp * zxing diff --git a/modules/objdetect/src/zxing/qrcode/decoder/data_mask.hpp b/modules/objdetect/src/zxing/qrcode/decoder/data_mask.hpp index ea8df79ae2..28dcb36fe4 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/data_mask.hpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/data_mask.hpp @@ -1,5 +1,15 @@ -#ifndef __DATA_MASK_H__ -#define __DATA_MASK_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_QRCODE_DECODER_DATA_MASK_HPP__ +#define __ZXING_QRCODE_DECODER_DATA_MASK_HPP__ /* * DataMask.hpp @@ -46,4 +56,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // __DATA_MASK_H__ +#endif // __ZXING_QRCODE_DECODER_DATA_MASK_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/decoder/decoded_bit_stream_parser.cpp b/modules/objdetect/src/zxing/qrcode/decoder/decoded_bit_stream_parser.cpp index 084d4ed28a..566dd787b3 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/decoded_bit_stream_parser.cpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/decoded_bit_stream_parser.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * DecodedBitStreamParser.cpp @@ -154,7 +164,7 @@ void DecodedBitStreamParser::decodeHanziSegment(Ref bits_, while (count > 0) { // Each 13 bits encodes a 2-byte character int twoBytes = bits.readBits(13, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; int assembledTwoBytes = ((twoBytes / 0x060) << 8) | (twoBytes % 0x060); // if (assembledTwoBytes < 0x003BF) { // mod by sofiawu @@ -175,7 +185,7 @@ void DecodedBitStreamParser::decodeHanziSegment(Ref bits_, } append(result, buffer, nBytes, StringUtils::GB2312, err_handler); - if (err_handler.ErrCode()){ + if (err_handler.errCode()){ delete [] buffer; return; } @@ -193,7 +203,7 @@ void DecodedBitStreamParser::decodeKanjiSegment(Ref bits, std::string while (count > 0) { // Each 13 bits encodes a 2-byte character int twoBytes = bits->readBits(13, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; int assembledTwoBytes = ((twoBytes / 0x0C0) << 8) | (twoBytes % 0x0C0); if (assembledTwoBytes < 0x01F00) { @@ -212,7 +222,7 @@ void DecodedBitStreamParser::decodeKanjiSegment(Ref bits, std::string } append(result, buffer, nBytes, StringUtils::SHIFT_JIS, err_handler); - if (err_handler.ErrCode()){ + if (err_handler.errCode()){ delete [] buffer; return; } @@ -245,7 +255,7 @@ void DecodedBitStreamParser::decodeByteSegment(Ref bits_, int readBits = available < 8 ? available : 8; readBytes[i] = static_cast(bits.readBits(readBits, err_handler)); } - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; std::string encoding; if (currentCharacterSetECI == 0) @@ -271,7 +281,7 @@ void DecodedBitStreamParser::decodeByteSegment(Ref bits_, } append(result, readBytes, nBytes, encoding.c_str(), err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; byteSegments->values().push_back(bytes_); } @@ -289,7 +299,7 @@ void DecodedBitStreamParser::decodeNumericSegment(Ref bits, std::stri return; } int threeDigitsBits = bits->readBits(10, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; if (threeDigitsBits >= 1000) { std::ostringstream s; @@ -311,7 +321,7 @@ void DecodedBitStreamParser::decodeNumericSegment(Ref bits, std::stri } // Two digits left over to read, encoded in 7 bits int twoDigitsBits = bits->readBits(7, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; if (twoDigitsBits >= 100) { std::ostringstream s; @@ -331,7 +341,7 @@ void DecodedBitStreamParser::decodeNumericSegment(Ref bits, std::stri } // One digit left over to read int digitBits = bits->readBits(4, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; if (digitBits >= 10) { std::ostringstream s; @@ -342,7 +352,7 @@ void DecodedBitStreamParser::decodeNumericSegment(Ref bits, std::stri bytes[i++] = ALPHANUMERIC_CHARS[digitBits]; } append(result, bytes->data(), nBytes, StringUtils::ASCII, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } char DecodedBitStreamParser::toAlphaNumericChar(size_t value, ErrorHandler & err_handler) { @@ -371,7 +381,7 @@ void DecodedBitStreamParser::decodeAlphanumericSegment(Ref bits_, int nextTwoCharsBits = bits.readBits(11, err_handler); bytes << toAlphaNumericChar(nextTwoCharsBits / 45, err_handler); bytes << toAlphaNumericChar(nextTwoCharsBits % 45, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; count -= 2; } if (count == 1) { @@ -382,7 +392,7 @@ void DecodedBitStreamParser::decodeAlphanumericSegment(Ref bits_, return; } bytes << toAlphaNumericChar(bits.readBits(6, err_handler), err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } // See section 6.4.8.1, 6.4.8.2 std::string s = bytes.str(); @@ -412,13 +422,13 @@ void DecodedBitStreamParser::decodeAlphanumericSegment(Ref bits_, s = r.str(); } append(result, s, StringUtils::ASCII, err_handler); - if (err_handler.ErrCode()) return; + if (err_handler.errCode()) return; } namespace { int parseECIValue(BitSource& bits, ErrorHandler &err_handler) { int firstByte = bits.readBits(8, err_handler); - if (err_handler.ErrCode()) return 0; + if (err_handler.errCode()) return 0; if ((firstByte & 0x80) == 0) { // just one byte @@ -428,14 +438,14 @@ int parseECIValue(BitSource& bits, ErrorHandler &err_handler) { { // two bytes int secondByte = bits.readBits(8, err_handler); - if (err_handler.ErrCode()) return 0; + if (err_handler.errCode()) return 0; return ((firstByte & 0x3F) << 8) | secondByte; } if ((firstByte & 0xE0) == 0xC0) { // three bytes int secondThirdBytes = bits.readBits(16, err_handler); - if (err_handler.ErrCode()) return 0; + if (err_handler.errCode()) return 0; return ((firstByte & 0x1F) << 16) | secondThirdBytes; } @@ -482,7 +492,7 @@ DecodedBitStreamParser::decode(ArrayRef bytes, else { mode = &Mode::forBits(bits.readBits(4, err_handler), err_handler); // mode is encoded by 4 bits - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } if (mode != &Mode::TERMINATOR) @@ -508,16 +518,16 @@ DecodedBitStreamParser::decode(ArrayRef bytes, // Read next 8 bits(symbol sequence #) and 8 bits(parity data), then continue symbolSequence = bits.readBits(8, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); parityData = bits.readBits(8, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } else if (mode == &Mode::ECI) { // Count doesn't apply to ECI int value = parseECIValue(bits, err_handler); - if (err_handler.ErrCode()) Ref(); + if (err_handler.errCode()) Ref(); currentCharacterSetECI = CharacterSetECI::getCharacterSetECIByValueFind(value); if (currentCharacterSetECI == 0) { @@ -533,11 +543,11 @@ DecodedBitStreamParser::decode(ArrayRef bytes, // chinese mode contains a sub set indicator right after mode indicator int subset = bits.readBits(4, err_handler); int countHanzi = bits.readBits(mode->getCharacterCountBits(version), err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); if (subset == GB2312_SUBSET) { decodeHanziSegment(bits_, result, countHanzi, err_handler); - if (err_handler.ErrCode()) Ref(); + if (err_handler.errCode()) Ref(); outputCharset = "GB2312"; modeName = mode->getName(); } @@ -547,12 +557,12 @@ DecodedBitStreamParser::decode(ArrayRef bytes, // "Normal" QR code modes: // How many characters will follow, encoded in this mode? int count = bits.readBits(mode->getCharacterCountBits(version), err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); if (mode == &Mode::NUMERIC) { decodeNumericSegment(bits_, result, count, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { err_handler = zxing::FormatErrorHandler("decode"); return Ref(); @@ -562,13 +572,13 @@ DecodedBitStreamParser::decode(ArrayRef bytes, else if (mode == &Mode::ALPHANUMERIC) { decodeAlphanumericSegment(bits_, result, count, fc1InEffect, err_handler); - if (err_handler.ErrCode()) Ref(); + if (err_handler.errCode()) Ref(); modeName = mode->getName(); } else if (mode == &Mode::BYTE) { decodeByteSegment(bits_, result, count, currentCharacterSetECI, byteSegments, hints, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { err_handler = zxing::FormatErrorHandler("decode"); return Ref(); @@ -579,7 +589,7 @@ DecodedBitStreamParser::decode(ArrayRef bytes, else if (mode == &Mode::KANJI) { decodeKanjiSegment(bits_, result, count, err_handler); - if (err_handler.ErrCode()) Ref(); + if (err_handler.errCode()) Ref(); modeName = mode->getName(); } else diff --git a/modules/objdetect/src/zxing/qrcode/decoder/decoded_bit_stream_parser.hpp b/modules/objdetect/src/zxing/qrcode/decoder/decoded_bit_stream_parser.hpp index 9e13e753a2..5241bbf3e8 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/decoded_bit_stream_parser.hpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/decoded_bit_stream_parser.hpp @@ -1,7 +1,17 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __DECODED_BIT_STREAM_PARSER_H__ -#define __DECODED_BIT_STREAM_PARSER_H__ +#ifndef __ZXING_QRCODE_DECODER_DECODED_BIT_STREAM_PARSER_HPP__ +#define __ZXING_QRCODE_DECODER_DECODED_BIT_STREAM_PARSER_HPP__ /* * DecodedBitStreamParser.hpp @@ -79,4 +89,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // QBAR_AI_QBAR_ZXING_QRCODE_DECODER_DECODEDBITSTREAMPARSER_H_ +#endif // __ZXING_QRCODE_DECODER_DECODED_BIT_STREAM_PARSER_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/decoder/decoder.cpp b/modules/objdetect/src/zxing/qrcode/decoder/decoder.cpp index 5643eaaedc..cef1925f59 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/decoder.cpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/decoder.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Decoder.cpp @@ -62,17 +72,15 @@ Ref Decoder::decode(Ref bits, ErrorHandler & err_handl int width = bits->getWidth(); int height = bits->getHeight(); - std::cout << width << ' ' << height << '\n'; - Ref bits2(new BitMatrix(width, height, reinterpret_cast(bits->getPtr()), err_handler)); - if (err_handler.ErrCode()) { + if (err_handler.errCode()) { bits2 = NULL; } Ref rst = decode(bits, false, err_handler); - if (err_handler.ErrCode() || rst == NULL) + if (err_handler.errCode() || rst == NULL) { - errMsg = err_handler.ErrMsg(); + errMsg = err_handler.errMsg(); } else { @@ -85,28 +93,28 @@ Ref Decoder::decode(Ref bits, ErrorHandler & err_handl } // flip add by sofiawu - err_handler.Reset(); + err_handler.reset(); if (bits->copyOf2(bits2)) { bits->randomFlipRegion(static_cast(3.0 / 8.0 * width), static_cast(3.0 / 8.0 * height), static_cast(1.0 / 4.0 * width) + 1, static_cast(1.0 / 4.0 * height) + 1, err_handler); rst = decode(bits, false, err_handler); - if (err_handler.ErrCode() || rst == NULL) + if (err_handler.errCode() || rst == NULL) { - errMsg = err_handler.ErrMsg(); + errMsg = err_handler.errMsg(); } else { return rst; } } - err_handler.Reset(); + err_handler.reset(); if (bits->copyOf2(bits2)) { bits->randomFlipRegion(static_cast(3.0 / 8.0 * width), static_cast(3.0 / 8.0 * height), static_cast(1.0 / 4.0 * width) + 1, static_cast(1.0 / 4.0 * height) + 1, err_handler); rst = decode(bits, false, err_handler); - if (err_handler.ErrCode() || rst == NULL) + if (err_handler.errCode() || rst == NULL) { - errMsg = err_handler.ErrMsg(); + errMsg = err_handler.errMsg(); } else { @@ -114,9 +122,9 @@ Ref Decoder::decode(Ref bits, ErrorHandler & err_handl } } - err_handler.Reset(); + err_handler.reset(); Ref result = decode(bits2, true, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { return Ref(); } @@ -135,11 +143,11 @@ Ref Decoder::decode(Ref bits, bool isMirror, ErrorHand { // Construct a parser and read version, error-correction level BitMatrixParser parser(bits, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); if (isMirror == true) { - // Revert the bit matrix + // revert the bit matrix parser.remask(); // Will be attempting a mirrored reading of the version and format info. @@ -147,7 +155,7 @@ Ref Decoder::decode(Ref bits, bool isMirror, ErrorHand // Preemptively read the version. parser.readVersion(err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { err_handler = zxing::ReaderErrorHandler("Decoder::decode mirror & no mirror"); return Ref(); @@ -155,7 +163,7 @@ Ref Decoder::decode(Ref bits, bool isMirror, ErrorHand // Preemptively read the format information. parser.readFormatInformation(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); /* * Since we're here, this means we have successfully detected some kind @@ -169,7 +177,7 @@ Ref Decoder::decode(Ref bits, bool isMirror, ErrorHand decoderState_ = START; possibleFix_ = 0; Version *version = parser.readVersion(err_handler); - if (err_handler.ErrCode() || version == NULL) + if (err_handler.errCode() || version == NULL) { err_handler = ReaderErrorHandler("Decoder::decode mirror & no mirror"); return Ref(); @@ -177,13 +185,13 @@ Ref Decoder::decode(Ref bits, bool isMirror, ErrorHand decoderState_ = READVERSION; float fixedPatternScore = estimateFixedPattern(bits, version, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { return Ref(); } Ref formatInfo = parser.readFormatInformation(err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { return Ref(); } @@ -193,9 +201,9 @@ Ref Decoder::decode(Ref bits, bool isMirror, ErrorHand // Read codewords ArrayRef codewords(parser.readCodewords(err_handler)); // add more tricks by sofiawu - if (err_handler.ErrCode()) + if (err_handler.errCode()) { - err_handler.Reset(); + err_handler.reset(); codewords = parser.readCodewords(err_handler); err_handler = zxing::ReaderErrorHandler("Decoder::decode mirror & no mirror"); return Ref(); @@ -206,7 +214,7 @@ Ref Decoder::decode(Ref bits, bool isMirror, ErrorHand // Separate into data blocks std::vector > dataBlocks(DataBlock::getDataBlocks(codewords, version, ecLevel, err_handler)); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { return Ref(); } @@ -222,13 +230,13 @@ Ref Decoder::decode(Ref bits, bool isMirror, ErrorHand // Error-correct and copy data blocks together into a stream of bytes for (size_t j = 0; j < dataBlocks.size(); j++) { - err_handler.Reset(); + err_handler.reset(); Ref dataBlock(dataBlocks[j]); ArrayRef codewordBytes = dataBlock->getCodewords(); int numDataCodewords = dataBlock->getNumDataCodewords(); correctErrors(codewordBytes, numDataCodewords, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { return Ref(); } @@ -248,7 +256,7 @@ Ref Decoder::decode(Ref bits, bool isMirror, ErrorHand err_handler, version->getVersionNumber()); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { return Ref(); } @@ -272,7 +280,7 @@ void Decoder::correctErrors(ArrayRef codewordBytes, int numDataCodewords, int numECCodewords = numCodewords - numDataCodewords; rsDecoder_.decode(codewordInts, numECCodewords, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { return; } @@ -295,13 +303,13 @@ unsigned int Decoder::getPossibleVersion() float Decoder::estimateFixedPattern(Ref bits, zxing::qrcode::Version * version, ErrorHandler & err_handler) { Ref fixedPatternValue = version->buildFixedPatternValue(err_handler); - if (err_handler.ErrCode()){ + if (err_handler.errCode()){ err_handler = zxing::ReaderErrorHandler("Decoder::decode mirror & no mirror"); return -1.0; } Ref fixedPatternTemplate = version->buildFixedPatternTemplate(err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { err_handler = zxing::ReaderErrorHandler("Decoder::decode mirror & no mirror"); return -1.0; diff --git a/modules/objdetect/src/zxing/qrcode/decoder/decoder.hpp b/modules/objdetect/src/zxing/qrcode/decoder/decoder.hpp index 9303a2a193..7ddbd0add8 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/decoder.hpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/decoder.hpp @@ -1,5 +1,15 @@ -#ifndef __DECODER_H__ -#define __DECODER_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_QRCODE_DECODER_DECODER_HPP__ +#define __ZXING_QRCODE_DECODER_DECODER_HPP__ /* * Decoder.hpp @@ -71,4 +81,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // __DECODER_H__ +#endif // __ZXING_QRCODE_DECODER_DECODER_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/decoder/mode.cpp b/modules/objdetect/src/zxing/qrcode/decoder/mode.cpp index f12fd2fb0b..65676e7c0b 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/mode.cpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/mode.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Mode.cpp diff --git a/modules/objdetect/src/zxing/qrcode/decoder/mode.hpp b/modules/objdetect/src/zxing/qrcode/decoder/mode.hpp index 3357b954bb..0c66409dc5 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/mode.hpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/mode.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __MODE_H__ -#define __MODE_H__ +#ifndef __ZXING_QRCODE_DECODER_MODE_HPP__ +#define __ZXING_QRCODE_DECODER_MODE_HPP__ /* * Mode.hpp diff --git a/modules/objdetect/src/zxing/qrcode/decoder/qrcode_decoder_meta_data.hpp b/modules/objdetect/src/zxing/qrcode/decoder/qrcode_decoder_meta_data.hpp index abd6d708af..f2a4869084 100644 --- a/modules/objdetect/src/zxing/qrcode/decoder/qrcode_decoder_meta_data.hpp +++ b/modules/objdetect/src/zxing/qrcode/decoder/qrcode_decoder_meta_data.hpp @@ -1,5 +1,15 @@ -#ifndef __DECODER_META_DATA_H__ -#define __DECODER_META_DATA_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_QRCODE_DECODER_QRCODE_DECODER_META_DATA_HPP__ +#define __ZXING_QRCODE_DECODER_QRCODE_DECODER_META_DATA_HPP__ /* * Copyright 2013 ZXing authors @@ -89,4 +99,4 @@ public: } } -#endif // __DECODER_META_DATA_H__ \ No newline at end of file +#endif // __ZXING_QRCODE_DECODER_QRCODE_DECODER_META_DATA_HPP__ \ No newline at end of file diff --git a/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern.cpp b/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern.cpp index c2421b4e88..cc0e49d006 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern.cpp +++ b/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * AlignmentPattern.cpp diff --git a/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern.hpp b/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern.hpp index 7fd47a6ba9..3c09859a92 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern.hpp +++ b/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern.hpp @@ -1,7 +1,17 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __ALIGNMENT_PATTERN_H__ -#define __ALIGNMENT_PATTERN_H__ +#ifndef __ZXING_QRCODE_DETECTOR_ALIGNMENT_PATTERN_HPP__ +#define __ZXING_QRCODE_DETECTOR_ALIGNMENT_PATTERN_HPP__ /* * AlignmentPattern.hpp @@ -45,4 +55,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // __ALIGNMENT_PATTERN_H__ +#endif // __ZXING_QRCODE_DETECTOR_ALIGNMENT_PATTERN_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern_finder.cpp b/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern_finder.cpp index 60efb5d06a..355960fd25 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern_finder.cpp +++ b/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern_finder.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2008 ZXing authors All rights reserved. diff --git a/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern_finder.hpp b/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern_finder.hpp index b728d0c460..f76f6c5cc5 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern_finder.hpp +++ b/modules/objdetect/src/zxing/qrcode/detector/alignment_pattern_finder.hpp @@ -1,5 +1,15 @@ -#ifndef __ALIGNMENT_PATTERN_FINDER_H__ -#define __ALIGNMENT_PATTERN_FINDER_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_QRCODE_DETECTOR_ALIGNMENT_PATTERN_FINDER_HPP__ +#define __ZXING_QRCODE_DETECTOR_ALIGNMENT_PATTERN_FINDER_HPP__ /* * AlignmentPatternFinder.hpp @@ -117,5 +127,5 @@ public: } // namespace qrcode } // namespace zxing -#endif // __ALIGNMENT_PATTERN_FINDER_H__ +#endif // __ZXING_QRCODE_DETECTOR_ALIGNMENT_PATTERN_FINDER_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/detector/detector.cpp b/modules/objdetect/src/zxing/qrcode/detector/detector.cpp index fc09132db1..dac27cf05a 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/detector.cpp +++ b/modules/objdetect/src/zxing/qrcode/detector/detector.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Detector.cpp @@ -86,7 +96,7 @@ void Detector::detect(DecodeHints const& hints, ErrorHandler & err_handler) finder.setFinderLoose(finderConditionLoose_); std::vector > finderInfos = finder.find(hints, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return; // Get all possible results @@ -293,7 +303,7 @@ int Detector::locatePatternRect(float x, float y, std::vector& poin int Detector::getFixedAlignmentPoints(size_t patternIdx, int dimension, float module_size, std::vector& pts_src, std::vector& pts_dst) { ErrorHandler err_handler; Version *provisionalVersion = Version::getProvisionalVersionForDimension(dimension, err_handler); - if (err_handler.ErrCode() != 0) + if (err_handler.errCode() != 0) return -1; if (patternIdx >= possiblePatternResults_.size()) return -1; @@ -429,7 +439,7 @@ int Detector::getFixedAlignmentPoints(size_t patternIdx, int dimension, float mo int Detector::getFlexibleAlignmentPoints(size_t patternIdx, size_t alignmentIdx, int dimension, float module_size, std::vector& pts_src, std::vector& pts_dst) { ErrorHandler err_handler; Version *provisionalVersion = Version::getProvisionalVersionForDimension(dimension, err_handler); - if (err_handler.ErrCode() != 0) + if (err_handler.errCode() != 0) return -1; if (patternIdx >= possiblePatternResults_.size()) return -1; @@ -1166,7 +1176,7 @@ int Detector::getPossibleAlignmentCount(size_t idx, DecodeHints& hints) if (possiblePatternResults_[idx]->possibleAlignmentPatterns.size() == 0) { Ref result = processFinderPatternInfo(hints, possiblePatternResults_[idx]->finderPatternInfo, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return -1; possiblePatternResults_[idx] = result; @@ -1200,7 +1210,7 @@ Ref Detector::getResultViaAlignmentMore(DecodeHints const& hints } Version *provisionalVersion = Version::getProvisionalVersionForDimension(dimension, err_handler); - if (err_handler.ErrCode() != 0) + if (err_handler.errCode() != 0) return Ref(NULL); Ref topLeft(possiblePatternResults_[patternIdx]->finderPatternInfo->getTopLeft()); @@ -1452,7 +1462,7 @@ Ref Detector::getResultViaAlignmentMore(DecodeHints const& hints cv::Mat H = cv::findHomography(pts_src, pts_dst, cv::RANSAC); Ref bits(sampleGrid(image_, dimension, H, err_handler)); - if (err_handler.ErrCode()) + if (err_handler.errCode()) Ref(); std::vector corners(4); @@ -1504,7 +1514,7 @@ Ref Detector::getResultViaAlignmentMore(DecodeHints const& hints a_x, b_x, c_x, d_x, e_x, f_x, a_y, b_y, c_y, d_y, e_y, f_y, err_handler)); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return Ref(); std::vector corners(4); @@ -1561,7 +1571,7 @@ Ref Detector::getResultViaAlignment(size_t patternIdx, size_t al Ref transform = createTransform(topLeft, topRight, bottomLeft, alignment, possibleDimension); Ref bits(sampleGrid(image_, possibleDimension, transform, err_handler)); - if (err_handler.ErrCode()) + if (err_handler.errCode()) Ref(); ArrayRef< Ref > corrners(new Array< Ref >(4)); @@ -1584,7 +1594,7 @@ Ref Detector::getResultViaAlignment(size_t patternIdx, size_t al Ref alignment(possiblePatternResults_[patternIdx]->possibleAlignmentPatterns[0]); Ref transform = createTransform(topLeft, topRight, bottomLeft, alignment, possibleDimension); Ref bits(sampleGrid(image_, possibleDimension, transform, err_handler)); - if (err_handler.ErrCode()) + if (err_handler.errCode()) Ref(); ArrayRef< Ref > corrners(new Array< Ref >(4)); @@ -1616,7 +1626,7 @@ Ref Detector::getResultViaPoints(DecodeHints const& hints, int d cv::Mat H = cv::findHomography(pts_src, pts_dst, cv::RANSAC); Ref bits(sampleGrid(image_, dimension, H, err_handler)); - if (err_handler.ErrCode()) + if (err_handler.errCode()) Ref(); std::vector corners(4); @@ -1669,7 +1679,7 @@ Ref Detector::getResultViaPoints(DecodeHints const& hints, int d a_x, b_x, c_x, d_x, e_x, f_x, a_y, b_y, c_y, d_y, e_y, f_y, err_handler)); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return Ref(); std::vector corners(4); @@ -1723,9 +1733,9 @@ Ref Detector::getNearestAlignmentPattern(int tryFindRange, flo ErrorHandler err_handler; for (int i = 2; i <= tryFindRange; i <<= 1) { - err_handler.Reset(); + err_handler.reset(); alignmentPattern = findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, static_cast(i), err_handler); - if (err_handler.ErrCode() == 0) + if (err_handler.errCode() == 0) break; } @@ -1788,11 +1798,11 @@ Ref Detector::processFinderPatternInfo(::DecodeHints& hints, Ref< for (int i = 0; i < 5; i++) { - err_handler.Reset(); + err_handler.reset(); dimension = oriDimension + dimensionDiff[i]; provisionalVersion = Version::getProvisionalVersionForDimension(dimension, err_handler); - if (err_handler.ErrCode() == 0) + if (err_handler.errCode() == 0) { // refine modulesize { @@ -1824,7 +1834,7 @@ Ref Detector::processFinderPatternInfo(::DecodeHints& hints, Ref< // find aligment point modulesBetweenFPCenters = provisionalVersion->getDimensionForVersion(err_handler) - 7; - if (err_handler.ErrCode()) { + if (err_handler.errCode()) { err_handler = zxing::ReaderErrorHandler("Cannot get version number"); return Ref(); } @@ -1846,20 +1856,20 @@ Ref Detector::processFinderPatternInfo(::DecodeHints& hints, Ref< Ref fitLineCenter; fitLineCenter = findAlignmentWithFitLine(topLeft, topRight, bottomLeft, moduleSize, err_handler); - if (err_handler.ErrCode() == 0) + if (err_handler.errCode() == 0) { if (fitLineCenter != NULL && MathUtils::isInRange(fitLineCenter->getX(), fitLineCenter->getY(), image_->getWidth(), image_->getHeight())){ foundFitLine = true; } } - err_handler.Reset(); + err_handler.reset(); Ref fitAP, estAP; // Anything above version 1 has an alignment pattern if (provisionalVersion->getAlignmentPatternCenters().size() > 0) { int tryFindRange = provisionalVersion->getDimensionForVersion(err_handler) / 4; - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); if (foundFitLine == true) { @@ -2055,7 +2065,7 @@ Ref Detector::sampleGrid(Ref image, int dimension, Ref bits = sampler.sampleGrid(image, dimension, transform, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return Ref(); return bits; @@ -2065,7 +2075,7 @@ Ref Detector::sampleGrid(Ref image, int dimension, cv::Mat { GridSampler &sampler = GridSampler::getInstance(); Ref bits = sampler.sampleGrid(image, dimension, transform, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return Ref(); return bits; @@ -2081,7 +2091,7 @@ Ref Detector::sampleGrid(Ref image, int dimension, ax, bx, cx, dx, ex, fx, ay, by, cy, dy, ey, fy, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return Ref(); return bits; @@ -2177,7 +2187,7 @@ Ref Detector::findAlignmentInRegion(float overallEstModuleSize - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, callback_); Ref ap = alignmentFinder.find(err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return Ref(); return ap; } @@ -2859,10 +2869,10 @@ bool Detector::checkConvexQuadrilateral(Ref topLeft, RefgetX()-bottomLeft->getX(); v3[1] = bottomRight->getY()-bottomLeft->getY(); v4[0] = bottomLeft->getX()-topLeft->getX(); v4[1] = bottomLeft->getY()-topLeft->getY(); - float c1 = MathUtils::VecCross(v1, v2); - float c2 = MathUtils::VecCross(v2, v3); - float c3 = MathUtils::VecCross(v3, v4); - float c4 = MathUtils::VecCross(v4, v1); + float c1 = MathUtils::vecCross(v1, v2); + float c2 = MathUtils::vecCross(v2, v3); + float c3 = MathUtils::vecCross(v3, v4); + float c4 = MathUtils::vecCross(v4, v1); // If it looks like a convex quadrilateral if ((c1 < 0.0 && c2 < 0.0 && c3 < 0.0 && c4 < 0.0)||(c1 > 0.0 && c2 > 0.0 && c3 > 0.0 && c4 > 0.0)) diff --git a/modules/objdetect/src/zxing/qrcode/detector/detector.hpp b/modules/objdetect/src/zxing/qrcode/detector/detector.hpp index 169d162faf..b8ea0e62f7 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/detector.hpp +++ b/modules/objdetect/src/zxing/qrcode/detector/detector.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __DETECTOR_H__ -#define __DETECTOR_H__ +#ifndef __ZXING_QRCODE_DETECTOR_DETECTOR_HPP__ +#define __ZXING_QRCODE_DETECTOR_DETECTOR_HPP__ /* * Detector.hpp @@ -167,4 +177,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // __DETECTOR_H__ +#endif // __ZXING_QRCODE_DETECTOR_DETECTOR_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern.cpp b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern.cpp index 65d32117fd..0afb633ec0 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern.cpp +++ b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * FinderPattern.cpp diff --git a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern.hpp b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern.hpp index fe4ee277f8..986473aaf3 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern.hpp +++ b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __FINDER_PATTERN_H__ -#define __FINDER_PATTERN_H__ +#ifndef __ZXING_QRCODE_DETECTOR_FINDER_PATTERN_HPP__ +#define __ZXING_QRCODE_DETECTOR_FINDER_PATTERN_HPP__ /* * FinderPattern.hpp @@ -91,4 +101,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // QBAR_AI_QBAR_ZXING_QRCODE_DETECTOR_FINDERPATTERN_H_ +#endif // __ZXING_QRCODE_DETECTOR_FINDER_PATTERN_INFO_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_finder.cpp b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_finder.cpp index d6d7b588d2..bb6f370ef0 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_finder.cpp +++ b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_finder.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * FinderPatternFinder.cpp @@ -201,25 +211,25 @@ int FinderPatternFinder::MAX_MODULES = 177; // support up to version 40 which int FinderPatternFinder::_minModuleSize = 1; // 1 pixel/module times MIN_SKIP modules/center int FinderPatternFinder::INTEGER_MATH_SHIFT = 8; -void FinderPatternFinder::InitConfig() +void FinderPatternFinder::initConfig() { - FPS_MS_VAL = GetIniParser()->GetReal("FP_SELECT", "FPS_MS_VAL", 1.0); - FP_IS_SELECT_BEST = GetIniParser()->GetInteger("FP_SELECT", "FP_IS_SELECT_BEST", 1); - FP_IS_SELECT_FILE_BEST = GetIniParser()->GetInteger("FP_SELECT", "FP_IS_SELECT_FILE_BEST", 1); - FP_INPUT_MAX_NUM = GetIniParser()->GetInteger("FP_SELECT", "FP_INPUT_MAX_NUM", 100); - FP_FILTER_SIZE = GetIniParser()->GetReal("FP_SELECT", "FP_FILTER_SIZE", 100); - FP_COUNT_MIN = GetIniParser()->GetReal("FP_SELECT", "FP_COUNT_MIN", 2.0); - FP_MS_MIN = GetIniParser()->GetReal("FP_SELECT", "FP_MS_MIN", 1.0); - FPS_CLUSTER_MAX = GetIniParser()->GetInteger("FP_SELECT", "FPS_CLUSTER_MAX", 4); - FPS_RESULT_MAX = GetIniParser()->GetInteger("FP_SELECT", "FPS_RESULT_MAX", 12); - K_FACTOR = GetIniParser()->GetInteger("FP_SELECT", "K_FACTOR", 2); - FP_RIGHT_ANGLE = GetIniParser()->GetReal("FP_SELECT", "FP_RIGHT_ANGLE", 0.342); - FP_SMALL_ANGLE1 = GetIniParser()->GetReal("FP_SELECT", "FP_SMALL_ANGLE1", 0.8191); - FP_SMALL_ANGLE2 = GetIniParser()->GetReal("FP_SELECT", "FP_SMALL_ANGLE2", 0.5736); + FPS_MS_VAL = GetIniParser()->getReal("FP_SELECT", "FPS_MS_VAL", 1.0); + FP_IS_SELECT_BEST = GetIniParser()->getInteger("FP_SELECT", "FP_IS_SELECT_BEST", 1); + FP_IS_SELECT_FILE_BEST = GetIniParser()->getInteger("FP_SELECT", "FP_IS_SELECT_FILE_BEST", 1); + FP_INPUT_MAX_NUM = GetIniParser()->getInteger("FP_SELECT", "FP_INPUT_MAX_NUM", 100); + FP_FILTER_SIZE = GetIniParser()->getReal("FP_SELECT", "FP_FILTER_SIZE", 100); + FP_COUNT_MIN = GetIniParser()->getReal("FP_SELECT", "FP_COUNT_MIN", 2.0); + FP_MS_MIN = GetIniParser()->getReal("FP_SELECT", "FP_MS_MIN", 1.0); + FPS_CLUSTER_MAX = GetIniParser()->getInteger("FP_SELECT", "FPS_CLUSTER_MAX", 4); + FPS_RESULT_MAX = GetIniParser()->getInteger("FP_SELECT", "FPS_RESULT_MAX", 12); + K_FACTOR = GetIniParser()->getInteger("FP_SELECT", "K_FACTOR", 2); + FP_RIGHT_ANGLE = GetIniParser()->getReal("FP_SELECT", "FP_RIGHT_ANGLE", 0.342); + FP_SMALL_ANGLE1 = GetIniParser()->getReal("FP_SELECT", "FP_SMALL_ANGLE1", 0.8191); + FP_SMALL_ANGLE2 = GetIniParser()->getReal("FP_SELECT", "FP_SMALL_ANGLE2", 0.5736); - QR_MIN_FP_AREA_ERR = GetIniParser()->GetReal("FP_SELECT", "BLOCK_AREA_ERR", 3); - QR_MIN_FP_MS_ERR = GetIniParser()->GetReal("FP_SELECT", "BLOCK_MS_ERR", 1); - QR_MIN_FP_ACCEPT = GetIniParser()->GetReal("FP_SELECT", "BLOCK_ACCEPT", 4); + QR_MIN_FP_AREA_ERR = GetIniParser()->getReal("FP_SELECT", "BLOCK_AREA_ERR", 3); + QR_MIN_FP_MS_ERR = GetIniParser()->getReal("FP_SELECT", "BLOCK_MS_ERR", 1); + QR_MIN_FP_ACCEPT = GetIniParser()->getReal("FP_SELECT", "BLOCK_ACCEPT", 4); } std::vector > FinderPatternFinder::find(DecodeHints const& hints , ErrorHandler & err_handler) @@ -358,13 +368,13 @@ std::vector > FinderPatternFinder::find(DecodeHints const for (size_t rj = matrix.getRowFirstIsWhite(i) ? 1 : 0; (rj + 4) < size_t(row_counter_width); rj += 2) { - if (block_->GetUnicomBlockIndex(i, irow_offsets[rj]) == block_->GetUnicomBlockIndex(i, irow_offsets[rj + 4]) && - block_->GetUnicomBlockIndex(i, irow_offsets[rj + 1]) == block_->GetUnicomBlockIndex(i, irow_offsets[rj + 3]) && - block_->GetUnicomBlockIndex(i, irow_offsets[rj]) != block_->GetUnicomBlockIndex(i, irow_offsets[rj + 2])) + if (block_->getUnicomBlockIndex(i, irow_offsets[rj]) == block_->getUnicomBlockIndex(i, irow_offsets[rj + 4]) && + block_->getUnicomBlockIndex(i, irow_offsets[rj + 1]) == block_->getUnicomBlockIndex(i, irow_offsets[rj + 3]) && + block_->getUnicomBlockIndex(i, irow_offsets[rj]) != block_->getUnicomBlockIndex(i, irow_offsets[rj + 2])) { - const int iBlackCir = block_->GetUnicomBlockSize(i, irow_offsets[rj]); - const int iWhiteCir = block_->GetUnicomBlockSize(i, irow_offsets[rj + 1]); - const int iBlackPnt = block_->GetUnicomBlockSize(i, irow_offsets[rj + 2]); + const int iBlackCir = block_->getUnicomBlockSize(i, irow_offsets[rj]); + const int iWhiteCir = block_->getUnicomBlockSize(i, irow_offsets[rj + 1]); + const int iBlackPnt = block_->getUnicomBlockSize(i, irow_offsets[rj + 2]); // we can pass : iBlackCir == iBlackCir // so optimizing @@ -396,8 +406,8 @@ std::vector > FinderPatternFinder::find(DecodeHints const else { int iMinX = 0, iMinY = 0, iMaxX = 0, iMaxY = 0; - block_->GetMinPoint(i, irow_offsets[rj + 1], iMinY, iMinX); - block_->GetMaxPoint(i, irow_offsets[rj + 3], iMaxY, iMaxX); + block_->getMinPoint(i, irow_offsets[rj + 1], iMinY, iMinX); + block_->getMaxPoint(i, irow_offsets[rj + 3], iMaxY, iMaxX); centerI = (iMaxY + iMinY) / 2.0; // y centerJ = (iMaxX + iMinX) / 2.0; // x } @@ -422,7 +432,7 @@ std::vector > FinderPatternFinder::find(DecodeHints const // filter and sort std::vector > patternInfos; patternInfos = getPatternInfosFileMode(hints, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { return std::vector >(); } @@ -531,7 +541,7 @@ vector > FinderPatternFinder::getPatternInfos(ErrorHandle // Handle possible centers for both pure and normal qrcode finderPatterns = selectBestPatterns(err_handler); - if (err_handler.ErrCode() == 0) + if (err_handler.errCode() == 0) { finderPatterns = orderBestPatterns(finderPatterns); resultBest = new FinderPatternInfo(finderPatterns); @@ -607,7 +617,7 @@ vector > FinderPatternFinder::getPatternInfos(ErrorHandle return patternInfos; } -bool FinderPatternFinder::IsPossibleFindPatterInfo( Ref a, Ref b, Ref c) +bool FinderPatternFinder::isPossibleFindPatterInfo( Ref a, Ref b, Ref c) { // check fangcha float aMs = a->getEstimatedModuleSize(); @@ -629,7 +639,7 @@ bool FinderPatternFinder::IsPossibleFindPatterInfo( Ref a, Ref a, Ref b, Ref c, vector > & patternInfos) +void FinderPatternFinder::pushToResult( Ref a, Ref b, Ref c, vector > & patternInfos) { vector< Ref > finderPatterns; finderPatterns.push_back(a); finderPatterns.push_back(b); finderPatterns.push_back(c); @@ -680,7 +690,7 @@ vector > FinderPatternFinder::getPatternInfosFileMode(Dec if (startSize == 3) { - PushToResult(possibleCenters_[0], possibleCenters_[1] , possibleCenters_[2], patternInfos); + pushToResult(possibleCenters_[0], possibleCenters_[1] , possibleCenters_[2], patternInfos); return patternInfos; } @@ -718,7 +728,7 @@ vector > FinderPatternFinder::getPatternInfosFileMode(Dec possible_idxs.erase(possible_idxs.begin() + max_idx); if (possible_idxs.size() == 3) { - PushToResult(possibleCenters_[possible_idxs[0]], possibleCenters_[possible_idxs[1]], possibleCenters_[possible_idxs[2]], patternInfos); + pushToResult(possibleCenters_[possible_idxs[0]], possibleCenters_[possible_idxs[1]], possibleCenters_[possible_idxs[2]], patternInfos); } } @@ -726,14 +736,14 @@ vector > FinderPatternFinder::getPatternInfosFileMode(Dec if (FP_IS_SELECT_BEST) { finderPatterns = selectBestPatterns(err_handler); - if (err_handler.ErrCode() == 0) - PushToResult(finderPatterns[0], finderPatterns[1], finderPatterns[2], patternInfos); + if (err_handler.errCode() == 0) + pushToResult(finderPatterns[0], finderPatterns[1], finderPatterns[2], patternInfos); } if (FP_IS_SELECT_FILE_BEST) { finderPatterns = selectFileBestPatterns(err_handler); - if (err_handler.ErrCode() == 0) - PushToResult(finderPatterns[0], finderPatterns[1], finderPatterns[2], patternInfos); + if (err_handler.errCode() == 0) + pushToResult(finderPatterns[0], finderPatterns[1], finderPatterns[2], patternInfos); } // kmean @@ -770,11 +780,11 @@ vector > FinderPatternFinder::getPatternInfosFileMode(Dec { for (uint z = y + 1; z < standardCenters.size(); z++) { - bool check_result = IsPossibleFindPatterInfo( + bool check_result = isPossibleFindPatterInfo( standardCenters[x], standardCenters[y], standardCenters[z]); if (check_result) { - PushToResult(standardCenters[x], standardCenters[y], standardCenters[z], + pushToResult(standardCenters[x], standardCenters[y], standardCenters[z], patternInfos); } } @@ -826,10 +836,10 @@ vector > FinderPatternFinder::getPatternInfosFileMode(Dec { for (uint z = y + 1; z < clusters_out[i].samples.size() && cluster_select <= FPS_CLUSTER_MAX && patternInfos.size() <= size_t(FPS_RESULT_MAX); z++) { - bool check_result = IsPossibleFindPatterInfo(clusterPatterns[x], clusterPatterns[y], clusterPatterns[z]); + bool check_result = isPossibleFindPatterInfo(clusterPatterns[x], clusterPatterns[y], clusterPatterns[z]); if (check_result) { - PushToResult(clusterPatterns[x], clusterPatterns[y], clusterPatterns[z], patternInfos); + pushToResult(clusterPatterns[x], clusterPatterns[y], clusterPatterns[z], patternInfos); cluster_select++; } } @@ -2161,7 +2171,7 @@ FinderPatternFinder::FinderPatternFinder(Ref image, Refconst& callback) : image_(image), possibleCenters_(), hasSkipped_(false), block_(block) , callback_(callback), compared_finder_counts(0) { CURRENT_CHECK_STATE = FinderPatternFinder::NORMAL; - InitConfig(); + initConfig(); } Ref FinderPatternFinder::getImage() { diff --git a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_finder.hpp b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_finder.hpp index 21793d52b0..24ebd240f0 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_finder.hpp +++ b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_finder.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __FINDER_PATTERN_FINDER_H__ -#define __FINDER_PATTERN_FINDER_H__ +#ifndef __ZXING_QRCODE_DETECTOR_FINDER_PATTERN_FINDER_HP__ +#define __ZXING_QRCODE_DETECTOR_FINDER_PATTERN_FINDER_HP__ /* * FinderPatternFinder.hpp @@ -131,14 +141,14 @@ protected: std::vector > getPatternInfos(ErrorHandler & err_handler); std::vector > getPatternInfosFileMode(DecodeHints const& hints, ErrorHandler & err_handler); - bool IsPossibleFindPatterInfo(Ref a, Ref b, Ref c); - void PushToResult( Ref a, Ref b, Ref c, std::vector > & patternInfos); + bool isPossibleFindPatterInfo(Ref a, Ref b, Ref c); + void pushToResult( Ref a, Ref b, Ref c, std::vector > & patternInfos); Ref getImage(); std::vector >& getPossibleCenters(); public: - void InitConfig(); + void initConfig(); float distance(Ref p1, Ref p2); FinderPatternFinder(Ref image, Ref block, Refconst&); @@ -151,4 +161,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // __FINDER_PATTERN_FINDER_H__ +#endif // __ZXING_QRCODE_DETECTOR_FINDER_PATTERN_FINDER_HP__ diff --git a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_info.cpp b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_info.cpp index 67f73727cb..20969ad050 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_info.cpp +++ b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_info.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * FinderPatternInfo.cpp * zxing diff --git a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_info.hpp b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_info.hpp index 28e85708b9..cdc544935a 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_info.hpp +++ b/modules/objdetect/src/zxing/qrcode/detector/finder_pattern_info.hpp @@ -1,5 +1,15 @@ -#ifndef __FINDER_PATTERN_INFO_H__ -#define __FINDER_PATTERN_INFO_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_QRCODE_DETECTOR_FINDER_PATTERN_INFO_HPP__ +#define __ZXING_QRCODE_DETECTOR_FINDER_PATTERN_INFO_HPP__ /* * FinderPatternInfo.hpp @@ -55,4 +65,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // __FINDER_PATTERN_INFO_H__ +#endif // __ZXING_QRCODE_DETECTOR_FINDER_PATTERN_INFO_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/detector/pattern_result.cpp b/modules/objdetect/src/zxing/qrcode/detector/pattern_result.cpp index 5f98c14b11..97f5fce7ae 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/pattern_result.cpp +++ b/modules/objdetect/src/zxing/qrcode/detector/pattern_result.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + #include "pattern_result.hpp" // VC++ diff --git a/modules/objdetect/src/zxing/qrcode/detector/pattern_result.hpp b/modules/objdetect/src/zxing/qrcode/detector/pattern_result.hpp index 6afd6ff125..d17c25b168 100644 --- a/modules/objdetect/src/zxing/qrcode/detector/pattern_result.hpp +++ b/modules/objdetect/src/zxing/qrcode/detector/pattern_result.hpp @@ -1,5 +1,15 @@ -#ifndef __POSSIBLE_DETECTOR_RESULT_H__ -#define __POSSIBLE_DETECTOR_RESULT_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_QRCODE_DETECTOR_POSSIBLE_DETECTOR_RESULT_HPP__ +#define __ZXING_QRCODE_DETECTOR_POSSIBLE_DETECTOR_RESULT_HPP__ /* * DetectorResult.hpp @@ -67,4 +77,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // QBAR_AI_QBAR_ZXING_QRCODE_DETECTOR_PATTERNRESULT_H_ +#endif // __ZXING_QRCODE_DETECTOR_POSSIBLE_DETECTOR_RESULT_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/error_correction_level.cpp b/modules/objdetect/src/zxing/qrcode/error_correction_level.cpp index fe9ba2570f..9a77bdf8b8 100644 --- a/modules/objdetect/src/zxing/qrcode/error_correction_level.cpp +++ b/modules/objdetect/src/zxing/qrcode/error_correction_level.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * ErrorCorrectionLevel.cpp diff --git a/modules/objdetect/src/zxing/qrcode/error_correction_level.hpp b/modules/objdetect/src/zxing/qrcode/error_correction_level.hpp index e4e1fef5b1..94948333c5 100644 --- a/modules/objdetect/src/zxing/qrcode/error_correction_level.hpp +++ b/modules/objdetect/src/zxing/qrcode/error_correction_level.hpp @@ -1,5 +1,15 @@ -#ifndef __ERROR_CORRECTION_LEVEL_H__ -#define __ERROR_CORRECTION_LEVEL_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_QRCODE_ERROR_CORRECTION_LEVEL_HPP__ +#define __ZXING_QRCODE_ERROR_CORRECTION_LEVEL_HPP__ /* * ErrorCorrectionLevel.hpp @@ -51,4 +61,4 @@ public: //} // namespace qrcode } // namespace zxing -#endif // __ERROR_CORRECTION_LEVEL_H__ +#endif // __ZXING_QRCODE_ERROR_CORRECTION_LEVEL_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/format_information.cpp b/modules/objdetect/src/zxing/qrcode/format_information.cpp index 2185b8d12e..770ea30afe 100644 --- a/modules/objdetect/src/zxing/qrcode/format_information.cpp +++ b/modules/objdetect/src/zxing/qrcode/format_information.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * FormatInformation.cpp * zxing @@ -41,7 +51,7 @@ int FormatInformation::BITS_SET_IN_HALF_BYTE[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, FormatInformation::FormatInformation(int formatInfo, float possiableFix, ErrorHandler & err_handler) : errorCorrectionLevel_(ErrorCorrectionLevel::forBits((formatInfo >> 3) & 0x03, err_handler)), dataMask_(static_cast(formatInfo & 0x07)) { possiableFix_ = possiableFix; - if (err_handler.ErrCode()) + if (err_handler.errCode()) return; } @@ -92,7 +102,7 @@ Ref FormatInformation::doDecodeFormatInformation(int maskedFo if (targetInfo == maskedFormatInfo1 || targetInfo == maskedFormatInfo2) { // Found an exact match Ref result(new FormatInformation(decodeInfo[1], possiableFix_, err_handler)); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return Ref(); return result; } @@ -112,7 +122,7 @@ Ref FormatInformation::doDecodeFormatInformation(int maskedFo } if (bestDifference <= 3) { Ref result(new FormatInformation(bestFormatInfo, possiableFix_, err_handler)); - if (err_handler.ErrCode()) + if (err_handler.errCode()) return Ref(); return result; } diff --git a/modules/objdetect/src/zxing/qrcode/format_information.hpp b/modules/objdetect/src/zxing/qrcode/format_information.hpp index 34e6351802..82c304e2e3 100644 --- a/modules/objdetect/src/zxing/qrcode/format_information.hpp +++ b/modules/objdetect/src/zxing/qrcode/format_information.hpp @@ -1,5 +1,15 @@ -#ifndef __FORMAT_INFORMATION_H__ -#define __FORMAT_INFORMATION_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_QRCODE_FORMAT_INFORMATION_HPP__ +#define __ZXING_QRCODE_FORMAT_INFORMATION_HPP__ /* * FormatInformation.hpp @@ -53,4 +63,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // __FORMAT_INFORMATION_H__ +#endif // __ZXING_QRCODE_FORMAT_INFORMATION_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/qrcode_reader.cpp b/modules/objdetect/src/zxing/qrcode/qrcode_reader.cpp index 5ada816443..5503d56c24 100644 --- a/modules/objdetect/src/zxing/qrcode/qrcode_reader.cpp +++ b/modules/objdetect/src/zxing/qrcode/qrcode_reader.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * QRCodeReader.cpp @@ -68,21 +78,21 @@ Ref QRCodeReader::decode(Ref image, DecodeHints hints) { // Binarize image using the Histogram Binarized method and be binarized ErrorHandler err_handler; Ref imageBitMatrix = image->getBlackMatrix(err_handler); - if (err_handler.ErrCode() || imageBitMatrix == NULL) + if (err_handler.errCode() || imageBitMatrix == NULL) return Ref(); Ref rst = decodeMore(image, imageBitMatrix, hints, err_handler); - if (err_handler.ErrCode() || rst == NULL) + if (err_handler.errCode() || rst == NULL) { reader_call_path_ += "1"; // enter mirro // black white mirro!!! Ref invertedMatrix = image->getInvertedMatrix(err_handler); - if (err_handler.ErrCode() || invertedMatrix == NULL) + if (err_handler.errCode() || invertedMatrix == NULL) return Ref(); Ref rst_ = decodeMore(image, invertedMatrix, hints, err_handler); - if (err_handler.ErrCode() || rst == NULL) + if (err_handler.errCode() || rst == NULL) return Ref(); return rst_; } @@ -101,18 +111,18 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima nowHints_ = hints; std::string ept; - image->m_poUnicomBlock->Init(); - image->m_poUnicomBlock->Reset(imageBitMatrix); + image->m_poUnicomBlock->init(); + image->m_poUnicomBlock->reset(imageBitMatrix); // detect - err_handler.Reset(); + err_handler.reset(); Ref detector(new Detector(imageBitMatrix, image->m_poUnicomBlock)); detector->detect(hints, err_handler); setReaderState(detector->getState()); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { err_handler = zxing::ReaderErrorHandler("error detect"); - ept = err_handler.ErrMsg(); + ept = err_handler.errMsg(); reader_call_path_ += "2"; // detect fail return Ref(); } @@ -149,14 +159,14 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima for (int j = 0; j < possibleAlignmentCount; j++) { ArrayRef< Ref > points; - err_handler.Reset(); + err_handler.reset(); Ref alignpattern = detector->getAlignmentPattern(i, j); Ref detectorResult = detector->getResultViaAlignment(i, j, detectedDimension_, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { - ept = err_handler.ErrCode(); + ept = err_handler.errCode(); setDecoderFix(decoder_.getPossibleFix(), points); setReaderState(decoder_.getState()); @@ -170,9 +180,9 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima points = detectorResult->getPoints(); Ref decoderResult(decoder_.decode(detectorResult->getBits(), err_handler)); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { - ept = err_handler.ErrCode(); + ept = err_handler.errCode(); setDecoderFix(decoder_.getPossibleFix(), points); setReaderState(decoder_.getState()); @@ -223,20 +233,20 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima } // decode - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, true, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } if (!is_decode_success) { - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, false, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } @@ -266,11 +276,11 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima } { - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, true, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } @@ -278,11 +288,11 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima { if (!is_decode_success) { - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, false, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } @@ -300,21 +310,21 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima pts_src[kk] = corner_pts_src[segment_len + kk - begin_idx]; } - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, true, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } } if (!is_decode_success) { - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, false, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } @@ -329,21 +339,21 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima pts_src[kk] = corner_pts_src[2 * segment_len + kk - begin_idx]; } - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, true, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } } if (!is_decode_success) { - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, false, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } @@ -377,11 +387,11 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima } { - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, true, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } @@ -389,11 +399,11 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima { if (!is_decode_success) { - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, false, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } @@ -411,21 +421,21 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima for (size_t kk = begin_idx; kk < pts_src.size(); kk ++) { pts_src[kk] = corner_pts_src[segment_len + kk - begin_idx]; } - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, true, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } } if (!is_decode_success) { - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, false, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } @@ -441,21 +451,21 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima for (size_t kk = begin_idx; kk < pts_src.size(); kk ++) { pts_src[kk] = corner_pts_src[2 * segment_len + kk - begin_idx]; } - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, true, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } } if (!is_decode_success) { - err_handler.Reset(); + err_handler.reset(); detectorResult = detector->getResultViaPoints(hints, detectedDimension_, pts_src, pts_dst, false, err_handler); - if (detectorResult != NULL && err_handler.ErrCode() == 0) { + if (detectorResult != NULL && err_handler.errCode() == 0) { decoderResult = decoder_.decode(detectorResult->getBits(), err_handler); - if (decoderResult != NULL && err_handler.ErrCode() == 0) { + if (decoderResult != NULL && err_handler.errCode() == 0) { is_decode_success = true; } } @@ -464,7 +474,7 @@ Ref QRCodeReader::decodeMore(Ref image, Ref ima } } - if (err_handler.ErrCode() || detectorResult == NULL || decoderResult == NULL) + if (err_handler.errCode() || detectorResult == NULL || decoderResult == NULL) continue; } diff --git a/modules/objdetect/src/zxing/qrcode/qrcode_reader.hpp b/modules/objdetect/src/zxing/qrcode/qrcode_reader.hpp index 50f3777715..17d7d698d5 100644 --- a/modules/objdetect/src/zxing/qrcode/qrcode_reader.hpp +++ b/modules/objdetect/src/zxing/qrcode/qrcode_reader.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __QR_CODE_READER_H__ -#define __QR_CODE_READER_H__ +#ifndef __ZXING_QRCODE_QRCODE_READER_HPP__ +#define __ZXING_QRCODE_QRCODE_READER_HPP__ /* * QRCodeReader.hpp @@ -170,4 +180,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // __QR_CODE_READER_H__ +#endif // __ZXING_QRCODE_QRCODE_READER_HPP__ diff --git a/modules/objdetect/src/zxing/qrcode/version.cpp b/modules/objdetect/src/zxing/qrcode/version.cpp index 3148b7e6c3..3be872b261 100644 --- a/modules/objdetect/src/zxing/qrcode/version.cpp +++ b/modules/objdetect/src/zxing/qrcode/version.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * Version.cpp * zxing @@ -140,7 +150,7 @@ Version *Version::getProvisionalVersionForDimension(int dimension, ErrorHandler } Version * version = Version::getVersionForNumber((dimension - 17) >> 2, err_handler); - if (err_handler.ErrCode()) + if (err_handler.errCode()) { err_handler = zxing::FormatErrorHandler("err format"); return NULL; @@ -196,7 +206,7 @@ Version *Version::decodeVersionInformation(unsigned int versionBits) { // Do the version info bits match exactly? done. if (targetVersion == versionBits) { Version* version = getVersionForNumber(i + 7 , err_handler); - if (err_handler.ErrCode()) return 0; + if (err_handler.errCode()) return 0; return version; } // Otherwise see if this is the closest to a real version info bit @@ -211,7 +221,7 @@ Version *Version::decodeVersionInformation(unsigned int versionBits) { // differ in less than 4 bits. if (bestDifference <= 3) { Version * version = getVersionForNumber(bestVersion , err_handler); - if (err_handler.ErrCode()) return 0; + if (err_handler.errCode()) return 0; return version; } // If we didn't find a close enough match, fail @@ -221,10 +231,10 @@ Version *Version::decodeVersionInformation(unsigned int versionBits) { Ref Version::buildFixedPatternValue(ErrorHandler & err_handler) { int dimension = getDimensionForVersion(err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); Ref fixedInfo(new BitMatrix(dimension, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); // first timming patterns for (int i = 0; i < dimension; i += 2) fixedInfo->set(i, 6); @@ -250,7 +260,7 @@ Ref Version::buildFixedPatternValue(ErrorHandler & err_handler) fixedInfo->flipRegion(0, dimension - 7, 7, 7, err_handler); fixedInfo->flipRegion(1, dimension - 6, 5, 5, err_handler); fixedInfo->flipRegion(2, dimension - 5, 3, 3, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); // alignment patterns size_t max = alignmentPatternCenters_.size(); @@ -264,7 +274,7 @@ Ref Version::buildFixedPatternValue(ErrorHandler & err_handler) fixedInfo->setRegion(alignmentPatternCenters_[y] - 2, i, 5, 5, err_handler); fixedInfo->flipRegion(alignmentPatternCenters_[y] - 1, i + 1, 3, 3, err_handler); fixedInfo->flipRegion(alignmentPatternCenters_[y], i + 2, 1, 1, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } } return fixedInfo; @@ -273,7 +283,7 @@ Ref Version::buildFixedPatternValue(ErrorHandler & err_handler) Ref Version::buildFixedPatternTemplate(ErrorHandler & err_handler) { int dimension = getDimensionForVersion(err_handler); Ref functionPattern(new BitMatrix(dimension, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); // Top left finder pattern + separator + format @@ -282,7 +292,7 @@ Ref Version::buildFixedPatternTemplate(ErrorHandler & err_handler) { functionPattern->setRegion(dimension - 8, 0, 8, 8, err_handler); // Bottom left finder pattern + separator + format functionPattern->setRegion(0, dimension - 8, 8, 8, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); // alignment patterns size_t max = alignmentPatternCenters_.size(); @@ -301,7 +311,7 @@ Ref Version::buildFixedPatternTemplate(ErrorHandler & err_handler) { functionPattern->setRegion(6, 8, 1, dimension - 16, err_handler); // Horizontal timing pattern functionPattern->setRegion(8, 6, dimension - 16, 1, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); return functionPattern; } @@ -309,7 +319,7 @@ Ref Version::buildFixedPatternTemplate(ErrorHandler & err_handler) { Ref Version::buildFunctionPattern(ErrorHandler & err_handler) { int dimension = getDimensionForVersion(err_handler); Ref functionPattern(new BitMatrix(dimension, err_handler)); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); // Top left finder pattern + separator + format functionPattern->setRegion(0, 0, 9, 9, err_handler); @@ -336,14 +346,14 @@ Ref Version::buildFunctionPattern(ErrorHandler & err_handler) { functionPattern->setRegion(6, 9, 1, dimension - 17, err_handler); // Horizontal timing pattern functionPattern->setRegion(9, 6, dimension - 17, 1, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); if (versionNumber_ > 6) { // Version info, top right functionPattern->setRegion(dimension - 11, 0, 3, 6, err_handler); // Version info, bottom left functionPattern->setRegion(0, dimension - 11, 6, 3, err_handler); - if (err_handler.ErrCode()) return Ref(); + if (err_handler.errCode()) return Ref(); } return functionPattern; diff --git a/modules/objdetect/src/zxing/qrcode/version.hpp b/modules/objdetect/src/zxing/qrcode/version.hpp index 20c3bbd8c5..74f35c528f 100644 --- a/modules/objdetect/src/zxing/qrcode/version.hpp +++ b/modules/objdetect/src/zxing/qrcode/version.hpp @@ -1,5 +1,15 @@ -#ifndef __VERSION_H__ -#define __VERSION_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_QRCODE_VERSION_HPP__ +#define __ZXING_QRCODE_VERSION_HPP__ /* * Version.hpp @@ -99,4 +109,4 @@ public: } // namespace qrcode } // namespace zxing -#endif // __VERSION_H__ +#endif // __ZXING_QRCODE_VERSION_HPP__ diff --git a/modules/objdetect/src/zxing/reader.cpp b/modules/objdetect/src/zxing/reader.cpp index 5277453811..3a7209847b 100644 --- a/modules/objdetect/src/zxing/reader.cpp +++ b/modules/objdetect/src/zxing/reader.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * Reader.cpp * zxing diff --git a/modules/objdetect/src/zxing/reader.hpp b/modules/objdetect/src/zxing/reader.hpp index 57312d0095..b3a108bb1a 100644 --- a/modules/objdetect/src/zxing/reader.hpp +++ b/modules/objdetect/src/zxing/reader.hpp @@ -1,5 +1,15 @@ -#ifndef __READER_H__ -#define __READER_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_READER_HPP__ +#define __ZXING_READER_HPP__ /* * Reader.hpp @@ -49,6 +59,6 @@ public: } // namespace zxing -#endif // QBAR_AI_QBAR_ZXING_READER_H_ +#endif // __ZXING_READER_HPP__ diff --git a/modules/objdetect/src/zxing/reader_exception.hpp b/modules/objdetect/src/zxing/reader_exception.hpp index ef258aa673..4b688b6d20 100644 --- a/modules/objdetect/src/zxing/reader_exception.hpp +++ b/modules/objdetect/src/zxing/reader_exception.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __READER_EXCEPTION_H__ -#define __READER_EXCEPTION_H__ +#ifndef __ZXING_READER_EXCEPTION_HPP__ +#define __ZXING_READER_EXCEPTION_HPP__ /* * ReaderException.hpp @@ -34,4 +44,4 @@ public: } -#endif // __READER_EXCEPTION_H__ +#endif // __ZXING_READER_EXCEPTION_HPP__ diff --git a/modules/objdetect/src/zxing/result.cpp b/modules/objdetect/src/zxing/result.cpp index 29f80f78c9..f88b9cedac 100644 --- a/modules/objdetect/src/zxing/result.cpp +++ b/modules/objdetect/src/zxing/result.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Result.cpp @@ -98,8 +108,8 @@ ArrayRef< Ref >& Result::getResultPoints() { void Result::setResultPoints(int idx, float x, float y){ if (idx < 0 || idx >= resultPoints_->size()) return; - resultPoints_[idx]->SetX(x); - resultPoints_[idx]->SetY(y); + resultPoints_[idx]->setX(x); + resultPoints_[idx]->setY(y); } void Result::enlargeResultPoints(int scale){ diff --git a/modules/objdetect/src/zxing/result.hpp b/modules/objdetect/src/zxing/result.hpp index 40ddaaf872..e0183524e0 100644 --- a/modules/objdetect/src/zxing/result.hpp +++ b/modules/objdetect/src/zxing/result.hpp @@ -1,5 +1,15 @@ -#ifndef __RESULT_H__ -#define __RESULT_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_RESULT_HPP__ +#define __ZXING_RESULT_HPP__ /* * Result.hpp @@ -147,4 +157,4 @@ public: }; } // namespace zxing -#endif // __RESULT_H__ +#endif // __ZXING_RESULT_HPP__ diff --git a/modules/objdetect/src/zxing/result_io.cpp b/modules/objdetect/src/zxing/result_io.cpp index c2a00938c3..660c610cce 100644 --- a/modules/objdetect/src/zxing/result_io.cpp +++ b/modules/objdetect/src/zxing/result_io.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * ResultIO.cpp diff --git a/modules/objdetect/src/zxing/result_point.cpp b/modules/objdetect/src/zxing/result_point.cpp index 3feaf791b9..cdad5a87a1 100644 --- a/modules/objdetect/src/zxing/result_point.cpp +++ b/modules/objdetect/src/zxing/result_point.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * ResultPoint.cpp @@ -45,12 +55,12 @@ float ResultPoint::getY() const return posY_; } -void ResultPoint::SetX(float fX) +void ResultPoint::setX(float fX) { posX_ = fX; } -void ResultPoint::SetY(float fY) +void ResultPoint::setY(float fY) { posY_ = fY; } diff --git a/modules/objdetect/src/zxing/result_point.hpp b/modules/objdetect/src/zxing/result_point.hpp index 73628402da..94b4ff4d23 100644 --- a/modules/objdetect/src/zxing/result_point.hpp +++ b/modules/objdetect/src/zxing/result_point.hpp @@ -1,6 +1,16 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __RESULT_POINT_H__ -#define __RESULT_POINT_H__ +#ifndef __ZXING_RESULT_POINT_HPP__ +#define __ZXING_RESULT_POINT_HPP__ /* * ResultPoint.hpp @@ -39,8 +49,8 @@ public: virtual float getX() const; virtual float getY() const; - virtual void SetX(float fX); - virtual void SetY(float fY); + virtual void setX(float fX); + virtual void setY(float fY); bool equals(Ref other); @@ -54,4 +64,4 @@ private: } // namespace zxing -#endif // __RESULT_POINT_H__ +#endif // __ZXING_RESULT_POINT_HPP__ diff --git a/modules/objdetect/src/zxing/result_point_callback.cpp b/modules/objdetect/src/zxing/result_point_callback.cpp index d54c8c0393..8271459061 100644 --- a/modules/objdetect/src/zxing/result_point_callback.cpp +++ b/modules/objdetect/src/zxing/result_point_callback.cpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + /* * ResultPointCallback.cpp * zxing diff --git a/modules/objdetect/src/zxing/result_point_callback.hpp b/modules/objdetect/src/zxing/result_point_callback.hpp index d22f24ca3f..46fef74471 100644 --- a/modules/objdetect/src/zxing/result_point_callback.hpp +++ b/modules/objdetect/src/zxing/result_point_callback.hpp @@ -1,5 +1,15 @@ -#ifndef __RESULT_POINT_CALLBACK_H__ -#define __RESULT_POINT_CALLBACK_H__ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + +#ifndef __ZXING_RESULT_POINT_CALLBACK_HPP__ +#define __ZXING_RESULT_POINT_CALLBACK_HPP__ /* * ResultPointCallback.hpp @@ -36,4 +46,4 @@ public: } // namespace zxing -#endif // QBAR_AI_QBAR_ZXING_RESULTPOINTCALLBACK_H_ +#endif // __ZXING_RESULT_POINT_CALLBACK_HPP__ diff --git a/modules/objdetect/src/zxing/zxing.hpp b/modules/objdetect/src/zxing/zxing.hpp index 7f9d2de734..67c275ec5f 100644 --- a/modules/objdetect/src/zxing/zxing.hpp +++ b/modules/objdetect/src/zxing/zxing.hpp @@ -1,3 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Tencent is pleased to support the open source community by making WeChat QRCode available. +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Modified from ZXing. Copyright ZXing authors. +// Licensed under the Apache License, Version 2.0 (the "License"). + // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2013 ZXing authors All rights reserved. @@ -14,8 +24,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __ZXING_H_ -#define __ZXING_H_ +#ifndef __ZXING_ZXING_HPP__ +#define __ZXING_ZXING_HPP__ //>>>>>>>> type define @@ -177,4 +187,4 @@ private: #define ZXING_TIME_MARK(string) (void)0 #endif -#endif +#endif // __ZXING_ZXING_HPP__