Zxing 是Google公司开发的一款1D/2D条码识别开源工具包,该工具跨平台,支持Android,IOS,Windows,Linux。本文主要走读Linux 平台下面运行的CPP 代码。
查看目录结构:
我们这里查看cpp 里面的
入口:
ZXing\cpp\magick\src\main.c
int main(int argc, char** argv)
进入后执行,
test_image_global
test_image_local
// 为什么这会执行这两个行数呢?这两个行数的作用是什么?区别是什么?
调用区别:
解答:
test_image_global 检查全局图像,test_image_local 检查局部图像,两个函数的作用都是对图像二值化处理,区别在于一个是局部处理,一个是全局处理。
int test_image_local(Image& image, string out_prefix) {
return test_image(image, out_prefix, true);
}
int test_image_global(Image& image, string out_prefix) {
return test_image(image, out_prefix, false);
}
test_image(Image& image, string out_prefix, bool localized)
Ref<BitMatrix> matrix(NULL); // 位图矩阵
Ref<Binarizer> binarizer(NULL); // 二值化
if (localized) {
binarizer = new LocalBlockBinarizer(source); // 定义局部块二值化
} else {
binarizer = new GlobalHistogramBinarizer(source);//定义全局直方图二值化
}
Binarizer 二值化类,
matrix = binarizer->getBlackMatrix(); // 获取二值化后处理后的图像
Ref<BinaryBitmap> binary(new BinaryBitmap(binarizer)); // 定义BinaryBitmap 类变量 binary, 这是一个bitmap 类型的图像数据
Ref<Result> result(decode(out_prefix, binary, cell_grid, cell_transformed));// 定义Result类变量,在形参中调用 decode 解码函数, 对图像进行解码操作。
Ref<Result> decode(string out_prefix, Ref<BinaryBitmap> image, string& cell_grid, string& cell_transformed) {
QREdgeDetector detector = QREdgeDetector(image->getBlackMatrix());// 定义QRcode 解码类
Ref<DetectorResult> detectorResult(detector.detect()); // 探测结果类
}
cell_result = result->getText()->getText(); // 使用result 变量获取识别处理文本结果