libdmtx 0.7.8.7
libdmtx is a software library that enables programs to read and write Data Matrix barcodes of the modern ECC200 variety.
Loading...
Searching...
No Matches
dmtxregion.c File Reference

libdmtx - Data Matrix Encoding/Decoding Library Copyright 2008, 2009 Mike Laughton. More...

#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "dmtx.h"
#include "dmtxstatic.h"

Go to the source code of this file.

Macros

#define DMTX_HOUGH_RES   180
 

Functions

DmtxRegiondmtxRegionCreate (DmtxRegion *reg)
 Create copy of existing region struct.
 
DmtxPassFail dmtxRegionDestroy (DmtxRegion **reg)
 Destroy region struct.
 
DmtxRegiondmtxRegionFindNext (DmtxDecode *dec, DmtxTime *timeout)
 寻找下一个二维码区域
 
DmtxRegiondmtxRegionScanPixel (DmtxDecode *dec, int x, int y)
 将坐标点(x,y)作为二维码L型框的边缘点去匹配二维码包围框
 
static DmtxPointFlow matrixRegionSeekEdge (DmtxDecode *dec, DmtxPixelLoc loc)
 寻找指定像素位置梯度流向,并检查该点是否能形成闭环。如果成功暂定该点在DataMatrix的'L'型边上
 
static DmtxPassFail matrixRegionOrientation (DmtxDecode *dec, DmtxRegion *reg, DmtxPointFlow begin)
 确定数据矩阵区域的方向和关键边界
 
static long distanceSquared (DmtxPixelLoc a, DmtxPixelLoc b)
 计算两个像素点之间的欧几里得距离的平方
 
DmtxPassFail dmtxRegionUpdateCorners (DmtxDecode *dec, DmtxRegion *reg, DmtxVector2 p00, DmtxVector2 p10, DmtxVector2 p11, DmtxVector2 p01)
 
DmtxPassFail dmtxRegionUpdateXfrms (DmtxDecode *dec, DmtxRegion *reg)
 
static double rightAngleTrueness (DmtxVector2 c0, DmtxVector2 c1, DmtxVector2 c2, double angle)
 
static int readModuleColor (DmtxDecode *dec, DmtxRegion *reg, int symbolRow, int symbolCol, int sizeIdx, int colorPlane)
 读取模块(码元)颜色值
 
static DmtxPassFail matrixRegionFindSize (DmtxDecode *dec, DmtxRegion *reg)
 确定二维码尺寸(点线中黑白点的总数)
 
static int countJumpTally (DmtxDecode *dec, DmtxRegion *reg, int xStart, int yStart, DmtxDirection dir)
 计算一个方向上颜色跳变次数
 
static DmtxPointFlow getPointFlow (DmtxDecode *dec, int colorPlane, DmtxPixelLoc loc, int arrive)
 从像素坐标寻找其在指定颜色平面的梯度方向
 
static DmtxPointFlow findStrongestNeighbor (DmtxDecode *dec, DmtxPointFlow center, int sign)
 
static DmtxFollow followSeek (DmtxDecode *dec, DmtxRegion *reg, int seek)
 根据指定步数从当前区域的起始点追踪到新位置
 
static DmtxFollow followSeekLoc (DmtxDecode *dec, DmtxPixelLoc loc)
 根据指定像素坐标初始化追踪起始信息
 
static DmtxFollow followStep (DmtxDecode *dec, DmtxRegion *reg, DmtxFollow followBeg, int sign)
 寻找followBeg的下一个点
 
static DmtxFollow followStep2 (DmtxDecode *dec, DmtxFollow followBeg, int sign)
 
static DmtxPassFail trailBlazeContinuous (DmtxDecode *dec, DmtxRegion *reg, DmtxPointFlow flowBegin, int maxDiagonal)
 从flowBegin点出发,分别从正负方向寻找连续的边界线
 
static int trailBlazeGapped (DmtxDecode *dec, DmtxRegion *reg, DmtxBresLine line, int streamDir)
 recives bresline, and follows strongest neighbor unless it involves ratcheting bresline inward or backward (although back + outward is allowed).
 
static int trailClear (DmtxDecode *dec, DmtxRegion *reg, int clearMask)
 
static DmtxBestLine findBestSolidLine (DmtxDecode *dec, DmtxRegion *reg, int step0, int step1, int streamDir, int houghAvoid)
 查找最佳实线
 
static DmtxBestLine findBestSolidLine2 (DmtxDecode *dec, DmtxPixelLoc loc0, int tripSteps, int sign, int houghAvoid)
 
static DmtxPassFail findTravelLimits (DmtxDecode *dec, DmtxRegion *reg, DmtxBestLine *line)
 
static DmtxPassFail matrixRegionAlignCalibEdge (DmtxDecode *dec, DmtxRegion *reg, int edgeLoc)
 
static DmtxBresLine bresLineInit (DmtxPixelLoc loc0, DmtxPixelLoc loc1, DmtxPixelLoc locInside)
 
static DmtxPassFail bresLineGetStep (DmtxBresLine line, DmtxPixelLoc target, int *travel, int *outward)
 
static DmtxPassFail bresLineStep (DmtxBresLine *line, int travel, int outward)
 

Detailed Description

libdmtx - Data Matrix Encoding/Decoding Library Copyright 2008, 2009 Mike Laughton.

All rights reserved. Copyright 2012-2016 Vadim A. Misbakh-Soloviov. All rights reserved. Copyright 2016 Tim Zaman. All rights reserved.

See LICENSE file in the main project directory for full terms of use and distribution.

Contact: Vadim A. Misbakh-Soloviov dmtx@.nosp@m.mva..nosp@m.name Mike Laughton mike@.nosp@m.drag.nosp@m.onfly.nosp@m.logi.nosp@m.c.com

Detect barcode regions

Definition in file dmtxregion.c.

Macro Definition Documentation

◆ DMTX_HOUGH_RES

#define DMTX_HOUGH_RES   180

Definition at line 26 of file dmtxregion.c.

Function Documentation

◆ bresLineGetStep()

static DmtxPassFail bresLineGetStep ( DmtxBresLine line,
DmtxPixelLoc target,
int * travel,
int * outward )
static

Definition at line 1922 of file dmtxregion.c.

◆ bresLineInit()

static DmtxBresLine bresLineInit ( DmtxPixelLoc loc0,
DmtxPixelLoc loc1,
DmtxPixelLoc locInside )
static

Definition at line 1856 of file dmtxregion.c.

◆ bresLineStep()

static DmtxPassFail bresLineStep ( DmtxBresLine * line,
int travel,
int outward )
static

Definition at line 1944 of file dmtxregion.c.

◆ countJumpTally()

static int countJumpTally ( DmtxDecode * dec,
DmtxRegion * reg,
int xStart,
int yStart,
DmtxDirection dir )
static

计算一个方向上颜色跳变次数

此函数遍历图像中的一行或一列,统计从亮模块到暗模块或反之的转换次数。

Parameters
dec解码上下文,提供解码环境信息
reg区域对象,包含当前分析区域的属性
xStart开始搜索的坐标X位置
yStart开始搜索的坐标Y位置
dir搜索方向,向右(DmtxDirRight)或向上(DmtxDirUp)

Definition at line 919 of file dmtxregion.c.

◆ distanceSquared()

static long distanceSquared ( DmtxPixelLoc a,
DmtxPixelLoc b )
static

计算两个像素点之间的欧几里得距离的平方

Definition at line 407 of file dmtxregion.c.

◆ dmtxRegionCreate()

DmtxRegion * dmtxRegionCreate ( DmtxRegion * reg)
extern

Create copy of existing region struct.

Returns
Initialized DmtxRegion struct

Definition at line 32 of file dmtxregion.c.

◆ dmtxRegionDestroy()

DmtxPassFail dmtxRegionDestroy ( DmtxRegion ** reg)
extern

Destroy region struct.

Parameters
reg
Returns
void

Definition at line 51 of file dmtxregion.c.

◆ dmtxRegionFindNext()

DmtxRegion * dmtxRegionFindNext ( DmtxDecode * dec,
DmtxTime * timeout )
extern

寻找下一个二维码区域

Parameters
decPointer to DmtxDecode information struct
timeout超时时间 (如果为NULL则不限时)

Definition at line 69 of file dmtxregion.c.

◆ dmtxRegionScanPixel()

DmtxRegion * dmtxRegionScanPixel ( DmtxDecode * dec,
int x,
int y )
extern

将坐标点(x,y)作为二维码L型框的边缘点去匹配二维码包围框

Definition at line 100 of file dmtxregion.c.

◆ dmtxRegionUpdateCorners()

DmtxPassFail dmtxRegionUpdateCorners ( DmtxDecode * dec,
DmtxRegion * reg,
DmtxVector2 p00,
DmtxVector2 p10,
DmtxVector2 p11,
DmtxVector2 p01 )
extern

Definition at line 421 of file dmtxregion.c.

◆ dmtxRegionUpdateXfrms()

DmtxPassFail dmtxRegionUpdateXfrms ( DmtxDecode * dec,
DmtxRegion * reg )
extern

Definition at line 528 of file dmtxregion.c.

◆ findBestSolidLine()

static DmtxBestLine findBestSolidLine ( DmtxDecode * dec,
DmtxRegion * reg,
int step0,
int step1,
int streamDir,
int houghAvoid )
static

查找最佳实线

该函数用于在给定的解码上下文和区域内,根据霍夫变换找到最佳实线。 它考虑了路径流的方向,并尝试避免指定的角度。

Parameters
dec解码上下文
reg区域信息
step0起始步长
step1结束步长
streamDir流的方向
houghAvoid霍夫变换中要避免的角度
Returns
DmtxBestLine 返回最佳实线的信息

Definition at line 1471 of file dmtxregion.c.

◆ findBestSolidLine2()

static DmtxBestLine findBestSolidLine2 ( DmtxDecode * dec,
DmtxPixelLoc loc0,
int tripSteps,
int sign,
int houghAvoid )
static

Definition at line 1590 of file dmtxregion.c.

◆ findStrongestNeighbor()

static DmtxPointFlow findStrongestNeighbor ( DmtxDecode * dec,
DmtxPointFlow center,
int sign )
static

Definition at line 1051 of file dmtxregion.c.

◆ findTravelLimits()

static DmtxPassFail findTravelLimits ( DmtxDecode * dec,
DmtxRegion * reg,
DmtxBestLine * line )
static

Definition at line 1679 of file dmtxregion.c.

◆ followSeek()

static DmtxFollow followSeek ( DmtxDecode * dec,
DmtxRegion * reg,
int seek )
static

根据指定步数从当前区域的起始点追踪到新位置

此函数从数据矩阵区域的起始追踪点出发,按照给定的步数(正向或负向), 逐步调用FollowStep函数进行追踪,并返回达到的新位置信息。此功能 支持快速跳转到区域内的指定追踪步骤,用于优化和控制追踪流程。

Parameters
dec解码上下文,用于缓存访问
reg当前数据矩阵区域信息,包含追踪起始位置、步数上限等
seek相对于起始点的追踪步数,正值表示正向追踪,负值表示反向追踪
Returns
返回追踪到达的新位置信息(DmtxFollow 结构体)

Definition at line 1113 of file dmtxregion.c.

◆ followSeekLoc()

static DmtxFollow followSeekLoc ( DmtxDecode * dec,
DmtxPixelLoc loc )
static

根据指定像素坐标初始化追踪起始信息

Definition at line 1138 of file dmtxregion.c.

◆ followStep()

static DmtxFollow followStep ( DmtxDecode * dec,
DmtxRegion * reg,
DmtxFollow followBeg,
int sign )
static

寻找followBeg的下一个点

Parameters
dec解码上下文,包含缓存访问等信息
reg当前处理的区域信息,包括追踪步数、跳跃目标位置等
followBeg起始点
sign追踪方向,+1 表示正向追踪,-1 表示负向追踪

Definition at line 1159 of file dmtxregion.c.

◆ followStep2()

static DmtxFollow followStep2 ( DmtxDecode * dec,
DmtxFollow followBeg,
int sign )
static

Definition at line 1203 of file dmtxregion.c.

◆ getPointFlow()

static DmtxPointFlow getPointFlow ( DmtxDecode * dec,
int colorPlane,
DmtxPixelLoc loc,
int arrive )
static

从像素坐标寻找其在指定颜色平面的梯度方向

Definition at line 974 of file dmtxregion.c.

◆ matrixRegionAlignCalibEdge()

static DmtxPassFail matrixRegionAlignCalibEdge ( DmtxDecode * dec,
DmtxRegion * reg,
int edgeLoc )
static

Definition at line 1781 of file dmtxregion.c.

◆ matrixRegionFindSize()

static DmtxPassFail matrixRegionFindSize ( DmtxDecode * dec,
DmtxRegion * reg )
static

确定二维码尺寸(点线中黑白点的总数)

此函数遍历可能的条形码尺寸,通过计算校准模块上的对比度来确定最佳尺寸索引。 它还会验证找到的尺寸索引是否与条形码图像的边缘和空白空间相匹配。

Parameters
[in]dec解码上下文,包含解码设置和图像信息
reg区域结构,用于存储找到的区域信息

以左上角水平往右检查

TL-—XX-—XX-----> XX 01 02 03 04 XX XX 05 06 07 08 XX 09 10 11 12 XX XX 13 14 15 16 XX XX XX XX XX XX

以右下角角竖直往上检查

           ^
           |

XX XX XX | XX 01 02 03 04 XX XX 05 06 07 08 | XX 09 10 11 12 XX XX 13 14 15 16 | XX XX XX XX XX BR

以左下角水平往右检查

XX XX XX XX 01 02 03 04 XX XX 05 06 07 08 XX 09 10 11 12 XX XX 13 14 15 16 BL XX XX XX XX XX-->

以左下角竖直往上检查

^ | XX XX XX XX 01 02 03 04 XX XX 05 06 07 08 XX 09 10 11 12 XX XX 13 14 15 16 BL XX XX XX XX XX

分析DataMatrix周围的空间

XX XX XX XX 01 02 03 04 XX XX 05 06 07 08 XX 09 10 11 12 XX XX 13 14 15 16 XX XX XX XX XX XX 00----------------->

^ | | XX XX XX | XX 01 02 03 04 XX | XX 05 06 07 08 | XX 09 10 11 12 XX | XX 13 14 15 16 00 XX XX XX XX XX XX

00-----------------> XX XX XX XX 01 02 03 04 XX XX 05 06 07 08 XX 09 10 11 12 XX XX 13 14 15 16 XX XX XX XX XX XX

               ^
               |

XX XX XX | XX 01 02 03 04 XX | XX 05 06 07 08 | XX 09 10 11 12 XX | XX 13 14 15 16 | XX XX XX XX XX XX 00

Definition at line 688 of file dmtxregion.c.

◆ matrixRegionOrientation()

static DmtxPassFail matrixRegionOrientation ( DmtxDecode * dec,
DmtxRegion * reg,
DmtxPointFlow begin )
static

确定数据矩阵区域的方向和关键边界

此函数分析并确定给定解码上下文中数据矩阵区域的方向性、极性和关键坐标点。 它通过跟随边缘、查找最佳直线、评估交叉点等步骤来实现对区域的精确定位。

Parameters
dec解码上下文,包含了解码设置和辅助信息
reg待分析的数据矩阵区域结构体,用于存储识别结果
begin起始追踪点,用于初始化追踪过程
Return values
DmtxPass成功确定区域方向
DmtxFail未能成功确定区域方向或区域不符合预期条件

Definition at line 240 of file dmtxregion.c.

◆ matrixRegionSeekEdge()

static DmtxPointFlow matrixRegionSeekEdge ( DmtxDecode * dec,
DmtxPixelLoc loc )
static

寻找指定像素位置梯度流向,并检查该点是否能形成闭环。如果成功暂定该点在DataMatrix的'L'型边上

该函数分析指定像素位置的各颜色通道,以确定哪个通道展现了最明显的边缘特征。 然后,它通过分析正负方向上的邻近像素强度,精确定位并返回最强边缘的方向向量。 如果找不到清晰的边缘特征,则返回表示空白边缘(dmtxBlankEdge)的默认值。

Parameters
dec解码上下文,包含图像数据和解码设置。
loc待分析的像素位置。
Returns
DmtxPointFlow 结构,表示找到的边缘方向和强度;如果未找到有效边缘,则返回 dmtxBlankEdge。

Definition at line 176 of file dmtxregion.c.

◆ readModuleColor()

static int readModuleColor ( DmtxDecode * dec,
DmtxRegion * reg,
int symbolRow,
int symbolCol,
int sizeIdx,
int colorPlane )
static

读取模块(码元)颜色值

Parameters
dec解码上下文,包含解码所需的状态信息。
reg当前处理的区域信息,用于定位和变换。
symbolRow二维码坐标系下的行坐标
symbolCol二维码坐标系下的列坐标
sizeIdx二维码种类索引
colorPlane需要读取的颜色平面索引
Returns
返回模块位置的平均颜色值。

Definition at line 646 of file dmtxregion.c.

◆ rightAngleTrueness()

static double rightAngleTrueness ( DmtxVector2 c0,
DmtxVector2 c1,
DmtxVector2 c2,
double angle )
static

Definition at line 620 of file dmtxregion.c.

◆ trailBlazeContinuous()

static DmtxPassFail trailBlazeContinuous ( DmtxDecode * dec,
DmtxRegion * reg,
DmtxPointFlow flowBegin,
int maxDiagonal )
static

从flowBegin点出发,分别从正负方向寻找连续的边界线

vaiiiooo

0x80 v = visited bit 0x40 a = assigned bit 0x38 u = 3 bits points upstream 0-7 0x07 d = 3 bits points downstream 0-7

Definition at line 1234 of file dmtxregion.c.

◆ trailBlazeGapped()

static int trailBlazeGapped ( DmtxDecode * dec,
DmtxRegion * reg,
DmtxBresLine line,
int streamDir )
static

recives bresline, and follows strongest neighbor unless it involves ratcheting bresline inward or backward (although back + outward is allowed).

Definition at line 1341 of file dmtxregion.c.

◆ trailClear()

static int trailClear ( DmtxDecode * dec,
DmtxRegion * reg,
int clearMask )
static

Definition at line 1436 of file dmtxregion.c.