Abstract:
A two-dimensional-code detection system includes a reading unit, a recognizing unit, a calculating unit and a position specifying unit. The reading unit reads an image including plural two-dimensional codes. The recognizing unit recognizes position detection patterns of the respective two-dimensional codes from the read image, which includes the plural two-dimensional codes. The calculating unit that selects at least two of the position detection patterns of the two-dimensional codes. The calculating unit calculates a minimum unit forming each of the selected position detection patterns. The position specifying unit judges whether or not the minimum units forming the selected at least two position detection patterns are substantially equal to each other. When judging that the minimum units forming the selected at least two position detection patterns are substantially equal to each other, the position specifying unit specifies a position of a two-dimensional code using the selected at least two position detection patterns.

Description:
BACKGROUND 
     Technical Field 
       [0001]    The invention relates to a technology for reading and decoding a two-dimensional code, and particularly to a two-dimensional code detection system and a two-dimensional code detection program for reading plural two-dimensional codes simultaneously and recognizing the respective two-dimensional codes accurately. 
       SUMMARY 
       [0002]    According to an aspect of the invention, a two-dimensional-code detection system includes a reading unit, a recognizing unit, a calculating unit and a position specifying unit. The reading unit reads an image including plural two-dimensional codes. The recognizing unit recognizes position detection patterns of the respective two-dimensional codes from the image, which includes the plural two-dimensional codes and is read by the reading unit. The calculating unit selects at least two of the position detection patterns of the plural two-dimensional codes read by the reading unit. The calculating unit calculates a minimum unit forming each of the selected position detection patterns. The position specifying unit judges whether or not the minimum units forming the selected at least two position detection patterns are substantially equal to each other. When judging that the minimum units forming the selected at least two position detection patterns are substantially equal to each other, the position specifying unit specifies a region of a two-dimensional code using the selected at least two position detection patterns. 
     
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         [0003]    Exemplary embodiment s of invention will be described in detail based on the following figures, wherein: 
           [0004]      FIG. 1  is a diagram showing a configuration of a system that executes a two-dimensional code detection method according to an exemplary embodiment; 
           [0005]      FIG. 2  is a flowchart explaining a process procedure of the entire system according to the exemplary embodiment; 
           [0006]      FIG. 3  is a flowchart for detecting a combination of position detection patterns, according to a first exemplary embodiment; 
           [0007]      FIG. 4  is a schematic diagram explaining a method for calculating a module size from center coordinates of the position detection pattern; 
           [0008]      FIG. 5  is a schematic diagram explaining distance values dxi and dyi; 
           [0009]      FIG. 6  is a flowchart (part  1 ) for judging whether or not three points form an isosceles right triangle; 
           [0010]      FIG. 7  is a flowchart (part  2 ) for judging whether or not the three points form the isosceles right triangle; 
           [0011]      FIG. 8  is a schematic diagram showing an inclined position detection pattern; 
           [0012]      FIG. 9  is a schematic drawings (part  1 ) explaining calculation of the inclination; 
           [0013]      FIG. 10  is a schematic drawings (part  1 ) explaining the calculation of the inclination; 
           [0014]      FIG. 11  is a flowchart explaining a third exemplary embodiment; 
           [0015]      FIG. 12  is a schematic diagram showing an example of a QR code having model number  40 ; and 
           [0016]      FIG. 13  is a schematic diagram explaining to judge based on distances, whether or not there is possibility that position detection patterns constitute the same QR code. 
       
    
    
     DETAILED DESCRIPTION 
       [0017]    Exemplary embodiments of the invention will be described below with reference to accompanying drawings. This exemplary embodiment relates to an algorithm for recognizing respective two-dimensional codes from a single raster image data, when a two-dimensional code detection system and a two-dimensional code detection program according to this exemplary embodiment reads a paper document on which the two-dimensional codes (e.g. QR codes) are arranged with a flatbed scanner. 
       (Explanation of Entire System) 
       [0018]      FIG. 1  is a configuration diagram showing a system that executes a two-dimensional code detection method according to an exemplary embodiment. An image input device  1  such as a scanner scans a paper document and generates raster image data. A digital camera may be used as the image input device  1 . A memory  2  stores the raster image data obtained by the image input device  1 . A CPU  3  reads a program and executes a detection process and a decoding process of a two-dimensional code by software. The two-dimensional code detection method according to the exemplary embodiment is implemented as a program executable by the CPU  3 . 
         [0019]    This system executes various processes on the basis of the decoded data. For instance, when the decoded data is an ID number (hereinafter, referred to as a document ID) identifying a document stored in a database, the system queries a database  6  with using the ID as a retrieving key, to acquire a document data body as a result of the query and print the document data body by using an image output device  5  such as a printer. Alternatively, the system may transmit the document data body to another computer via an external interface  4  and a network. 
         [0020]    Hereinafter, exemplary embodiments will be described. QR codes are employed as an example of the two-dimensional code to be detected. 
       (Process Procedures of Entire System) 
       [0021]      FIG. 2  is a flowchart explaining a process procedure of the entire system according to the exemplary embodiment. First, the CPU  3  acquires the raster image data from the image input device  1  (step S 11 ) and binarizes the image data (step S 12 ). A simple binarization method, which uses a threshold value, or other binarization methods may be employed. 
         [0022]    Next, the CPU  3  detects center coordinates of position detection patterns of the two-dimensional code (here, the QR codes) from the binarized raster image data (step S 13 ). The QR code contains three position element patterns. As a detection method, the existing method (JIS X 0510, which is incorporated by reference in its entirety) is employed. That is, in order to detect the QR codes from the image, the CPU  3  scans the entire image and detects position element patterns. Thereafter, the CPU  3  calculates all center coordinates of the detected position element patterns. 
         [0023]    The center coordinates of the detected position detection patterns have been calculated. At least two such position detection patterns are used (three in this exemplary embodiment) to indicate one bar code. At this step, it has not been known which combination of three position detection patterns indicates a bar code. 
         [0024]    In a process of detecting a combination of position detection patterns (step S 14 ), the CPU  3  determines a combination of three position detection patterns, which indicates a bar code. A method of determining the combination will be described in detail. On the basis of the thus determined combination of the three position detection patterns, the CPU  3  specifies a bar code area. Since a rotation angle of the bar code can be known from the relation among the three position detection patterns, the CPU  3  corrects the rotation angle of the bar code area for the bar code to erect the bar code area (step S 15 ). Next, the CPU  3  trims the elected bar code area to decode the bar code (step S 16 ). The existing decoding method (a method described in the JIS) is employed (step S 17 ). 
         [0025]    If plural bar codes areas are detected as a result of the combination detection, the CPU  3  performs rotation correction (step S 15 ), trimming (step S 16 ) and decodes process (step S 17 ) on all the bar code areas. When all combinations are finished, the process is ended (step S 18 ). 
       First Exemplary Embodiment 
       [0026]    The detection of the combination of the position detection patterns in step  14  of  FIG. 2  will be explained in detail.  FIG. 3  is a flowchart for detecting the combination of the position detection patterns according to a first exemplary embodiment. This process is performed after all center coordinates of the position detection patterns are calculated by the method described in the JIS. 
         [0027]    One QR code contains three position detection patterns. Therefore, if there are N QR codes, there are 3N center coordinates of position detection patterns. The CPU  3  acquires a list of the center coordinates (step  21 ). 
         [0028]    Next, the CPU  3  selects three coordinates from among the 3N center coordinates, as a combination. A combination method selects 3 pieces from 3N pieces so as to perform a round robin system. The number of the combination is calculated by taking 3 pieces from 3N pieces. For instance, if number of the OR codes is 2, the number of the center coordinates of the position detection patterns is 2N=6, and the number of the combination selecting 3 pieces from 6 pieces is 20. If the number of the OR codes is 10, the number of the combination is 4,060 (see the following equation (1). 
         [0000]    
       
         
           
             
               C 
               3 
                 
                 
               
                 3 
                  
                 N 
               
                 
             
             = 
             
               
                 
                   ( 
                   
                     3 
                      
                     N 
                   
                   ) 
                 
                 ! 
               
               
                 
                   3 
                   ! 
                 
                  
                 
                   
                     ( 
                     
                       
                         3 
                          
                         N 
                       
                       - 
                       3 
                     
                     ) 
                   
                   ! 
                 
               
             
           
         
       
     
       (Estimation of Module Size) 
       [0029]    Next, the center coordinates of the selected three position detection patterns are referred to as X, Y, and Z, respectively. In addition, the CPU  3  calculates a module size from the position detection patterns to which the respective coordinates belong. The module size is a size of a unit square (minimum unit). The position detection patterns of the QR codes are formed of this module. Specifically, the width of an external frame of the position detection pattern is equal to seven modules. 
         [0030]      FIG. 4  is a schematic diagram illustrating a method of calculating the module size from center coordinates of the position detection patterns. First, the center coordinates of the position detection patterns is referred to as p 0 . A center part of the position detection patterns is a black pixel. Pixel values are checked in the horizontal direction from the center point p 0  (on the right side in  FIG. 4 ), and a point where continuous black pixels turn to a white pixel is referred to as p 1 . Pixel values are further checked in the horizontal direction from the p 1 , and a point where continuous white pixels turn to a black pixel is referred to as p 2 . Furthermore, a point where continuous black pixels turn to a white pixel is referred to as p 3 . In turn, pixel values are checked in the reverse direction from the center point p 0  (on the left side in  FIG. 4 ), points p 4 , p 5  and p 6  where pixel values likewise change are calculated. A distance between points p 6  and p 5  is referred to as dx 1 , a distance between points p 5  and p 4  is referred to as dx 2 , a distance between points p 4  and p 1  is referred to as dx 3 , a distance between points p 1  and p 2  is referred to as dx 4 , and a distance between points p 2  and p 3  is referred to as dx 5 . 
         [0031]    In the same way, pixel values are checked in the vertical direction from the center point p 0 , points where pixel values change are calculated, and distances dy 1 , dy 2 , dy 3 , dy 4  and dy 5  between the points are calculated as shown in  FIG. 5 . From these distance values, a module size may be calculated using the following equation; 
         [0000]    
       
         
           
             
               the 
                
               
                   
               
                
               estimated 
                
               
                   
               
                
               module 
                
               
                   
               
                
               size 
             
             = 
             
               
                 
                   
                     
                       
                         
                           ( 
                           
                             
                               dx 
                                
                               
                                   
                               
                                
                               1 
                             
                             + 
                             
                               dx 
                                
                               
                                   
                               
                                
                               2 
                             
                             + 
                             
                               
                                 dx 
                                  
                                 
                                     
                                 
                                  
                                 3 
                               
                               3 
                             
                             + 
                             
                               dx 
                                
                               
                                   
                               
                                
                               4 
                             
                             + 
                             
                               dx 
                                
                               
                                   
                               
                                
                               5 
                             
                           
                           ) 
                         
                         + 
                       
                     
                   
                   
                     
                       
                         ( 
                         
                           
                             dy 
                              
                             
                                 
                             
                              
                             1 
                           
                           + 
                           
                             dy 
                              
                             
                                 
                             
                              
                             2 
                           
                           + 
                           
                             
                               dy 
                                
                               
                                   
                               
                                
                               3 
                             
                             3 
                           
                           + 
                           
                             dy 
                              
                             
                                 
                             
                              
                             4 
                           
                           + 
                           
                             dy 
                              
                             
                                 
                             
                              
                             5 
                           
                         
                         ) 
                       
                     
                   
                 
                 10 
               
               . 
             
           
         
       
     
         [0032]    In addition, only the horizontal distances dx 1 , dx 2 , dx 3 , dx 4 , and dx 5  are calculated, and the estimated module size may be calculated on the basis of the following equation; 
         [0000]    
       
         
           
             
               the 
                
               
                   
               
                
               estimated 
                
               
                   
               
                
               module 
                
               
                   
               
                
               size 
             
             = 
             
               
                 
                   ( 
                   
                     
                       dx 
                        
                       
                           
                       
                        
                       1 
                     
                     + 
                     
                       dx 
                        
                       
                           
                       
                        
                       2 
                     
                     + 
                     
                       
                         dx 
                          
                         
                             
                         
                          
                         3 
                       
                       3 
                     
                     + 
                     
                       dx 
                        
                       
                           
                       
                        
                       4 
                     
                     + 
                     
                       dx 
                        
                       
                           
                       
                        
                       5 
                     
                   
                   ) 
                 
                 5 
               
               . 
             
           
         
       
     
         [0033]    By using the above method, the module sizes Mx, My, and Mz of the three position detection patterns are calculated (step S 22  to S 24 ). 
         [0034]    Next, the CPU  3  compares the module sizes Mx, My and Mz (step S 25 ). That is, the module sizes calculated from the three position detection patterns forming one QR code are equal to each other. If the three module sizes are different, one QR code is not formed and therefore the CPU  3  does not evaluate the combination of the three. In contrast, when the three module sizes are almost equal, there is a possibility that one QR code is formed and therefore the CPU  3  proceeds to the subsequent process. For instance, when the difference between any two of the three module sizes is within a predetermined permissible range, the CPU  3  determines two module sizes are almost equal. Furthermore, a user may designate the permissible range. Since there are variation factors due to the image scanning, some margin may be permissible when the module sizes are evaluated. 
       (Evaluation of Isosceles Right Triangle) 
       [0035]    Next, the CPU  3  evaluates whether or not the center coordinates X, Y and Z of the three position detection patterns whose module sizes are almost equal form an isosceles right triangle.  FIG. 6  and  FIG. 7  are flowcharts for determining whether or not the three points form the isosceles right triangle. 
         [0036]    First, in  FIG. 6 , the CPU  3  acquires three points, that is, the center coordinates X, Y, and Z (step S 31 ) to thereby determine whether or not the three points form the isosceles triangle with the right angle located in the point X (step S 32 ). When the determination is true (True), the CPU  3  determines that the three points form the isosceles right triangle. In addition, when the determination is false (False), the CPU  3  determines whether or not the three points form the isosceles right triangle with the right angle located in the point Y (step S 33 ). When the determination is true (True), the CPU  3  determines that the three points form the isosceles right triangle. In addition, when the determination is false, the CPU  3  determines whether or not the three points form the isosceles right triangle with the right angle located in the point Z (step S 33 ). When the determination is true (True), the CPU  3  determines that the three points form the isosceles right triangle. In addition, if the determination is false (False), the CPU  3  determines that the three points does not form the isosceles right triangle. 
         [0037]    A process for determining whether or not the three points form the isosceles right triangle with the right angle located in each point will be described with reference to a flowchart shown in  FIG. 7 . That is, at first, the CPU  3  acquires the point X, which is the apex, and other points Y and Z (step S 41 ) Then, the CPU  3  calculates a distance between X and Y and a distance between X and Z (step S 42 ), and calculates an angle θ between a straight line XY and a straight line XZ (step S 43 ). 
         [0038]    Then, the CPU  3  determines whether or not the distance XY is equal to the distance XZ (step S 44 ) and judges whether the angle θ=90° (step S 45 ). If any of the judgments is true, the CPU  3  determines that the three points form the isosceles right triangle. If any of the judgments is false, the CPU  3  determines that the three points do not form the isosceles right triangle. 
         [0039]    Turning to  FIG. 3 , when the three points form the isosceles right triangle (step S 26 ), the CPU  3  stores the three points as the center coordinates of the three position detection patterns, which form the QR codes (step S 27 ). The CPU  3  executes the rotation correction on the basis of the coordinates of the position detection patterns and acquires desired information by decoding the QR codes. 
       Second Exemplary Embodiment 
       [0040]    A second exemplary embodiment relates to a method of calculating the module size when the position detection patterns are inclined. 
       (Estimation of Module from Inclined Position Detection Pattern) 
       [0041]    As shown in  FIGS. 8 and 9 , in the case where there is a possibility that a position detection pattern is inclined, the module size is calculated as below. That is, as shown in  FIGS. 8 and 9 , when pixel values are checked in the horizontal direction from the center point p 0  of the position detection pattern, a point where black pixels turn to a white pixel is referred to as p 1 . A horizontal line passing through centers of the p 1  and p 2  is referred to as a straight-line ab. 
         [0042]    As shown in  FIG. 10 , at this time, the CPU  3  sets a window W having a size of 2 pixels in the position of p 1 . In addition, the CPU  3  moves the window W in the upper direction from p 1  so that the left part of the window W is a black pixel and the right of the window W is a white pixel, and records a locus of the window W. Similarly, the CPU  3  moves in the downward direction from the p 1  and records a locus of the window W. The locus of the window W acquired by the above method referred to as a straight-line cd. In  FIGS. 8 and 9 , an angle between a straight line ef, which is perpendicular to the straight-line ab and passes through the p 1 , and the straight-line cd (contour lines of the position detection pattern), is denoted by θ. Since the straight-line cd has been already acquired, the CPU  3  may calculate the angle θ. As shown in  FIGS. 8 and 9 , an inclination angle of the position detection pattern is θ. 
         [0043]    As shown in  FIG. 8 , a straight line a′b′, which passes through p 0  and has the inclined angle θ, is set. Pixel values are checked along the straight line a′b′, and black and white-turning points p 1 ′, p 2 , p 3 , p 4 , p 5 , and p 6  of the pixel values are calculated. On the basis of these points, the CPU  3  may calculate the distances dx 1 , dx 2 , dx 3 , dx 4 , and dx 5 , respectively. Similarly, the CPU  3  calculates black and white-turning points while referring to pixel values along the straight-line e′f′, and then calculates distances dy 1 , dy 2 , dy 3 , dy 4 , and dy 5  between the points, respectively. In the following processes, the CPU calculates module sizes by using the similar formula as the first exemplary embodiment. 
       Third Exemplary Embodiment 
       [0044]    In a third exemplary embodiment, module sizes are calculated in the same way as the first and second exemplary embodiments, and a maximum size of the QR codes, which cab be taken, is calculated from the module sizes, and a position detection pattern only within the predetermined range is estimated. 
       (Specification of Maximum QR Size from Module Size) 
       [0045]      FIG. 11  is a flowchart explaining a third exemplary embodiment. That is, in the same way as the first exemplary embodiment, the CPU  3  acquires a list of the center coordinates of the position detection pattern (step S 51 ), and the center coordinates of the selected three position detection patterns are referred to as X, Y and Z, respectively. In addition, a module size Mx of the position detection pattern having the center point X is calculated (step S 52 ). 
         [0046]    The QR codes are defined from the model number  1  to the model number  40  in JIS. The largest number is the model number  40 .  FIG. 12  is an example of the QR code of the model number  40 . The QR code of the model number  40  is formed of 177 modules. At this time, position detection patterns are provided on an edge of the QR code and the position detection pattern is formed of seven modules. Therefore, a distance between the centers of the position detection pattern is 170 modules. 
         [0047]    The module size Mx of the position detection pattern having the center point X has been already calculated. It is assumed that a distance between the position detection patterns of this QR code whose module size is D. In this case, D is equal to 170·Mx. Accordingly, a center point of the position detection pattern where a distance from the center point X is within D may form one QR code together with the center point X. In contrast, a center point of the position detection pattern where a distance from the center point X is longer than D cannot form one QR code together with the center point X. (see  FIG. 13 ) 
         [0048]    The CPU  3  compares the distance D with the distances XY and XZ between the center points of the selected three position detection patterns (step S 54  to S 55 ). When the distances XY and XZ are shorter than the distance D (Yes in step S 54  and S 55 ), there is a possibility that the points X, Y and Z form one QR code. Therefore, the CPU  3  estimates whether or not the three points form the isosceles right triangle (step S 56 ). The subsequent process is similar to the first exemplary embodiment. When the three points form the isosceles right triangle, the CPU  3  stores the three points X, Y and Z (step S 57 ). 
         [0049]    In the explained exemplary embodiment, the QR code is selected as the example of the two-dimensional code. The two-dimensional code detection method and the two-dimensional code detection program are applied to an image forming apparatuses such as a copier as well as a small apparatus such as a mobile phone and a mobile terminal. In addition, the two-dimensional code detection program may be stored in a predetermined storage medium to be distributed, or may be distributed through a network. 
         [0050]    The foregoing description of the exemplary embodiments of the present invention has been provided for the purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise forms disclosed. Obviously, many modifications and variations will be apparent to practitioners skilled in the art. The exemplary embodiments were chosen and described in order to best explain the principles of the invention and its practical applications, thereby enabling others skilled in the art to understand the invention for various embodiments and with the various modifications as are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the following claims and their equivalents.