add license and update function name and add implementation for detect and decode.

This commit is contained in:
cswccc 2024-11-18 20:04:15 +08:00
parent 7fbda0a5ac
commit b77047fc08
244 changed files with 3567 additions and 6745 deletions

View File

@ -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)
main()

View File

@ -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<DECODER_READER> 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<DECODER_READER>& readers = std::vector<DECODER_READER>(),
const float detector_iou_thres = 0.6,

View File

@ -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<Binarizer> BinarizerMgr::Binarize(zxing::Ref<LuminanceSource> 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;
}

View File

@ -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<zxing::Binarizer> Binarize(zxing::Ref<zxing::LuminanceSource> 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<BINARIZER> m_vecRotateBinarizer;
};
} // namesapce cv
} // namesapce cv
#endif // __OPENCV_BINARZERMGR_HPP__

View File

@ -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 <iostream>
#define CLIP(x, x1, x2) (std::fmax<float>)(x1, (std::fmin<float>)(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<DetectInfo> &bboxes)
int QBarDetector::detect(const Mat &image,std::vector<DetectInfo> &bboxes)
{
Mat input_blob;
int ret = this->pre_process_det(image,input_blob);

View File

@ -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 <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
@ -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<DetectInfo> &bboxes);
int init(const std::string &config_path);
int detect(const Mat &image,std::vector<DetectInfo> &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;}

View File

@ -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 <iostream>
@ -57,12 +64,12 @@ int gettimeofday(struct timeval *tp, void *tzp)
#endif
namespace cv {
void QBarDecoder::Detect(Mat srcImage, std::vector<DetectInfo> &bboxes) {
void QBarDecoder::detect(Mat srcImage, std::vector<DetectInfo> &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<LuminanceSource> source, Ref<Result> &result, DecodeHints& decodeHints)
int QBarDecoder::decode(Ref<LuminanceSource> source, Ref<Result> &result, DecodeHints& decodeHints)
{
int res = -1;
std::string cell_result;
@ -149,19 +156,19 @@ int QBarDecoder::Decode(Ref<LuminanceSource> source, Ref<Result> &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<int>(binarizer_mgr_.GetCurBinarizer()));
result->setBinaryMethod(static_cast<int>(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<std::mutex> 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<Point2f> points_qr;
@ -311,7 +318,7 @@ private:
std::vector<QBAR_RESULT>& results;
};
std::vector<QBAR_RESULT> QBarDecoder::Decode(Mat srcImage, std::vector<DetectInfo>& detect_results) {
std::vector<QBAR_RESULT> QBarDecoder::decode(Mat srcImage, std::vector<DetectInfo>& detect_results) {
std::vector<QBAR_RESULT> results(detect_results.size());
ParallelDecode parallelDecode(this, srcImage, detect_results, results);
@ -390,7 +397,7 @@ void QBarDecoder::nms(std::vector<QBAR_RESULT>& 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<QBarDetector>(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<SuperScale>(new SuperScale());
ret = sr_->Init(ml_mode.super_resolution_model_path_);
ret = sr_->init(ml_mode.super_resolution_model_path_);
if(ret)
{
return ret;

View File

@ -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 <iostream>
#include <string>
@ -45,7 +52,7 @@ public:
QBarDecoder() = default;
~QBarDecoder() = default;
void SetReaders(const std::unordered_set<QBAR_READER> &readers) { readers_ = readers; }
void setReaders(const std::unordered_set<QBAR_READER> &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<DetectInfo> &bboxes);
QBAR_RESULT Decode(Mat& srcImage);
std::vector<QBAR_RESULT> Decode(Mat srcImage, std::vector<DetectInfo> &_detect_results_);
void detect(Mat srcImage, std::vector<DetectInfo> &bboxes);
QBAR_RESULT decode(Mat& srcImage);
std::vector<QBAR_RESULT> decode(Mat srcImage, std::vector<DetectInfo> &_detect_results_);
int InitAIModel(QBAR_ML_MODE &ml_mode);
int initAIModel(QBAR_ML_MODE &ml_mode);
private:
int Decode(zxing::Ref<zxing::LuminanceSource> source, zxing::Ref<zxing::Result> &result, zxing::DecodeHints& decodeHints);
QBAR_RESULT ProcessResult(zxing::Result *zx_result);
void AddFormatsToDecodeHints(zxing::DecodeHints &hints);
int decode(zxing::Ref<zxing::LuminanceSource> source, zxing::Ref<zxing::Result> &result, zxing::DecodeHints& decodeHints);
QBAR_RESULT processResult(zxing::Result *zx_result);
void addFormatsToDecodeHints(zxing::DecodeHints &hints);
void nms(std::vector<QBAR_RESULT>& 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__

View File

@ -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);
}

View File

@ -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
} // namespace cv
#endif // __OPENCV_QBARSOURCE_HPP__

View File

@ -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 <stdint.h>
#include <string>
@ -382,4 +392,4 @@ struct QBarDrawParam {
}
};
} // namespace cv
#endif // QBAR_AI_QBAR_QBARSTRUCT_H_
#endif // __OPENCV_QBARSTRUCT_HPP__

View File

@ -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<PimplQRAruco>(p)->arucoDetector.setDetectorParameters(params);
}
struct PimplCode : public ImplContour {
struct PimplWeChat : public GraphicalCodeDetector::Impl {
std::shared_ptr<QBarDecoder> qbarDecode_;
PimplCode() {
PimplWeChat() {
qbarDecode_ = make_shared<QBarDecoder>();
}
bool detectMulti(InputArray in, OutputArray points) const override {
Mat gray;
if (!checkQRInputImage(in, gray)) {
points.release();
return false;
}
std::vector<DetectInfo> _detect_results;
qbarDecode_->Detect(gray, _detect_results);
vector<Point2f> 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<cv::String>& 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<DetectInfo> 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<Point2f> 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<QBAR_RESULT> 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<cv::String>& 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<string>& decoded_info, OutputArrayOfArrays straight_qrcode) const CV_OVERRIDE;
bool detectAndDecodeMulti(InputArray img, vector<string>& 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<Point2f> 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<float>::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<float>(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<string> 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<DetectInfo> _detect_results;
qbarDecode_->detect(gray, _detect_results);
vector<Point2f> 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<cv::String>& 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<DetectInfo> 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<Point2f> 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<QBAR_RESULT> 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<cv::String>& 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<DECODER_READER>& readers,
const float detector_iou_thres,
const float decoder_iou_thres,
const float score_thres,
const int reference_size) {
p = makePtr<PimplCode>();
p = makePtr<PimplWeChat>();
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<PimplCode>(p)->qbarDecode_->InitAIModel(mode.qbar_ml_mode);
int ret = std::dynamic_pointer_cast<PimplWeChat>(p)->qbarDecode_->initAIModel(mode.qbar_ml_mode);
if (ret) {
return;
}
CV_Assert(ret == 0);
if (readers.empty()) {
std::dynamic_pointer_cast<PimplCode>(p)->qbarDecode_->SetReaders({ONED_BARCODE, QRCODE, PDF417, DATAMATRIX});
std::dynamic_pointer_cast<PimplWeChat>(p)->qbarDecode_->setReaders({ONED_BARCODE, QRCODE, PDF417, DATAMATRIX});
}
else {
unordered_set<QBAR_READER> readers_;
@ -4846,26 +4891,26 @@ CodeDetector::CodeDetector(const std::string& detection_model_path_,
readers_.insert(static_cast<QBAR_READER>(reader));
}
std::dynamic_pointer_cast<PimplCode>(p)->qbarDecode_->SetReaders(readers_);
std::dynamic_pointer_cast<PimplWeChat>(p)->qbarDecode_->setReaders(readers_);
}
std::dynamic_pointer_cast<PimplCode>(p)->qbarDecode_->setDetectorReferenceSize(reference_size);
std::dynamic_pointer_cast<PimplCode>(p)->qbarDecode_->setDetectorScoreThres(score_thres);
std::dynamic_pointer_cast<PimplCode>(p)->qbarDecode_->setDetectorIouThres(detector_iou_thres);
std::dynamic_pointer_cast<PimplCode>(p)->qbarDecode_->setDecoderIouThres(decoder_iou_thres);
std::dynamic_pointer_cast<PimplWeChat>(p)->qbarDecode_->setDetectorReferenceSize(reference_size);
std::dynamic_pointer_cast<PimplWeChat>(p)->qbarDecode_->setDetectorScoreThres(score_thres);
std::dynamic_pointer_cast<PimplWeChat>(p)->qbarDecode_->setDetectorIouThres(detector_iou_thres);
std::dynamic_pointer_cast<PimplWeChat>(p)->qbarDecode_->setDecoderIouThres(decoder_iou_thres);
}
void CodeDetector::setDetectorReferenceSize(int reference_size) {
std::dynamic_pointer_cast<PimplCode>(p)->qbarDecode_->setDetectorReferenceSize(reference_size);
void CodeDetectorWeChat::setDetectorReferenceSize(int reference_size) {
std::dynamic_pointer_cast<PimplWeChat>(p)->qbarDecode_->setDetectorReferenceSize(reference_size);
}
void CodeDetector::setDetectorScoreThres(float score_thres) {
std::dynamic_pointer_cast<PimplCode>(p)->qbarDecode_->setDetectorScoreThres(score_thres);
void CodeDetectorWeChat::setDetectorScoreThres(float score_thres) {
std::dynamic_pointer_cast<PimplWeChat>(p)->qbarDecode_->setDetectorScoreThres(score_thres);
}
void CodeDetector::setDetectorIouThres(float iou_thres) {
std::dynamic_pointer_cast<PimplCode>(p)->qbarDecode_->setDetectorIouThres(iou_thres);
void CodeDetectorWeChat::setDetectorIouThres(float iou_thres) {
std::dynamic_pointer_cast<PimplWeChat>(p)->qbarDecode_->setDetectorIouThres(iou_thres);
}
void CodeDetector::setDecoderIouThres(float iou_thres) {
std::dynamic_pointer_cast<PimplCode>(p)->qbarDecode_->setDecoderIouThres(iou_thres);
void CodeDetectorWeChat::setDecoderIouThres(float iou_thres) {
std::dynamic_pointer_cast<PimplWeChat>(p)->qbarDecode_->setDecoderIouThres(iou_thres);
}
} // namespace

View File

@ -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);

View File

@ -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:

View File

@ -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.

View File

@ -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__

View File

@ -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<BitArray> Binarizer::getBlackRow(int y, Ref<BitArray> row, ErrorHandler & er
if (!matrix_)
{
matrix_ = getBlackMatrix(err_handler);
if (err_handler.ErrCode()) return Ref<BitArray>();
if (err_handler.errCode()) return Ref<BitArray>();
}
matrix_->getRow(y, row);

View File

@ -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__

View File

@ -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<BitArray> BinaryBitmap::getBlackRow(int y, Ref<BitArray> row, ErrorHandler & err_handler) {
Ref<BitArray> bitary = binarizer_->getBlackRow(y, row, err_handler);
if (err_handler.ErrCode()) return Ref<BitArray>();
if (err_handler.errCode()) return Ref<BitArray>();
return bitary;
}
Ref<BitMatrix> BinaryBitmap::getBlackMatrix(ErrorHandler & err_handler) {
Ref<BitMatrix> bitmtx = binarizer_->getBlackMatrix(err_handler);
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
return bitmtx;
}
Ref<BitMatrix> BinaryBitmap::getInvertedMatrix(ErrorHandler & err_handler) {
Ref<BitMatrix> bitmtx = binarizer_->getInvertedMatrix(err_handler);
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
return bitmtx;
}

View File

@ -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__

View File

@ -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

View File

@ -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__

View File

@ -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__

View File

@ -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;

View File

@ -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<int> counters);
@ -100,4 +110,4 @@ std::ostream& operator << (std::ostream&, BitArray const&);
} // namespace zxing
#endif // __BIT_ARRAY_H__
#endif // __ZXING_COMMON_BIT_ARRAY_HPP__

View File

@ -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.

View File

@ -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));
}

View File

@ -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__

View File

@ -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

View File

@ -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__

View File

@ -1,48 +0,0 @@
#ifndef __BYTE_MATRIX_H__
#define __BYTE_MATRIX_H__
#include "counted.hpp"
#include "bit_array.hpp"
#include "array.hpp"
#include <limits>
namespace zxing {
class ByteMatix : public Counted {
public:
ByteMatix(int dimension);
ByteMatix(int width, int height);
ByteMatix(int width, int height, ArrayRef<char> 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<char> getRow(int y, ArrayRef<char> row);
int getWidth() const { return width; }
int getHeight() const {return height;}
private:
int width;
int height;
ArrayRef<char> bytes;
ArrayRef<int> row_offsets;
private:
inline void init(int, int);
ByteMatix(const ByteMatix&);
ByteMatix& operator =(const ByteMatix&);
};
}
#endif

View File

@ -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"

View File

@ -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__

View File

@ -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 <iostream>
#include <stdio.h>
#include <ctype.h>
#ifndef ZXing_Character_h
#define ZXing_Character_h
namespace zxing
{
@ -58,4 +67,4 @@ namespace zxing
};
}
#endif
#endif // __ZXING_COMMON_CHARACTER_HPP__

View File

@ -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

View File

@ -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__

View File

@ -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 <assert.h>
@ -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);

View File

@ -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 <string>
#include <map>
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<int, char> m_tIntToChar[COMPRESS_BASE];
std::map<char, int> 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__

View File

@ -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__

View File

@ -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 <iostream>
static const std::string base64_chars =
@ -97,4 +109,5 @@ inline std::string base64_decode(std::string const& encoded_string) {
}
return ret;
}
}
#endif // __ZXING_COMMON_DEBUG_TOOLS_HPP__

View File

@ -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

View File

@ -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__

View File

@ -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__

View File

@ -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<float> & 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<float> & 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__

View File

@ -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<Ref<ResultPoint> > MonochromeRectangleDetector::detect(ErrorHandler & err
right = static_cast<int>(pointC->getX()) + 1;
Ref<ResultPoint> pointD(findCornerFromCenter(halfWidth, 0, left, right,
halfHeight, deltaY, top, bottom, halfWidth >> 1, err_handler));
if (err_handler.ErrCode()) return vector<Ref<ResultPoint> >();
if (err_handler.errCode()) return vector<Ref<ResultPoint> >();
bottom = static_cast<int>(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<Ref<ResultPoint> >();
if (err_handler.errCode()) return vector<Ref<ResultPoint> >();
vector<Ref<ResultPoint> > corners(4);
corners[0].reset(pointA);

View File

@ -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__

View File

@ -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

View File

@ -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__

View File

@ -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

View File

@ -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

View File

@ -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<BitMatrix> FastWindowBinarizer::getBlackMatrix(ErrorHandler & err_handler) {
if (!matrix0_)
{
binarizeImage1(err_handler);
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
}
return Binarizer::getBlackMatrix(err_handler);
@ -102,7 +112,7 @@ Ref<BitArray> FastWindowBinarizer::getBlackRow(int y, Ref<BitArray> row, ErrorHa
if (!matrix0_)
{
binarizeImage1(err_handler);
if (err_handler.ErrCode()) return Ref<BitArray>();
if (err_handler.errCode()) return Ref<BitArray>();
}
// 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<BitMatrix> matrix(new BitMatrix(width, height, err_handler));
if (err_handler.ErrCode()) return -1;
if (err_handler.errCode()) return -1;
ArrayRef<char> 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<BitMatrix> 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++)

View File

@ -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

View File

@ -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<BitArray> GlobalHistogramBinarizer::getBlackRow(int y, Ref<BitArray> row, Er
if (!matrix0_)
{
binarizeImage0(err_handler);
if (err_handler.ErrCode()) return Ref<BitArray>();
if (err_handler.errCode()) return Ref<BitArray>();
}
// Call parent getBlackMatrix to get current matrix
return Binarizer::getBlackRow(y, row, err_handler);
@ -72,7 +82,7 @@ Ref<BitArray> GlobalHistogramBinarizer::getBlackRow(int y, Ref<BitArray> row, Er
// Does not sharpen the data, as this call is intended to only be used by 2D readers.
Ref<BitMatrix> GlobalHistogramBinarizer::getBlackMatrix(ErrorHandler &err_handler) {
binarizeImage0(err_handler);
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
// 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<BitMatrix> 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<char> 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<height*3/5-1; row+=4){
ArrayRef<char> 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<char> 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<char> localLuminances = source.getMatrix();
for (int y = 0; y < height; y++) {

View File

@ -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__

View File

@ -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<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise(ErrorHandl
new GreyscaleRotatedLuminanceSource(greyData_,
dataWidth_, dataHeight_,
top_, left_, getHeight(), getWidth(), err_handler));
if (err_handler.ErrCode()) return Ref<LuminanceSource>();
if (err_handler.errCode()) return Ref<LuminanceSource>();
return result;
}

View File

@ -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__

View File

@ -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

View File

@ -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__

View File

@ -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<ByteMatrix> GridSampler::sampleGrid(Ref<ByteMatrix> 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<ByteMatrix>();
if (err_handler.errCode()) return Ref<ByteMatrix>();
if (outlier >= maxOutlier)
{
@ -72,7 +82,7 @@ Ref<ByteMatrix> GridSampler::sampleGrid(Ref<ByteMatrix> image, int dimension, Re
Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform, ErrorHandler &err_handler) {
Ref<BitMatrix> bits(new BitMatrix(dimension, err_handler));
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
std::vector<float> points(dimension << 1, (const float)0.0f);
@ -91,7 +101,7 @@ Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> 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<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
if (outlier >= maxOutlier)
{
@ -159,7 +169,7 @@ Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<
Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, cv::Mat& transform, ErrorHandler &err_handler) {
Ref<BitMatrix> bits(new BitMatrix(dimension, err_handler));
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
std::vector<cv::Point2f> points(dimension);
@ -177,7 +187,7 @@ Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> 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<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
if (outlier >= maxOutlier)
{
@ -249,7 +259,7 @@ Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension,
{
Ref<BitMatrix> bits(new BitMatrix(dimension, err_handler));
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
std::vector<cv::Point2f> points(dimension);
@ -270,7 +280,7 @@ Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> 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<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
if (outlier >= maxOutlier)
{
@ -337,7 +347,7 @@ Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension,
Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimensionX, int dimensionY, Ref<PerspectiveTransform> transform, ErrorHandler &err_handler)
{
Ref<BitMatrix> bits(new BitMatrix(dimensionX, dimensionY, err_handler));
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
std::vector<float> points(dimensionX << 1, (const float)0.0f);
for (int y = 0; y < dimensionY; y++)
{
@ -350,7 +360,7 @@ Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimensionX, int
}
transform->transformPoints(points);
checkAndNudgePoints(image->getWidth(), image->getHeight(), points, err_handler);
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
for (int x = 0; x < max; x += 2)
{
if (image->get(static_cast<int>(points[x]), static_cast<int>(points[x + 1])))
@ -370,7 +380,7 @@ Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, floa
p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY));
Ref<BitMatrix> rst = sampleGrid(image, dimension, transform, err_handler);
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
return rst;
}
@ -382,7 +392,7 @@ Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimensionX, int
p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY));
Ref<BitMatrix> rst = sampleGrid(image, dimensionX, dimensionY, transform, err_handler);
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
return rst;
}

View File

@ -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__

View File

@ -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<LuminanceSource> source) {
return Ref<Binarizer> (new GlobalHistogramBinarizer(source));
}
/* Init integral
/* init integral
*/
int HybridBinarizer::initBlockIntegral()
{
@ -134,7 +144,7 @@ Ref<BitMatrix> HybridBinarizer::getBlackMatrix(ErrorHandler &err_handler)
if (!matrix0_)
{
binarizeByBlock(0, err_handler);
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
}
// First call binarize image in child class to get matrix0_ and binCache
@ -154,7 +164,7 @@ Ref<BitArray> HybridBinarizer::getBlackRow(int y, Ref<BitArray> row, ErrorHandle
if (!matrix0_)
{
binarizeByBlock(0, err_handler);
if (err_handler.ErrCode()) return Ref<BitArray>();
if (err_handler.errCode()) return Ref<BitArray>();
}
// Call parent getBlackMatrix to get current matrix
@ -247,7 +257,7 @@ void HybridBinarizer::calculateThresholdForBlock(Ref<ByteMatrix>& 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<ByteMatrix>& 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<ByteMatrix>& 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<ByteMatrix>& 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<ByteMatrix>& 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<BitMatrix> 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;

View File

@ -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__

View File

@ -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

View File

@ -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__

View File

@ -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 <cstdio>
@ -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<ByteMatrix> matrix, float fRatio, ImageCutResult & result)
int ImageCut::cut( Ref<ByteMatrix> matrix, float fRatio, ImageCutResult & result)
{
int iWidth = matrix->getWidth();
int iHeight = matrix->getHeight();

View File

@ -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 <stdint.h>
#include <vector>
#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<ByteMatrix> 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<ByteMatrix> matrix , float fRatio, ImageCutResult & result);
};
} // namespace zxing
#endif // __ZXING_COMMON_IMAGE_CUT_HPP__

View File

@ -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 <iostream>
#ifndef ZXing_Integer_h
#define ZXing_Integer_h
namespace zxing
{
@ -28,4 +37,4 @@ public:
}
#endif
#endif // __ZXING_COMMON_INTEGER_HPP__

View File

@ -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<double> a, std::vector<double> 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();

View File

@ -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<vector>
@ -17,3 +28,4 @@ double cal_distance(std::vector<double> a, std::vector<double> b);
std::vector<Cluster> k_means(std::vector<std::vector<double> > trainX, uint k, uint maxepoches, uint minchanged);
} // namespace zxing
#endif // __ZXING_COMMON_KMEANS_HPP__

View File

@ -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<ByteMatrix> NewGridSampler::sampleGrid(Ref<ByteMatrix> 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<ByteMatrix>();
if (err_handler.errCode()) return Ref<ByteMatrix>();
if (outlier >= maxOutlier)
{
@ -53,7 +63,7 @@ Ref<ByteMatrix> NewGridSampler::sampleGrid(Ref<ByteMatrix> image, int dimension,
// Samples an image for a rectangular matrix of bits of the given dimension.
Ref<BitMatrix> NewGridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform, float fInitialMS, ErrorHandler & err_handler) {
Ref<BitMatrix> bits(new BitMatrix(dimension, err_handler));
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
std::vector<float> points(dimension << 1, (const float)0.0f);
@ -83,20 +93,20 @@ Ref<BitMatrix> NewGridSampler::sampleGrid(Ref<BitMatrix> 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<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
}
}
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<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
}
}
}
@ -129,14 +139,14 @@ Ref<BitMatrix> NewGridSampler::sampleGrid(Ref<BitMatrix> 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<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
}
}
@ -151,14 +161,14 @@ Ref<BitMatrix> NewGridSampler::sampleGrid(Ref<BitMatrix> 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<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
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<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
}
for (int x = 0; x < max; x += 2) {
@ -182,7 +192,7 @@ int NewGridSampler::checkAndNudgePoints(int width, int height, std::vector<float
else
{
err_handler = ReaderErrorHandler("checkAndNudgePoints:: no points!");
if (err_handler.ErrCode()) return -1;
if (err_handler.errCode()) return -1;
}
// The Java code assumes that if the start and end points are in bounds, the rest will also be.

View File

@ -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_NEW_GRID_SAMPLER_HPP__
#define __ZXING_COMMON_NEW_GRID_SAMPLER_HPP__
/*
* NewGridSampler.hpp
@ -45,3 +56,4 @@ public:
static NewGridSampler &getInstance();
};
} // namespace zxing
#endif // __ZXING_COMMON_NEW_GRID_SAMPLER_HPP__

View File

@ -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").
/*
* PerspectiveTransform.cpp
* zxing

View File

@ -1,5 +1,15 @@
#ifndef __PERSPECTIVE_TANSFORM_H__
#define __PERSPECTIVE_TANSFORM_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_PERSPECTIVE_TANSFORM_HPP__
#define __ZXING_COMMON_PERSPECTIVE_TANSFORM_HPP__
/*
* PerspectiveTransform.hpp
@ -47,4 +57,4 @@ public:
};
} // namespace zxing
#endif // __PERSPECTIVE_TANSFORM_H__
#endif // __ZXING_COMMON_PERSPECTIVE_TANSFORM_HPP__

View File

@ -1,5 +1,15 @@
#ifndef __POINT_H__
#define __POINT_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_POINT_HPP__
#define __ZXING_COMMON_POINT_HPP__
/*
* Point.hpp
@ -44,4 +54,4 @@ public:
Point end;
};
}
#endif // POINT_H_
#endif // __ZXING_COMMON_POINT_HPP__

View File

@ -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.cpp
@ -53,7 +63,7 @@ GenericGF::GenericGF(int primitive_, int size_, int b, ErrorHandler & err_handle
zero->getCoefficients()[0] = 0;
one = Ref<GenericGFPoly>(new GenericGFPoly(*this, ArrayRef<int>(new Array<int>(1)), err_handler));
one->getCoefficients()[0] = 1;
if (err_handler.ErrCode()) return;
if (err_handler.errCode()) return;
}
Ref<GenericGFPoly> GenericGF::getZero() {
@ -78,7 +88,7 @@ Ref<GenericGFPoly> GenericGF::buildMonomial(int degree, int coefficient, ErrorHa
coefficients[0] = coefficient;
Ref<GenericGFPoly> gfpoly(new GenericGFPoly(*this, coefficients, err_handler));
if (err_handler.ErrCode()) return Ref<GenericGFPoly>();
if (err_handler.errCode()) return Ref<GenericGFPoly>();
return gfpoly;
}

View File

@ -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 <vector>
#include "../counted.hpp"
@ -66,5 +76,5 @@ public:
};
} // namespace zxing
#endif // gENERICGF_H
#endif // __ZXING_COMMON_REEDSOLOMON_GENERIC_GF_HPP__

View File

@ -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> GenericGFPoly::addOrSubtract(Ref<zxing::GenericGFPoly> other,
}
Ref<GenericGFPoly> gfpoly(new GenericGFPoly(field_, sumDiff, err_handler));
if (err_handler.ErrCode()) return Ref<GenericGFPoly>();
if (err_handler.errCode()) return Ref<GenericGFPoly>();
return gfpoly;
}
@ -176,7 +186,7 @@ Ref<GenericGFPoly> GenericGFPoly::multiply(Ref<zxing::GenericGFPoly> other, Erro
}
Ref<GenericGFPoly> gfpoly(new GenericGFPoly(field_, product, err_handler));
if (err_handler.ErrCode()) return Ref<GenericGFPoly>();
if (err_handler.errCode()) return Ref<GenericGFPoly>();
return gfpoly;
}
@ -196,7 +206,7 @@ Ref<GenericGFPoly> GenericGFPoly::multiply(int scalar, ErrorHandler & err_handle
}
Ref<GenericGFPoly> gfpoly(new GenericGFPoly(field_, product, err_handler));
if (err_handler.ErrCode()) return Ref<GenericGFPoly>();
if (err_handler.errCode()) return Ref<GenericGFPoly>();
return gfpoly;
}
@ -215,7 +225,7 @@ Ref<GenericGFPoly> GenericGFPoly::multiplyByMonomial(int degree, int coefficient
}
Ref<GenericGFPoly> gfpoly(new GenericGFPoly(field_, product, err_handler));
if (err_handler.ErrCode()) return Ref<GenericGFPoly>();
if (err_handler.errCode()) return Ref<GenericGFPoly>();
return gfpoly;
}
@ -236,19 +246,19 @@ std::vector<Ref<GenericGFPoly> > GenericGFPoly::divide(Ref<GenericGFPoly> other,
int denominatorLeadingTerm = other->getCoefficient(other->getDegree());
int inverseDenominatorLeadingTerm = field_.inverse(denominatorLeadingTerm, err_handler);
if (err_handler.ErrCode()) return std::vector<Ref<GenericGFPoly> >();
if (err_handler.errCode()) return std::vector<Ref<GenericGFPoly> >();
while (remainder->getDegree() >= other->getDegree() && !remainder->isZero()) {
int degreeDifference = remainder->getDegree() - other->getDegree();
int scale = field_.multiply(remainder->getCoefficient(remainder->getDegree()),
inverseDenominatorLeadingTerm);
Ref<GenericGFPoly> term = other->multiplyByMonomial(degreeDifference, scale, err_handler);
if (err_handler.ErrCode()) return std::vector<Ref<GenericGFPoly> >();
if (err_handler.errCode()) return std::vector<Ref<GenericGFPoly> >();
Ref<GenericGFPoly> iterationQuotiont = field_.buildMonomial(degreeDifference, scale, err_handler);
if (err_handler.ErrCode()) return std::vector<Ref<GenericGFPoly> >();
if (err_handler.errCode()) return std::vector<Ref<GenericGFPoly> >();
quotient = quotient->addOrSubtract(iterationQuotiont, err_handler);
remainder = remainder->addOrSubtract(term, err_handler);
if (err_handler.ErrCode()) return std::vector<Ref<GenericGFPoly> >();
if (err_handler.errCode()) return std::vector<Ref<GenericGFPoly> >();
}
std::vector<Ref<GenericGFPoly> > returnValue(2);

View File

@ -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 <vector>
#include "../array.hpp"
@ -52,4 +62,4 @@ public:
} // namespace zxing
#endif // gENERICGFPOLY_H
#endif // __ZXING_COMMON_REEDSOLOMON_GENERIC_GFPOLY_HPP_

View File

@ -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<int> received, int twoS, ErrorHandler & err_handler) {
Ref<GenericGFPoly> poly(new GenericGFPoly(*field, received, err_handler));
if (err_handler.ErrCode()) return;
if (err_handler.errCode()) return;
ArrayRef<int> syndromeCoefficients(twoS);
bool noError = true;
for (int i = 0; i < twoS; i++) {
@ -59,25 +69,25 @@ void ReedSolomonDecoder::decode(ArrayRef<int> received, int twoS, ErrorHandler &
}
Ref<GenericGFPoly> syndrome(new GenericGFPoly(*field, syndromeCoefficients, err_handler));
Ref<GenericGFPoly> 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<Ref<GenericGFPoly> > sigmaOmega =
runEuclideanAlgorithm(monomial, syndrome, twoS, err_handler);
if (err_handler.ErrCode()) return;
if (err_handler.errCode()) return;
Ref<GenericGFPoly> sigma = sigmaOmega[0];
Ref<GenericGFPoly> omega = sigmaOmega[1];
ArrayRef<int> errorLocations = findErrorLocations(sigma, err_handler);
if (err_handler.ErrCode()) return;
if (err_handler.errCode()) return;
ArrayRef<int> 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<Ref<GenericGFPoly> > ReedSolomonDecoder::runEuclideanAlgorithm(Ref<Generi
Ref<GenericGFPoly> q = field->getZero();
int denominatorLeadingTerm = rLast->getCoefficient(rLast->getDegree());
int dltInverse = field->inverse(denominatorLeadingTerm, err_handler);
if (err_handler.ErrCode()) return vector<Ref<GenericGFPoly> >();
if (err_handler.errCode()) return vector<Ref<GenericGFPoly> >();
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<Ref<GenericGFPoly> >();
if (err_handler.errCode()) return vector<Ref<GenericGFPoly> >();
}
Ref<GenericGFPoly> tmp = q->multiply(tLast, err_handler);
if (err_handler.ErrCode()) return vector<Ref<GenericGFPoly> >();
if (err_handler.errCode()) return vector<Ref<GenericGFPoly> >();
t = tmp->addOrSubtract(tLastLast, err_handler);
if (err_handler.ErrCode()) return vector<Ref<GenericGFPoly> >();
if (err_handler.errCode()) return vector<Ref<GenericGFPoly> >();
if (r->getDegree() >= rLast->getDegree())
{
@ -152,7 +162,7 @@ vector<Ref<GenericGFPoly> > ReedSolomonDecoder::runEuclideanAlgorithm(Ref<Generi
int inverse = field->inverse(sigmaTildeAtZero, err_handler);
Ref<GenericGFPoly> sigma(t->multiply(inverse, err_handler));
Ref<GenericGFPoly> omega(r->multiply(inverse, err_handler));
if (err_handler.ErrCode()) return vector<Ref<GenericGFPoly> >();
if (err_handler.errCode()) return vector<Ref<GenericGFPoly> >();
result[0] = sigma;
result[1] = omega;
@ -177,7 +187,7 @@ ArrayRef<int> ReedSolomonDecoder::findErrorLocations(Ref<GenericGFPoly> 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<int>();
@ -205,6 +215,6 @@ ArrayRef<int> ReedSolomonDecoder::findErrorMagnitudes(Ref<GenericGFPoly> errorEv
result[i] = field->multiply(result[i], xiInverse);
}
}
if (err_handler.ErrCode()) return ArrayRef<int>();
if (err_handler.errCode()) return ArrayRef<int>();
return result;
}

View File

@ -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__

View File

@ -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

View File

@ -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__

View File

@ -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<BitArray> SimpleAdaptiveBinarizer::getBlackRow(int y, Ref<BitArray> 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<BitArray>();
if (err_handler.errCode()) return Ref<BitArray>();
}
// Call parent getBlackMatrix to get current matrix
return Binarizer::getBlackRow(y, row, err_handler);
@ -56,7 +66,7 @@ Ref<BitMatrix> 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<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
}
// 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<BitMatrix> matrix(new BitMatrix(width, height, err_handler));
if (err_handler.ErrCode()) return -1;
if (err_handler.errCode()) return -1;
ArrayRef<char> localLuminances = source.getMatrix();

View File

@ -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__

View File

@ -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

View File

@ -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__

View File

@ -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 -*-
/*

View File

@ -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__

View File

@ -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 <stdio.h>
@ -14,7 +24,7 @@ UnicomBlock::~UnicomBlock()
{
}
void UnicomBlock::Init()
void UnicomBlock::init()
{
if (m_bInit) return;
m_vcIndex = std::vector<unsigned short>(m_iHeight * m_iWidth, 0);
@ -25,30 +35,30 @@ void UnicomBlock::Init()
m_bInit = true;
}
void UnicomBlock::Reset(Ref<BitMatrix> poImage)
void UnicomBlock::reset(Ref<BitMatrix> 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<int>(m_iNowIdx) != -1) m_iNowIdx++;
if (m_iNowIdx == 0) m_iNowIdx++;

View File

@ -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 <vector>
@ -12,18 +23,18 @@ public:
UnicomBlock(int iMaxHeight, int iMaxWidth);
~UnicomBlock();
void Init();
void Reset(Ref<BitMatrix> poImage);
void init();
void reset(Ref<BitMatrix> 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<BitMatrix> m_poImage;
};
} // namespace zxing
#endif // __ZXING_COMMON_UNICOM_BLOCK_HPP__

View File

@ -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;

View File

@ -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);
bool loadBMP(const char* BMPfname, int &nWidth, int &nHeight, unsigned char* buffer);
#endif // __ZXING_COMMON_UTIL_BMP_HPP__

View File

@ -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

View File

@ -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__

View File

@ -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;

View File

@ -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 <map>
#include <string>
@ -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<std::string, std::string> _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__

View File

@ -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<Result> DataMatrixReader::decode(Ref<BinaryBitmap> image, DecodeHints hints)
Ref<BitMatrix> imageBitMatrix=image->getBlackMatrix(err_handler);
Ref<Result> 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<BitMatrix> invertedMatrix = image->getInvertedMatrix(err_handler);
if (err_handler.ErrCode() || invertedMatrix == NULL) return Ref<Result>();
if (err_handler.errCode() || invertedMatrix == NULL) return Ref<Result>();
Ref<Result> 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<LuminanceSource> gray_img = image->getLuminanceSource();
dmtx::DmtxDecode dec;
@ -98,11 +108,11 @@ Ref<Result> DataMatrixReader::decodeMore(Ref<BinaryBitmap> image, Ref<BitMatrix>
(void)hints;
Detector detector(imageBitMatrix);
if (err_handler.ErrCode()) return Ref<Result>();
if (err_handler.errCode()) return Ref<Result>();
Ref<DetectorResult> 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<Result>();
@ -111,7 +121,7 @@ Ref<Result> DataMatrixReader::decodeMore(Ref<BinaryBitmap> image, Ref<BitMatrix>
ArrayRef< Ref<ResultPoint> > points(detectorResult->getPoints());
Ref<DecoderResult> decoderResult = decoder_.decode(detectorResult->getBits(), err_handler);
if (err_handler.ErrCode())
if (err_handler.errCode())
{
reader_call_path_ += "2"; // decode fail
return Ref<Result>();

View File

@ -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__

View File

@ -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> bitMatrix, ErrorHandler & err_handler) {
@ -61,7 +71,7 @@ Version * BitMatrixParser::readVersion(Ref<BitMatrix> 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<BitMatrix> BitMatrixParser::extractDataRegion(Ref<BitMatrix> bitMatrix, Erro
int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns;
Ref<BitMatrix> bitMatrixWithoutAlignment(new BitMatrix(sizeDataRegionColumn, sizeDataRegionRow, err_handler));
if (err_handler.ErrCode()) return Ref<BitMatrix>();
if (err_handler.errCode()) return Ref<BitMatrix>();
for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow)
{
int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows;

View File

@ -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__

Some files were not shown because too many files have changed in this diff Show More