簡體   English   中英

pdf417條碼創建,Reed Solomon糾錯碼字與python和JAVA之間存在差異

[英]pdf417 barcode creation, Reed Solomon error correction codewords disparity between python and JAVA

我使用Python庫pdf417gen創建了pdf417條碼。

條形碼是字符串“ M1LONG”的圖形表示。 條形碼具有兩個數據列,並且Reed Solomon糾錯安全級別設置為“ 1”。 這表明在輸入八個數據碼字的情況下,糾錯碼字的數量應為四個。

Python輸出將數據代碼字從D07到D00顯示為{8, 389, 902, 11, 900, 344, 396, 900} 8,389,902,11,900,344,396,900 {8, 389, 902, 11, 900, 344, 396, 900} python列出了從C03到C00的錯誤校正碼字,如{718, 801, 313, 877} 這是用於生成所有代碼字的Python:

from builtins import range

from .data import ERROR_CORRECTION_FACTORS

def compute_error_correction_code_words(data_words, level):
    assert 0 <= level <= 8

    # Correction factors for the given level
    factors = ERROR_CORRECTION_FACTORS[level]

    # Number of EC words
    count = 2 ** (level + 1)

    # Correction code words list, prepopulated with zeros
    ec_words = [0] * count

    # Do the math
    for data_word in data_words:
        temp = (data_word + ec_words[-1]) % 929

        for x in range(count - 1, -1, -1):
            word = ec_words[x - 1] if x > 0 else 0
            ec_words[x] = (word + 929 - (temp * factors[x]) % 929) % 929

    return [929 - x if x > 0 else x for x in reversed(ec_words)]

糾錯碼字是使用多項式,Galois Field算法和模數929的補碼生成的,模數929是pdf417系統可能的碼字數。 該計算使用許多因素來簡化過程。 對於安全級別1,建議的因素數量為4。 這些因素是522,568,723,809

http://grandzebu.net/informatique/codbar/pdf417coef.txt

問題是這樣的。 我嘗試使用從http://grandzebu.net/informatique/codbar-en/pdf417.htm獲得的JAVA偽代碼重新創建錯誤代碼字。

我編寫了一個JAVA程序來嘗試生成與上述Python軟件相同的代碼字,但是它不會生成相同的錯誤代碼字。

JAVA程序可以編譯並運行,數學知識在未經訓練的人看來還可以,但是產生的錯誤代碼並不相同。 這是我的JAVA,JAVA變量的名稱與Python相同,以使比較這兩個程序更加容易。

import java.util.Arrays;

public class reedsolomon{

    public static void main (String[] args){

        int ec_words[] = new int[4];//correction codewords array
        int temp=0;//holding variable
        int count=4; //number of error correction codewords
        int data_words[] = {8,389,902,11,900,344,396,900};// eight data codewords array D7 to D0.
        int factors[]= {522,568,723,809}; //factors or coefficients array.
        for(int i=0; i<data_words.length-1; i++) { 
            temp=(data_words[i] + ec_words[count-1])%929;
            for(int x=count-1; x>-1; x--){
                if(x==0){
                    ec_words[x] = (929-(temp*factors[x])%929)%929; //negative values in the Galois Field
                    //GF(929) are equal to the complement of itself if
                    //ec_words[x] > -929
                }
                else{
                    ec_words[x]=(ec_words[x-1]+929-(temp*factors[x])%929) %929; //negative values in the Galois Field
                    //GF(929) are equal to the complement of the
                    //remainder (ec_words[x] /929) if ec_words[x] <= -929.
                }
            }
        }
        for(int j=0; j<count; j++){
            if(ec_words[j] != 0){
                ec_words[j]=929-ec_words[j]; 
            }
        }System.out.println("Error codewords are " + Arrays.toString(ec_words));
    }
}

我將不勝感激地知道JAVA代碼有什么問題,它可以阻止它生成與庫pdf417gen中包含的python程序相同的錯誤代碼字。

您的代碼中有兩個問題。

  1. 最重要的一個:您沒有處理所有單詞。 您的代碼顯示為:

     for(int i=0; i<data_words.length-1; i++) { 

    但應顯示為:

     for(int i=0; i < data_words.length; i++) { 

    在for循環中,您丟失了data_words[data_words.length-1]的最后一個數據字

  2. 您不會像在python中那樣反轉Java代碼中的ec_words數組,因此結果在ec_words中是相反的順序。

應用第一個修復程序后,Java代碼的結果是:

Error codewords are [877, 313, 801, 718]

一些澄清(至少對於其他閱讀此主題的人)。 “因數”實際上是GF(929)= 1 x中生成多項式g(x)=(x-3)(x-3 ^ 2)(x-3 ^ 3)(x-3 ^ 4)的系數。 ^ 4 + 809 x ^ 3 + 723 x ^ 2 + 568 x +522。編碼過程將數據視為多項式m(x),將其乘以x ^ 4來為4個奇偶校驗字節創建空間,然后除以m (x)x ^ 4 / g(x)產生余數r(x)。 編碼后的代碼字為m(x)x ^ 4-r(x)= 8 x ^ 11 + 389 x ^ 10 + 902 x ^ 9 + 11 x ^ 8 + 900 x ^ 7 + 344 x ^ 6 + 396 x ^ 5 + 900 x ^ 4 + 718 x ^ 3 + 801 x ^ 2 + 313 x + 877。

Wiki文章在其BCH視圖示例中還使用了GF(929)和相同的生成多項式:

https://en.wikipedia.org/wiki/Reed%E2%80%93Solomon_error_correction#Example_3

RS(12,8)GF(929)的可能代碼字的數量為929 ^ 8(數量巨大)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM