Patent Publication Number: US-11037313-B2

Title: Self-correction method and device for structured light depth camera of smart phone

Description:
CROSS-REFERENCE TO RELATED APPLICATIONS 
     This Application claims priority from CN Application No. 201711369838.8, filed Dec. 18, 2017 and CN Application No. 201711367573.8, filed Dec. 18, 2017, the contents of which are incorporated herein in the entirety by reference. 
     Some references, which may include patents, patent applications, and various publications, are cited and discussed in the description of the present disclosure. The citation and/or discussion of such references is provided merely to clarify the description of the present disclosure and is not an admission that any such reference is “prior art” to the disclosure described herein. All references cited and discussed in this specification are incorporated herein by reference in their entireties and to the same extent as if each reference was individually incorporated by reference. 
     TECHNICAL FIELD 
     The invention relates to the technical field of smart phones, smart cameras and depth sensing, in particular to a self-correction method and device for a structured light depth camera of a smart phone. 
     BACKGROUND 
     A depth camera is a camera with a depth detecting function, and has extensive application and development prospects in the fields of three-dimensional information extraction, object identification, classification, motion tracking, machine vision, man-machine interaction, 3D printing, virtual reality and the like. Embedded application of the depth camera on a smart phone will also be popularized step by step. 
     A structured light depth camera mainly consists of a laser coded pattern projector, an image receiving sensor and a depth sensing and calculating module, monocular structured light or binocular structured light can be used, accurate depth information is acquired, and is not affected by ambient light, a depth sensing algorithm, software and hardware are implemented simply relatively. A basic principle is as follows: a coded pattern (a random speckle or a rule symbol speckle) is projected to the surface of an object through the infrared laser coded pattern projector generally, by reflection of the surface of the object, the image receiving sensor acquires a coded image, and then the depth information of the distance between the object and a projection module is obtained through image depth sensing and calculating. Although the structured light depth camera is relatively simple in the aspects of structural design and a depth acquiring principle, requirements on assembly precision are quite high if high-precision depth information requires to be obtained, in a using process, the optical axis of the laser coded pattern projector or the image receiving sensor may deviate if accidents such as falling, collision and the like occur, and thus, problems of reduction of depth precision, increasing of mismatching noises and the like are caused. Particularly, the structured light depth camera is embedded in the smart phone, when a user uses the mobile phone, falling, collision, knocking and the like occur inevitably, the optical axis of the structured light depth camera twists quite easily, and the way of solving the problems of reduction of precision, increasing of noises and the like due to change of the optical axis, enhancing the robustness of the structured light depth camera of the mobile phone and implementing a self-correction technology of the structured light depth camera of the smart phone appears to be particularly important. 
     SUMMARY 
     In view of this, the invention provides a self-correction method and device for a structured light depth camera of a smart phone, and the self-correction device for the structured light depth camera of the smart phone consists of an infrared laser speckle projector, an infrared receiving image sensor, a self-correction module, a depth calculating module and a mobile phone application processing AP. The method comprises the steps of projecting a speckle pattern by an infrared laser speckle projector at first to carry out feature calibration and speckling on a target object, setting a speckle feature block in a pre-acquired reference speckle image, acquiring an input speckle image through the infrared receiving image sensor, and searching an optimal feature matching block corresponding to the speckle feature block in the input speckle image through a similarity criteria to obtain an offset between the feature block and the matching block, and once the optical axes of the infrared laser speckle projector and the infrared receiving image sensor change relatively, the offset may change along with the change; an optimal offset is solved according to a certain rule and the reference speckle image is adjusted reversely, thus, the center of the input speckle image and the center of the reference speckle image form a self-feedback adjusting closed-loop system, an optimal matching relation between the input speckle image and the corrected reference speckle image can always be found out when the optical axes vary widely, and a correct offset is obtained and is used for depth calculation. In a self-correction process, the mobile phone application processing AP is used for setting the size and number of feature blocks and the range of the matching search window and solving the optimal offset, a whole depth sensing self-correction process can also be completed by software acceleration or a special IP core mode, therefore, the problems that in a using process of the structured light depth camera of the smart phone, depth precision is reduced and noises are increased due to the change of the optical axes of the infrared laser speckle projector and the infrared receiving image sensor are solved, real-time depth self-correction of the smart phone is realized, and the robustness of the smart phone is improved. 
     In order to realize above goals, the invention adopts the following technical solution: 
     A self-correction method for a structured light depth camera of a smart phone comprises the following steps: 
     step 1: projecting a speckle image by an infrared laser speckle projector, and receiving the projected speckle image and generating an input speckle image and a reference speckle image by an infrared image receiving sensor. 
     Step 2: detecting the change of the optical axis of the reference speckle image relative to the input speckle image, and correcting the reference speckle image according to an optimal offset. 
     Step 2.1: for the preprocessed reference speckle image and the preprocessed input speckle image, setting speckle feature blocks in the reference speckle image, wherein the center point of the speckle feature blocks is (x i=1, . . . , p , y i=1, . . . , p ), and the sizes are m×n, and extracting a matching search window which takes a point corresponding to the position (x i=1, . . . , p , y i=1, . . . , p ) as the center and has the size being M×N (wherein M&gt;m, and N&gt;n) from the input speckle image; 
     step 2.2: extracting a matching block of which the size is m×n from the matching search window, and calculating the similarity between the matching block and the feature block through a similarity criterion, wherein the matching block corresponding to the maximum similarity is an optimal matching block; 
     step 2.3: extracting the center point (x′ i=1, . . . , p , y′ i=1, . . . , p ) of the optimal matching block, and calculating an offset (Δx i ,Δy i ) between the center point (x i=1, . . . , p , y i=1, . . . , p ) of the feature block and the center point (x′ i=1, . . . , p , y′ i=1, . . . , p ) of the matching block; 
     step 2.4: detecting the offset, outputting the offset (Δx i ,Δy i ) to a mobile phone AP terminal and solving an optimal offset according to a certain rule; and 
     step 2.5: integrally adjusting the position of the reference speckle image in the up-down direction (−Δy) or the left-right direction (−Δx) reversely according to the optimal offset. 
     Step 3: searching an optimal speckle matching block from the corrected reference speckle image for every pixel point of the input speckle image in an image block mode to obtain an offset (Δx′,Δy′), and calculating the depth information of the pixel point according to a depth calculating formula by use of the offset. 
     A self-correction device of a structured light depth camera of a smart phone comprises: 
     a projection and receiving device module, wherein an infrared laser speckle projector projects a speckle image, and after the speckle image is reflected by a target object or a projection space, the projected speckle image is received by the infrared image receiving sensor; 
     an AP module, which is used for controlling parameters such as the numbers, shapes and sizes of feature blocks, matching blocks, matching search windows and the like, and calculating the optimal offset of the change of the optical axes of the reference speckle image and the input speckle image; 
     a self-correction module, which is used for detecting the change of the optical axes of the reference speckle image and the input speckle image, calculating the offset of the reference speckle image relative to the input speckle image through the feature block of the reference speckle image and the matching block of the input speckle image, and correcting the reference speckle image according to the optimal offset, wherein the module comprises a reference speckle image and input speckle image preprocessing submodule, a reference speckle image feature block and input speckle image matching search window generating submodule, a matching block and feature block similarity calculating submodule, an offset (similarity maximum matching block) calculating submodule, an offset change detecting submodule and a reference speckle image adjusting submodule; and the submodules are as follows: 
     1) the reference speckle image and input speckle image preprocessing submodule is used for carrying out preprocessing including RAW data format conversion, adaptive denoising, coherence enhancing, binarization and the like on a speckle image received by the image receiving sensor; 
     2) the reference speckle image feature block and input speckle image matching search window generating submodule is used for extracting a feature block of which the center point is (x,y) and the size is m×n from the reference speckle window, and extracting a matching search window which takes a point corresponding to the position of the center point of the feature block as the center and has a certain range from the input speckle window; 
     3) the matching block and feature block similarity calculating submodule calculates the similarities between the feature block and all matching blocks with the same size in the matching search window according to a block matching similarity criterion; 
     4) the similarity maximum matching block calculating submodule is used for calculating the maximum value of all the similarities between the feature block and the different matching blocks, the matching block corresponding to the maximum value is an optimal speckle matching block of the feature block, the corresponding offset (Δx,Δy) is the offset vector of the feature block, and the offset is obtained by subtracting a coordinate value (x′, y′) of the center point of the optimal matching block from a coordinate value (x,y) of the center point of the feature block according to an X-axis and a Y-axis separately; 
     5) the offset change detecting submodule is used for determining the change direction and size of the reference speckle image relative to the input speckle image, namely the change direction and size of the optimal axis of the laser speckle projector relative to the optical axis of the image receiving sensor; 
     6) the reference speckle image adjusting submodule is used for reversely adjusting the reference speckle image according to the optimal offset output by AP; and 
     a depth calculating module is used for calculating the offset of a pixel point according to the corrected reference speckle image and the input speckle image, and calculating the depth corresponding to the center point of the input speckle image block according to the depth calculating formula by use of the offset in the X or Y direction. 
     The method and the device provided by the invention can effectively solve the problems of reduction of depth precision, increasing of mismatching noises and the like of the infrared laser speckle projector and the infrared receiving image sensor due to the change of optical axes, real-time self-correction of the structured light depth camera in the smart phone is realized, and the robustness of the depth camera is improved. 
     By the technical solution, the beneficial effects of the invention are specifically embodied through embodiments which are set forth below. 
    
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         FIG. 1  is a structure block diagram of a self-correction device for a structured light depth camera of a smart phone; 
         FIG. 2  is a flow chart of a self-correction method for a structured light depth camera of a smart phone; 
         FIG. 3  is a schematic diagram of a laser speckle pattern; 
         FIG. 4  is a schematic diagram of a feature block of a reference speckle image and a matching search window; 
         FIG. 5  is a flow chart of a self-correction process; 
         FIG. 6  is a flow chart of an AP manual control process; and 
         FIG. 7  is a schematic diagram of a method for solving the rotation angle of an image. 
     
    
    
     DETAILED DESCRIPTION 
     A self-correction method and device in the invention are further illustrated in detail below in combination with drawings  1 - 7 . 
       FIG. 1  is a structure block diagram of a self-correction device for a structured light depth camera of a smart phone of an embodiment of the invention. As shown in  FIG. 1 , the self-correction device comprises a projection and receiving module  10 , an AP module  11 , a self-correction module  12  and a depth calculating module  13 . 
     The projection and receiving module  10  is used for receiving an input speckle image which is projected from an infrared laser speckle projector, acquired by an image receiving sensor and used for depth calculation, and a reference speckle image. 
     The infrared laser speckle projector projects a speckle image, may consist of a vertical cavity surface emitting laser (VCSEL), a collimating mirror and a diffractive optical element (DOE), may also consist of a semiconductor laser device (LD), a collimating mirror and a diffractive optical element (DOE), may further consist of a digital light procession (DLP) projector, an LD/VCSEL and a micro-electro-mechanical systems (MEMS) device and the like, and projected speckle patterns comprise a random speckle, rule symbol array structured light, a mixed structured light speckle including a random speckle and rule symbols, and the like. 
     The input speckle image is an input speckle image sequence which is acquired by the infrared laser speckle projector and the image receiving sensor, and the reference speckle image is a speckle image which is cured in an internal or external memory and has known depth distance information. 
     The AP module  11  is used for controlling parameters and processes such as the number and size of feature blocks extracted from the reference speckle image, the range and size of a matching search window in the input speckle image and the size of matching blocks extracted from the matching search window in a matching process, and meanwhile, the optimal offset of the change of the optical axes of the reference speckle image and the input speckle image can be calculated in a manual or automatic mode to adjust and correct the reference speckle image. 
     By the self-correction module  12 , the change of the optical axes of the reference speckle image and the input speckle image are detected, the offset of the reference speckle image relative to the input speckle image is calculated through the feature block of the reference speckle image and the matching block of the input speckle image, the reference speckle image is corrected according to the optimal offset, thus, the center of the input speckle image and the center of the reference speckle image form a self-feedback adjusting closed-loop system, an optimal matching relation between the input speckle image and the corrected reference speckle image can always be found out when the optical axes vary widely, and a correct offset is obtained and is used for depth calculation. 
     The self-correction module  12  further comprises a reference speckle image and input speckle image preprocessing submodule  121 , a reference speckle image feature block and input speckle image matching search window generating submodule  122 , a match block and feature block similarity calculating submodule  123 , an offset (similarity maximum matching block) calculating submodule  124 , an offset change detecting submodule  125  and a reference speckle image adjusting submodule  126 . 
     The reference speckle image and input speckle image preprocessing submodule  121  is used for carrying out adaptive preprocessing including RAW data format conversion, adaptive denoising, coherence enhancing, binarization and the like on the reference speckle image and the input speckle image, and aims to enable a laser speckle image to be clear and reduce noise interference through preprocessing on the laser speckle image, and self-correction and depth sensing and calculation of contents in the invention are facilitated. 
     The reference speckle image feature block and input speckle image matching search window generating submodule  122  is used for extracting an image block of which the size is m×n from the position of a point (x,y) in the reference speckle image as a feature block, a matching search window is an input speckle image block which takes the corresponding point, of which the position is the same as that of the center point (x,y) of the feature block as the center point, in the input speckle image and is extracted in a certain range around the center point, the size is M×N, M and N are integers, and generally, M&gt;m and N&gt;n, wherein m×n is the size of the feature block in the reference speckle image, m is the width of the feature block, and n is the height of the feature block; and M×N is the size of the matching search window in the input speckle image, M is the width of the search window, and N is the height of the search window. 
     The matching block and feature block similarity calculating submodule  123  is used for extracting an image block of which the size is the same as that of the feature block from the matching search window as a matching block, calculating the similarity between the feature block and the matching block according to a normalized cross correlation method (NCC) similarity criterion or sum-of-absolute-values-of-differences (SAD), and simultaneously obtaining similarities between the feature block and all matching blocks through parallel calculation. 
     The similarity maximum matching block calculating submodule  124  is used for solving a maximum value of all similarities which are obtained by carrying out matching calculation on the same feature block through the matching block and feature block similarity calculating submodule  123 , the matching block corresponding to the maximum value is the optimal matching block of the feature block, an offset (Δx,Δy) is calculated according to the center point (x,y) of the feature block and coordinates (x′,y′) of the center point of the optimal matching block in the input speckle image, namely the offset vector of the feature block is calculated, and the offset is obtained by subtracting a coordinate value of the center point (x′, y′) of the optimal matching block from a coordinate value (x,y) of the center point of the feature block according to an X-axis and a Y-axis separately. 
     The offset change detecting submodule  125  is used for determining the change direction and size of the reference speckle image relative to the input speckle image according to the offset, namely the directions and sizes of the change of the optical axes of the infrared laser speckle projector and the image receiving sensor are determined. If the infrared laser speckle projector and the image receiving sensor of the projection and receiving module  10  are horizontally placed in the left-right direction before the optical axes change, namely the optical axes of the infrared laser speckle projector and the image receiving sensor are parallel in the horizontal direction, deviation in the direction which is perpendicular to the Y-axis is mainly adjusted after the optical axes change, if Δy≠0, Δy is output to the AP module  11 , the AP module  11  calculates an optimal offset, the reference speckle image is adjusted reversely according to Δy, if Δy=0, it shows that the optical axes do not change, and along with increasing of the offset, the change of the optical axes of the infrared laser speckle projector and the image receiving sensor is increased. On the contrary, if the infrared laser speckle projector and the image receiving sensor of the projection and receiving module  10  are vertically placed before optical axes change, namely the optical axes of the infrared laser speckle projector and the image receiving sensor are parallel in the vertical direction, deviation in the horizontal X-axis direction is mainly adjusted after the optical axes change. Subsequently, the horizontal placement of the infrared laser speckle projector and the image receiving sensor is mainly taken as an example. 
     The reference speckle image adjusting submodule  126  is used for reversely adjusting the reference speckle image according to the offset. If the infrared laser speckle projector and the image receiving sensor are placed horizontally, the reference speckle image is reversely adjusted according to an offset Δy. If Δy&gt;0, it shows that the optical axis of the reference speckle image moves downwards relative to the input speckle image, and the reference speckle image is integrally adjusted upwards, if Δy&lt;0, it shows that the optical axis of the reference speckle image moves upwards relative to the input speckle image, and the reference speckle image is integrally adjusted downwards. Similarly, if the infrared laser speckle projector and the image receiving sensor are placed vertically, the reference speckle image is reversely adjusted according to an offset Δx. 
     The depth calculating module  13  calculates a depth value corresponding to a pixel point in the input speckle image, an image block is extracted from the input speckle image, a point which corresponds to the center point of an input image block is found from the adjusted reference speckle image, a matching search window is extracted around the point in a certain range by taking the point as the center, sum-of-absolute-values-of-differences SAD or normalized cross correlation method (NCC) similarity between the input image block and the matching block in the matching search window is calculated, a matching block which corresponds to a minimum SAD value or a minimum NCC similarity value is solved as a corrected optimal matching block, the position of the center point of the matching block relative to the center point of the matching search window is the offset of the input image block, the depth information of the current center point of the input image block is calculated according to the depth calculating formula in combination with the known distance parameter of the reference speckle image and the baseline distance between the infrared laser speckle projector and the image receiving sensor, and a depth map corresponding to the whole input speckle image is obtained after point-by-point and line-by-line calculation is carried out. 
     The size of the image block extracted from the input speckle image in a depth calculating process and the size of the feature block extracted from the reference speckle image feature block and matching search window generating submodule in a self-correction process can be the same, and can also be different. 
     The device has the following basic functions: the input speckle image sequence (with unknown depth information) from the infrared laser speckle projector and the image receiving sensor is compared with the reference speckle image (which is a standard speckle image as a matching reference, and has a fixed pattern and known depth distance information) by image adaptive preprocessing, a speckle feature block is extracted from the reference speckle image, block matching motion estimation is carried out on the speckle feature block and a matching block of which the size is the same as that of the feature block in an input matching search window, a matching block which is the most similar to the feature block is found by a certain search strategy and a similarity criterion to obtain the offset of coordinates of the matching block in the input speckle image and coordinates of the center point of the feature block, the reference speckle image is reversely adjusted according to the offset, the adjusted reference speckle image and the input speckle image are subjected to block matching motion estimation to obtain the offset of every point in the input speckle image relative to the reference speckle image, the depth information of the current center point is obtained according to the offset, the known distance parameter of the reference speckle image and the baseline distance between the infrared laser speckle projector and the image receiving sensor and on the basis of the depth calculating formula, and the depth information corresponding to the whole input speckle image is obtained after point-by-point and line-by-line calculation is carried out. Functions of various submodules of the device will be illustrated in more detail in introduction of the flow of the method hereinafter. 
       FIG. 2  is an integral flow chart of the self-correction method for the structured light depth camera of the smart phone of the embodiment of the invention. In order to clearly illustrate the self-correction method provided by the invention, the method will be described below in combination with  FIG. 2 - FIG. 7 , and particularly, the method comprises the following steps: 
     step 1: projecting a speckle image by an infrared laser speckle projector, and receiving the projected speckle image and generating an input speckle image and a reference speckle image by an image receiving sensor. 
     Particularly, the infrared laser speckle projector projects a laser beam in a fixed graph to a plane which is distant from the infrared laser speckle projector by a distance of d, the plane is perpendicular to the center axis of the projector, and a matching reference graph which is acquired by the image receiving sensor, adaptively preprocessed and stored, and is used for carrying out depth sensing and calculation on the input speckle image sequence is the reference speckle image. 
     A speckle image is formed by projecting a laser beam to a target object or a projection space by the infrared laser speckle projector, and then is acquired by the image receiving sensor to obtain the input speckle image. The input speckle image is subjected to adaptive preprocessing like the reference speckle image.  FIG. 3  shows a laser speckle pattern projected by the infrared laser speckle projector, and the laser speckle pattern consists of random speckle points.  FIG. 3  shows a laser speckle pattern which is only taken as an example, and the contents of the invention are suitable for various structured light speckle patterns including a random speckle, rule symbol array structured light, a mixed structured light speckle comprising a random speckle and rule symbols and the like. 
     Step 2: detecting the change of the optical axis of the reference speckle image relative to the input speckle image, and correcting the reference speckle image according to the optimal offset. 
     In a specific embodiment, step 2 further comprises: 
     step 2.1: preprocessing the reference speckle image and the input speckle image, setting feature blocks in the reference speckle image, wherein the center point of the feature blocks is (x i=1, . . . , p , y i=1, . . . , p ), and the sizes of the feature blocks are m×n, and extracting a matching search window which takes a point corresponding to the position of (x i=1, . . . , p , y i=1, . . . , p ) as the center and has the size being M×N (wherein M&gt;m, N&gt;n) from the input speckle image; wherein 
     preprocessing on the reference speckle image and the input speckle image comprises adaptive preprocessing including RAW data format conversion, adaptive denoising, coherence enhancing, binarization and the like. 
     Step 2.2: extracting a matching block with the size being m×n from the matching search window, and calculating the similarity between the matching block and the feature block through a similarity criterion, wherein the matching block corresponding to the maximum similarity is the optimal matching block; 
     particularly, as shown in  FIG. 2 , extracting a matching block A rel  of which the size is m×n and is the same as the size of the feature block from the matching search window, and calculating the similarity between the feature block A ref  and the matching block A rel  according to a normalized cross correlation method (NCC) similarity criterion formula: 
             sim   =       (         n   0     ⁢   c     -   ab     )           a   ⁡     (       n   0     -   a     )       ⁢     b   ⁡     (       n   0     -   b     )                   
or calculating the similarity between the feature block A ref  and the matching block A rel  according to a sum-of-absolute-values-of-differences (SAD) formula:
 
             sim_sad   =       ∑     i   =   1     m     ⁢       ∑     j   =   1     n     ⁢            x     i   ,   j       -     y     i   ,   j                        
wherein n 0  is the number of pixel points of the matching block (or the number of pixel points of the feature block, namely m×n),
 
               a   =       ∑     i   =   1     m     ⁢       ∑     j   =   1     n     ⁢     x     i   ,   j     2           ,     
     ⁢     b   =       ∑     i   =   1     m     ⁢       ∑     j   =   1     n     ⁢     y     i   ,   j     2           ,     
     ⁢     c   =       ∑     i   =   1     m     ⁢       ∑     j   =   1     n     ⁢       x     i   ,   j       ⁢     y     i   ,   j               ,         
x i,j  shows values of the pixel points in the feature block, and y i,j  shows the values of the pixel points in the matching block.
 
     As shown in  FIG. 4 , for every matching block A rel  in the matching search window, the similarity between the matching block A rel  and the feature block A ref  is calculated, the maximum value max(sim M×N ) or max(sim′ M×N ) of all similarity values in the matching search window is solved, and the matching block corresponding to the maximum similarity is the optimal matching block. 
     Step 2.3: extracting the center point (x′ i=1, . . . , p , y′ i=1, . . . , p ) of the optimal matching block, and calculating the offset (Δx i=1, . . . , p , Δy i=1, . . . , p ) between the center point (x i=1, . . . , p , y i=1, . . . , p ) of the feature block and the center point (x′ i=1, . . . , p , y′ i=1, . . . , p ) of the matching block; 
     for example, the infrared laser speckle projector and the image receiving sensor are horizontally placed in the left-right direction before optical axes change, namely, the optical axes of the infrared laser speckle projector and the image receiving sensor are parallel in the horizontal direction, and after the optical axes change, deviation in the direction which is perpendicular to a Y-axis is mainly adjusted. As shown in  FIG. 5 , after corresponding points are found out, the offset Δy i  in the direction y and the offset Δx i  in the direction x of every corresponding point of the reference speckle image and the input speckle image are calculated according to the formula below.
 
Δ y   i   =y   i   −y′   i  
 
Δ x   i   =x   i   −x′   i  
 
     Step 2.4: detecting the offset, outputting the offset (Δx i ,Δy i ) to the mobile phone AP terminal and solving the optimal offset according to a certain rule; and 
     particularly, as shown in  FIG. 5 , calculating the maximum value Δy max  and the minimum value Δy min , which correspond to the center point of the matching block of the input speckle image, of the center point of the feature block of the reference speckle image. 
     Then the optimal offset used for image correction is calculated according to  FIG. 5 . A threshold value th is set, if a judgment condition Δy max −Δy min &lt;=th is met, the mean value of Δy i  is taken as the optimal offset for the image correction: 
     
       
         
           
             
               Δ 
               ⁢ 
               
                   
               
               ⁢ 
               y 
             
             = 
             
               
                 1 
                 p 
               
               ⁢ 
               
                 
                   ∑ 
                   
                     i 
                     = 
                     1 
                   
                   p 
                 
                 ⁢ 
                 
                   Δ 
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   
                     y 
                     i 
                   
                 
               
             
           
         
       
     
     or as shown in  FIG. 6 , Δy is adjusted under manual control at the AP terminal to enable the effect of the depth map to be optimal. 
     If the judgment condition Δy max −Δy min &lt;=th is not met, the rotation angle θ of an image needs to be calculated through a point (x i=1, . . . , p , y i=1, . . . , p ) and a point (x′ i=1, . . . , p , y′ i=1, . . . , p ) to rotatably correct the reference speckle image. 
     As shown in  FIG. 7 , for a point (x i , y i ) and a point (x′ i , y′ i ), an included angle θ i  between the two points is solved and is as follows: 
     
       
         
           
             
               tan 
               ⁢ 
               
                   
               
               ⁢ 
               
                 θ 
                 i 
               
             
             = 
             
               
                 
                   y 
                   i 
                 
                 - 
                 
                   y 
                   i 
                   ′ 
                 
               
               
                 
                   x 
                   i 
                 
                 - 
                 
                   x 
                   i 
                   ′ 
                 
               
             
           
         
       
     
     namely 
     
       
         
           
             
               θ 
               i 
             
             = 
             
               arctan 
               ⁢ 
               
                 
                   
                     
                       y 
                       i 
                     
                     - 
                     
                       y 
                       i 
                       ′ 
                     
                   
                   
                     
                       x 
                       i 
                     
                     - 
                     
                       x 
                       i 
                       ′ 
                     
                   
                 
                 . 
               
             
           
         
       
     
     The reference speckle image is subjected to reverse rotational processing by the mean value 
               Δ   ⁢           ⁢   θ     =       1   p     ⁢       ∑     i   =   1     p     ⁢     θ   i               
of all angles:
 
     Image ref =rotate(Image ref ,−Δθ), or as shown in  FIG. 6 , Δθ is adjusted under manual control at the AP terminal to enable the effect of the depth map to be optimal. 
     Step 2.5: integrally adjusting the position of the reference speckle image in the up-down direction (−Δy) or the left-right direction (−Δx) reversely according to the optimal offset; 
     If Δy≠0, the reference speckle image is reversely corrected according to the offset Δy, namely:
 
Image ref =Image ref   −Δy,  
 
and if Δy=0, the reference speckle image is not corrected.
 
     Step 3, searching the optimal matching block of every pixel point of the input speckle image in the reference speckle image in an image block mode to obtain an offset (Δx′,Δy′), and calculating the depth information of the pixel point by use of the offset according to the depth calculating formula. 
     Particularly, the image block is extracted from the input speckle image, the matching search window which has a certain range is extracted from the corrected reference speckle image, the matching block of which the size is the same as that of the input image block is extracted from the matching search window, SAD values or NCC similarity of the input image block and the matching block is calculated, the matching block corresponding to the minimum SAD value or NCC similarity value is the optimal matching block, and the offset of the center point of the optimal matching block relative to the position of the center point of the matching search window is the offset (Δx′,Δy′) of the input image block. 
     An offset Δm (Δm=Δx′, or Δm=Δy′) in the x direction or the Y direction is selected, and in combination with the known distance d of the reference speckle image, the focal length f of the image receiving sensor, the baseline distance s between the infrared laser speckle projector and the image receiving sensor and the pixel pitch parameter μ of the pixel points of the image receiving sensor, the depth information d′ of the center point (x,y) of the input image block is calculated according to the following formula: 
     
       
         
           
             
               d 
               ′ 
             
             = 
             
               fsd 
               
                 fs 
                 + 
                 
                   Δ 
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   m 
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   μ 
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   d 
                 
               
             
           
         
       
     
     wherein the optimal offset Δm is equal to the difference between the coordinate value of the center point x of the matching search window and the coordinate value of the center point x′ of the optimal matching block, or the difference between the coordinate value of the center point y of the matching search window and the coordinate value of the center point y′ of the optimal matching block, and Δm can be positive or negative. 
     Preferably, if the optical axes of the infrared laser speckle projector and the image receiving sensor are parallel in the horizontal direction, then only the offset Δy of the feature block and the optimal matching block in the Y-axis direction can be concerned, and the center of the optical axis of the input speckle image and the center of the optical axis of the corrected reference speckle image are kept parallel in the horizontal direction by reversely adjusting the offset −Δy of the reference speckle image. Similarly, if the optical axes of the infrared laser speckle projector and the image receiving sensor are parallel in the vertical direction, then only the offset Δx of the feature block and the optimal matching block in the X-axis direction can be concerned, and the center of the optical axis of the input speckle image and the center of the optical axis of the corrected reference speckle image are kept parallel in the vertical direction by reversely adjusting the offset −Δx of the reference speckle image. 
     As an example, a search strategy and a similarity measurement index use a traditional full search block matching and normalized cross correlation method (NCC) similarity criterion and sum-of-absolute-values-of-differences (SAD) method, but various other improved search strategies and similarity measurement indexes can also be used, such as a three step search method (TSS), and the self-correction method and device which are provided by the invention are not affected when different similarity search strategy methods are used. The search strategy in the invention searches matching blocks one by one, the precision can reach the pixel level, and by performing interpolation calculation on the pixel points of the speckle images, and the precision can also reach the sub-pixel level. 
     Although the foregoing embodiment is finished in a specific system, it should not be regarded as the limitation to the invention, the invention can be similarly applied to a similar pattern projection and image sensor system, the number of speckle feature blocks for detecting an offset is not limited to be 1, can be more than 1, and can be 2, 3, 4, . . . , n; and the sizes or shapes of the speckle feature blocks are variable, and the speckle feature blocks can be in geometrical shapes such as rectangle, diamond and roundness besides square. Therefore, modifications and improvements which are made within the spirit and scope of the invention shall be included in the foregoing claims. 
     In one embodiment, the present disclosure provides an automatic correction method for a structured-light 3D depth camera. The method comprises the following steps: 
     S 100 , acquiring a first feature block from a reference encoded image, wherein the depth distance of the reference encoded image is known; 
     S 200 , searching for a first matching block corresponding to the first feature block from an input encoded image; 
     S 300 , acquiring a first offset of the first feature block relative to the first matching block according to optical axis positions of a laser encoded pattern projector and an image reception sensor; 
     S 400 , correcting a position of the reference encoded image according to the first offset; and 
     S 500 , acquiring a first feature block from the corrected reference encoded image if the first offset is not zero, and returning to S 200 . 
     In this embodiment, the optimal encoded matching block corresponding to the encoded feature block is searched for in the input encoded image in the above steps through the similarity criterion, and then the offset of the feature block relative to the matching block is acquired; and the offset is detected, if the optical axis of the laser encoded pattern projector and the optical axis of the image reception sensor change, the offset of the feature block relative to the matching block will change accordingly, and then the position of the reference encoded image is oppositely adjusted upwards or downwards according to an offset change to form a self-feedback regulation closed-loop system between the center of the input encoded image and the center of the reference encoded image so that the optimal matching relation can always be figured out when the optical axis of the input encoded image and the optimal axis of the reference encoded image change drastically. 
     According to the method or device based on any one of the above or below implementation schemes/characteristics/aspects, the laser encoded pattern projector is used to project a structured-light encoded image and is formed by a vertical cavity surface emitting laser (VCSEL), a collimating lens and a diffractive optical element (DOE), or is formed by a laser diode (LD), a collimating lens and a DOE, or is formed by LD/VCSEL and a Micro Electro Mechanical System (MEMS) or adopts digital light processing (DLP) for projection. Structured-light encoded patterns projected by the laser encoded pattern projector include random speckles, regular symbol array structured light, and hybrid structured light codes of the random speckles and the regular symbol array structured light. 
     The input encoded image is an encoded pattern formed by projecting a laser beam to a target object or to a projection space with the laser encoded pattern projector and is then transmitted, and finally, is collected by the image reception sensor to acquire an encoded image sequence. The speckle pattern is adaptively preprocessed like the reference encoded image, and after being preprocessed, the speckle pattern is stored in rows according to a field synchronization signal and a row synchronization signal. The present disclosure is suitable for various structured-light encoded patterns such as random speckles, regular symbol array structured light, and hybrid structured-light codes of the random speckles and the regular symbol array structured light. 
     The reference encoded image is cured in an internal or external memory, has known depth distance information and is stored in rows after being preprocessed like the input encoded image, and the row data position in which the reference encoded image is read is the same as that of the input encoded image. 
     Preprocessing carried out on the reference encoded image and the input encoded image includes RAW data format conversion, adaptive noise cancellation, coherence-enhancing, binarization and the like. By preprocessing the laser encoded image, the encoded pattern is clearer, noise interference is reduced, and automatic correction and depth perception calculation described above are facilitated. 
     The reference encoded image is a matching reference pattern which is obtained by projecting a laser beam in a constant pattern with the laser projector to a plane with a distance d away from the laser projector and perpendicular to the central axis of the projector, is acquired by the image reception sensor and is stored to be used for depth perception calculation of the input encoded image sequence after being adaptively preprocessed. The reference encoded image can be a laser speckle encoded pattern formed by random speckles, a symbol array encoded pattern formed by regular symbols or a hybrid encoded pattern formed by random speckles and regular symbols. 
     The method based on any one of the above or below implementation schemes/characteristics/aspects further comprises the following steps: 
     S 600 , acquiring one pixel of the input encoded image, and taking the pixel as a first pixel; acquiring a second feature block with the first pixel as a center; 
     S 700 , searching for a second matching block matched with the second feature block from the corrected reference encoded image; 
     S 800 , acquiring a second offset of the second feature block relative to the second matching block, and calculating a depth distance corresponding to the first pixel according to the second offset; and 
     S 900 , returning to S 600  till depth distances corresponding to all pixels of the input encoded image are acquired. 
     In this embodiment, an input image block is extracted from the input encoded image, a point corresponding to the center point of the input image block is found out in the adjusted reference encoded image, a matching search window within a certain range is extracted with the point as the center, and a candidate matching block with the maximum similarity is taken as the optimal matching block; the position offset of the center point of the optimal matching block relative to the center point of the matching search window is obtained, and this offset is the second offset of the input image block; and the depth information of the current center point of the input image block is calculated according to a depth calculation formula based on the known distance parameter of the reference encoded image and the baseline distance between the laser encoded pattern projector and the image reception sensor, and a depth map corresponding to the input whole speckle image is obtained through point-by-point and row-by-row calculation. 
     In this embodiment, when the optical axes change drastically, depth calculation is carried out in terms of the corrected offset after the optimal matching relation between the input encoded image and the reference encoded image is figured out, and in this way, the problems of depth precision reduction and mismatch noise increase caused by deflection of the optical axis of the laser pattern projector or the image sensor when falling, collision or the like occurs in the using process are solved. 
     According to the method or device based on any one of the above or below implementation schemes/characteristics/aspects, the depth calculation formula is preferably as follows: 
     
       
         
           
             
               d 
               ′ 
             
             = 
             
               fsd 
               
                 fs 
                 + 
                 
                   Δ 
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   m 
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   μ 
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   d 
                 
               
             
           
         
       
     
     In the formula, d is the known distance of the reference encoded image, f is the focal length of the image sensor, s is the baseline distance between the laser projector and the image reception sensor, μ is the pixel pitch parameter of the image sensor, d′ is the depth information of the center point (x,y) of the input image block, Δm is the difference between coordinates of the center point of the input image block and the center point x′ of the optimal matching block, wherein Δm=Δx′, or Δm=Δy′. 
     According to the method based on any one of the above and below implementation schemes/characteristics/aspects, searching in S 200  and S 700  comprises the following steps: 
     determining a center and size of a matching search window, wherein the center of the matching search window is a center point of the feature block, and the size of the matching search window is greater than the size of the feature block; and 
     extracting candidate matching blocks from the matching search window, calculating similarities of the candidate matching blocks to the feature block, and taking the candidate matching block with the maximum similarity as the matching block corresponding to the feature block. 
     According to the method or device based on any one of the above or below implementation schemes/characteristics/aspects, for each feature block, the maximum similarity is figured out of all the similarities obtained through matching calculation, a matching block corresponding to the maximum similarity is taken as the optimal marching block of the feature block, the coordinate (x′, y′) of the center point of the optima matching block in the input encoded image is output, an offset (Δx,Δy) calculated according to (x,y) and (x′, y′) is the offset vector of the feature block, and the offset is calculated by subtracting the coordinate (x′, y′) of the center point of the optimal matching block from the coordinate (x,y) of the center point of the feature block in terms of X axis and Y axis. 
     As for multiple feature blocks, the offset of the center point (x i=1, . . . , p , y i=1, . . . , p ) of each feature block relative to the center point (x′ i=1, . . . , p , y′ i=1, . . . , p ) of the corresponding matching block is calculated in terms of the following formula:
 
Δ x   i   =x   i   −x′   i  
 
Δ y   i   =y   i   −y′   i  
 
     An average of (Δx i=1, . . . , p , Δy i=1, . . . , p ) is taken as the optimal offset (Δx, Δy); 
     
       
         
           
             
               
                 Δ 
                 ⁢ 
                 
                     
                 
                 ⁢ 
                 x 
               
               = 
               
                 
                   1 
                   p 
                 
                 ⁢ 
                 
                   
                     ∑ 
                     
                       i 
                       = 
                       1 
                     
                     p 
                   
                   ⁢ 
                   
                     Δ 
                     ⁢ 
                     
                         
                     
                     ⁢ 
                     
                       x 
                       i 
                     
                   
                 
               
             
             , 
             
               
 
             
             ⁢ 
             
               
                 Δ 
                 ⁢ 
                 
                     
                 
                 ⁢ 
                 y 
               
               = 
               
                 
                   1 
                   p 
                 
                 ⁢ 
                 
                   
                     ∑ 
                     
                       i 
                       = 
                       1 
                     
                     p 
                   
                   ⁢ 
                   
                     Δ 
                     ⁢ 
                     
                         
                     
                     ⁢ 
                     
                       y 
                       i 
                     
                   
                 
               
             
           
         
       
     
     According to the method based on any one of the above or below implementation schemes/characteristics/aspects, acquisition in S 300  preferably comprises the following steps: 
     S 301 , acquiring center point coordinates of each feature block and the matching block corresponding to each feature block, and calculating differences between corresponding coordinate components of the center point coordinates; 
     S 302 , acquiring an average of the differences between all the coordinate components and taking the average as the first offset. 
     According to the method based on any one of the above or below implementation schemes/characteristics/aspects, correction in S 300  comprises the following steps: 
     S 311 , if the optical axes of the laser encoded pattern projector and the image reception sensor are parallel to a first component of the first offset, moving in a direction opposite to a second component of the first offset by a distance equal to the absolute value of the second component of the first offset; 
     S 312 , if the optical axes of the laser encoded pattern projector and the image reception sensor are parallel to the second component of the first offset, moving in a direction opposite to the first component of the first offset by a distance equal to the absolute value of the first component. 
     The components of the first offset herein are two-dimensional vectors and include an X-axis vector and a Y-axis vector in the rectangular coordinate system of the image. 
     In this embodiment, if the optical axes of a projector and a reception camera in a structured-light projection and reception device are parallel in the horizontal direction, only an offset Δy of the encoded feature block relative to the optimal feature block in the Y-axis direction is considerable, the offset −Δy of the reference encoded image is oppositely adjusted till the center of the optical axis of the input encoded image and the center of the optical axis of the corrected reference encoded image are kept parallel in the horizontal direction. Similarly, if the optical axes of the projector and the reception camera in the structured-light projection and reception device are parallel in the vertical direction, only the offset Δx of the encoded feature block relative to the optimal matching block in the X-axis direction is considerable, and the offset −Δx of the reference encoded image is oppositely adjusted till the center of the optical axis of the input encoded image and the center of the optical axis of the corrected reference encoded image are kept parallel in the vertical direction. 
     A reference encoded image position adjustment sub-module oppositely adjusts the reference encoded image according to the offset Δy, wherein if Δy&gt;0, the whole reference encoded image is adjusted upwards, and Image ref =Image ref −Δy; if Δy&lt;0, the whole reference encoded image is adjusted downwards, and Image ref =Image ref +Δy; and if Δy=0, it indicates that the optical axis of the reference encoded image does not change relative to the optical axis of the input encoded image, and the reference encoded image does not need to be adjusted. According to the method in one embodiment, an encoded image sequence (with depth information unknown) input through a laser encoded pattern projector and an image reception sensor after being adaptively preprocessed is compared with a reference encoded image (serving as a standard encoded image of the matching criterion and having a constant pattern and known depth distance information) which is cured in a memory, an encoded feature block is extracted from the reference encoded image, matching movement between the encoded feature block and matching blocks, having the same size as the encoded feature block, input to the matching search window is estimated, and the optimal matching block most similar to the feature block is found out based on a certain search strategy and similarity criterion; an offset of the coordinate of the matching block in the input encoded image relative to the coordinate of the center point of the feature block is acquired, and the reference encoded image is oppositely adjusted according to the offset; block matching movement between the adjusted reference encoded image and the input encoded image is estimated to obtain an offset of each point in the input encoded image relative to the reference encoded image, then the depth information of the current center point is calculated according to a depth calculation formula based on the offset, the known distance parameter of the reference encoded image and the baseline distance between the laser encoded pattern projector and the image reception sensor, and finally, the depth information corresponding to the input whole encoded image is obtained through point-by-point and row-by-row calculation. 
     In one embodiment, the present disclosure provides an automatic correction device for a structured-light 3D depth camera. The device comprises: 
     a first acquisition module configured to acquire a first feature block from a reference encoded image, wherein the reference encoded image has a known depth distance; 
     a first search module configured to search for a first matching block corresponding to the first feature block from an input encoded image; 
     a first offset acquisition module configured to acquire a first offset of the first feature block relative to the first matching block according to optical axis positions of a laser encoded pattern projector and an image reception sensor; 
     a correction module configured to correct a position of the reference encoded image according to the first offset; and 
     a first return module configured to acquire a first feature block from the corrected reference encoded image if the first offset is not zero and to return to the first search module. 
     In this embodiment, an image block having a size of m×n is extracted by the first acquisition module from a point (x,y) in the reference encoded image to be taken as the feature block. The first search module extracts an input encoded image block within a certain range with a corresponding point, identical with the center point (x,y) of the feature block, of the input encoded image as the center point, wherein the input encoded image block has a size of M×N, M and N are integers, generally M&gt;m, and N&gt;n. 
     The device based on any one of the above or below implementation schemes/characteristics/aspects further comprises: 
     a second acquisition module configured to acquire one pixel of the input encoded image, to take the pixel as a first pixel and to acquire a second feature block with the first pixel as a center; 
     a second search module configured to search for a second matching block matched with the second feature block from the corrected reference encoded image; 
     a calculation module configured to acquire a second offset of the second feature block relative to the second matching block and to calculate a depth distance corresponding to the first pixel according to the second offset; and 
     a second return module configured to return to the second acquisition module till depth distances corresponding to all pixels in the input encoded image are acquired. 
     According to the device based on any one of the above or below implementation schemes/characteristics/aspects, the first search module and the second search module preferably carry out searching through the following steps: 
     determining a center and size of a matching search window, wherein the center of the matching search window is a center point of the feature block, and the size of the matching search window is greater than the size of the feature block; and 
     extracting candidate matching blocks from the matching search window, calculating similarities of the candidate matching blocks to the feature block, and taking the candidate matching block with the maximum similarity as the matching block corresponding to the feature block. 
     According to the device based on any one of the above or below implementation schemes/characteristics/aspects, the first offset acquisition module preferably acquires the first offset through the following steps: 
     acquiring center point coordinates of each feature block and the matching block corresponding to each feature block, and calculating differences between corresponding coordinate components of the center point coordinates; and 
     acquiring an average of the differences between all the coordinate components and taking the average as the first offset. 
     In the above embodiment, the first offset acquisition module preferably carries out correction through the following steps: 
     if the optical axes of the laser encoded pattern projector and the image reception sensor are parallel to a first component of the first offset, moving in a direction opposite to a second component of the first offset by a distance equal to the absolute value of the second component of the first offset; 
     if the optical axes of the laser encoded pattern projector and the image reception sensor are parallel to the second component of the first offset, moving in a direction opposite to the first component of the first offset by a distance equal to the absolute value of the first component; 
     wherein, the components of the first offset are two-dimensional vectors. 
     According to the device or method based on any one of the above or below implementation schemes/characteristics/aspects, the similarities are calculated through any one of the following methods: 
     Method 1: sum of absolute differences (SAD); 
     Method 2: normalization cross correlation (NCC) similarity criterion; 
     Method 3: three-step search (TSS). 
     The automatic correction method and device provided by the present disclosure will not be affected no matter which similarity search strategy or method is adopted. 
     According to the device or method based on any one of the above or below implementation schemes/characteristics/aspects, in the search strategy the matching blocks are preferably searched for one by one so that the precision can reach the pixel level, and the precision can even reach the sub-pixel level through interpolating calculation of the pixels of the speckle image. 
     Preferably, in terms of calculation based on the NCC similarity criterion, if the feature block is marked as A ref , the corresponding matching block is marked as A rel  and the similarity is marked as sim, the following relation is met: 
     
       
         
           
             sim 
             = 
             
               
                 ( 
                 
                   nc 
                   - 
                   ab 
                 
                 ) 
               
               
                 
                   
                     a 
                     ⁡ 
                     
                       ( 
                       
                         n 
                         - 
                         a 
                       
                       ) 
                     
                   
                   ⁢ 
                   
                     b 
                     ⁡ 
                     
                       ( 
                       
                         n 
                         - 
                         b 
                       
                       ) 
                     
                   
                 
               
             
           
         
       
     
     Wherein, n 0  is the number of pixels of the matching block (or the number of pixels of the feature block, namely m×n); 
               a   =       ∑     i   =   1     m     ⁢       ∑     j   =   1     n     ⁢     x     i   ,   j     2           ,     
     ⁢     b   =       ∑     i   =   1     m     ⁢       ∑     j   =   1     n     ⁢     y     i   ,   j     2           ,     
     ⁢     c   =       ∑     i   =   1     m     ⁢       ∑     j   =   1     n     ⁢       x     i   ,   j       ⁢     y     i   ,   j               ,         
wherein, x i,j  is the value of the pixels of the feature block, and y i, j  is the value of the pixels of the matching block.
 
     As shown in  FIG. 4 , a matching block A rel  is extracted from each point in the matching search window, the similarity between A rel  and A ref  is calculated, the maximum similarity max(sim M×N ) or max(sim′ M×N ) of all the similarities in the matching search window is figured out, and the matching block corresponding to the maximum similarity is the optimal matching block. 
     According to the device or method based on any one of the above or below implementation schemes/characteristics/aspects, the size of the image block extracted from the input encoded image can be identical with or different from the size of the feature block extracted from the reference encoded image and the size of the feature block extracted by an input encoded image matching search window generation sub-module in the automatic correction process. 
     The self-correction method and device for the structured light depth camera of the smart phone provided by the invention not only are suitable for the structured light depth camera in the mobile phone, but also are suitable for other monocular, binocular or multi-view structured light depth camera modules; and meanwhile, the contents and the device of the invention can be realized by an ASIC chip, and can be realized on IP core embedded SoC application or software on various SoC processors (CPU, GPU, DSP and AP), and therefore, modifications and improvements which are made within the spirit and scope of the invention shall be included in the foregoing claims.