#ifndef __LINESSAMPLER_H__ #define __LINESSAMPLER_H__ /* * Copyright 2010 ZXing authors All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include namespace zxing { namespace pdf417 { namespace detector { class LinesSampler { private: static const int MODULES_IN_SYMBOL = 17; static const int BARS_IN_SYMBOL = 8; static const int POSSIBLE_SYMBOLS = 2787; static const std::vector RATIOS_TABLE; static std::vector init_ratios_table(); static const int BARCODE_START_OFFSET = 2; Ref linesMatrix_; int symbolsPerLine_; int dimension_; static std::vector > findVertices(Ref matrix, int rowStep); static std::vector > findVertices180(Ref matrix, int rowStep); static ArrayRef findGuardPattern(Ref matrix, int column, int row, int width, bool whiteFirst, const int pattern[], int patternSize, ArrayRef counters); static int patternMatchVariance(ArrayRef counters, const int pattern[], int maxIndividualVariance); static void correctVertices(Ref matrix, std::vector >& vertices, bool upsideDown); static void findWideBarTopBottom(Ref matrix, std::vector >& vertices, int offsetVertice, int startWideBar, int lenWideBar, int lenPattern, int nIncrement); static void findCrossingPoint(std::vector >& vertices, int idxResult, int idxLineA1, int idxLineA2, int idxLineB1, int idxLineB2, Ref matrix); static float computeModuleWidth(std::vector >& vertices); static int computeDimension(Ref topLeft, Ref topRight, Ref bottomLeft, Ref bottomRight, float moduleWidth); int computeYDimension(Ref topLeft, Ref topRight, Ref bottomLeft, Ref bottomRight, float moduleWidth); Ref sampleLines(std::vector > const& vertices, int dimensionY, int dimension); static void codewordsToBitMatrix(std::vector >& codewords, Ref& matrix); static int calculateClusterNumber(int codeword); static Ref sampleGrid(Ref image, int dimension); static void computeSymbolWidths(std::vector& symbolWidths, const int symbolsPerLine, Ref linesMatrix); static void linesMatrixToCodewords(std::vector >& clusterNumbers, const int symbolsPerLine, const std::vector& symbolWidths, Ref linesMatrix, std::vector >& codewords); static std::vector > > distributeVotes(const int symbolsPerLine, const std::vector >& codewords, const std::vector >& clusterNumbers); static std::vector findMissingLines(const int symbolsPerLine, std::vector >& detectedCodeWords); static int decodeRowCount(const int symbolsPerLine, std::vector >& detectedCodeWords, std::vector& insertLinesAt); static int round(float d); static Point intersection(Line a, Line b); public: LinesSampler(Ref linesMatrix, int dimension); Ref sample(); }; } } } #endif // __LINESSAMPLER_H__