QR计算的位置,code对齐模式 [英] Calculating the position of QR Code alignment patterns

查看:264
本文介绍了QR计算的位置,code对齐模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何计算中的 ISO / IEC的表18004:2000附录E

I need to know how to calculate the positions of the QR Code alignment patterns as defined in the table of ISO/IEC 18004:2000 Annex E.

我不明白它是如何计算出来的。如果取版16,例如,该位置通过计算{6,26,50,74}和点之间的距离是{20,24,24}。为什么不是{6,28,52,74},如果点之间的距离,{22,24,22},分配更加公平?

I don't understand how it's calculated. If you take the Version 16, for example, the positions are calculated using {6,26,50,74} and distance between the points are {20,24,24}. Why isn't it {6,28,52,74}, if the distances between the points, {22,24,22}, is distributed more equally?

我想知道这是如何程序产生的。

I would like to know how this can be generated procedurally.

推荐答案

尽管说明书确实提供了比对表,这是一个合理的问题(和一个我发现自己与:-)) - 产生的可能性位置在程序上有其可取之处(错字少易code,较小的code的足迹,了解模式/位置的属性)。

While the specification does provide a table of the alignment, this is a reasonable question (and one I found myself with :-)) - the possibility of generating the positions procedurally has its merits (less typo-prone code, smaller code footprint, knowing pattern/properties of the positions).

我很高兴地告诉大家,是的,过程存在(它甚至相当简单)。 规范本身说大部分:

I'm happy to report that, yes, a procedure exists (and it is even fairly simple). The specification itself says most of it:

[对准图案]隔开尽可能均匀的时序模式与符号的相对侧之间,任何不均匀的间距被定时图案和在符号内的第一对准图案之间收纳

[The alignment patterns] are spaced as evenly as possible between the Timing Pattern and the opposite side of the symbol, any uneven spacing being accommodated between the timing pattern and the first alignment pattern in the symbol interior.

也就是说,只有在第一和第二坐标可能不同于间隔的其余部分之间的间隔。其余的必须是平等的。 另一个重要的位是当然的是,对于AP以同意所述定时模式,该间隔必须为偶数的。 剩余的棘手位刚开四舍五入权利。

That is, only the interval between the first and second coordinate may differ from the rest of the intervals. The rest must be equal. Another important bit is of course that, for the APs to agree with the timing patterns, the intervals must be even. The remaining tricky bit is just getting the rounding right.

反正 - 这里是code印花对齐位置表:

Anyway - here's code printing the alignment position table:

def size_for_version(version):
    return 17 + 4 * version

def alignment_coord_list(version):
    if version == 1:
        return []
    divs = 2 + version // 7
    size = size_for_version(version)
    total_dist = size - 7 - 6
    divisor = 2 * (divs - 1)
    # Step must be even, for alignment patterns to agree with timing patterns
    step = (total_dist + divisor // 2 + 1) // divisor * 2 # Get the rounding right
    coords = [6]
    for i in range(divs - 2, -1, -1): # divs-2 down to 0, inclusive
        coords.append(size - 7 - i * step)
    return coords

for version in range(1, 40 + 1): # 1 to 40 inclusive
    print("V%d: %s" % (version, alignment_coord_list(version)))

这篇关于QR计算的位置,code对齐模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆