Disclosure of Invention
The invention aims to overcome the defects of the prior art and provides a real-time three-dimensional deformation measuring method based on GPU parallel acceleration. In all matching, the left camera image L before deformation is used0As a reference image, the pre-calculation data of the IC-GN algorithm can be repeatedly used, so that a large amount of calculation is saved. The method has the advantages that the algorithm is accelerated by developing a GPU program based on CUDA, the computing capability of hardware is fully exerted, real-time three-dimensional deformation measurement is achieved, the computing speed can exceed 40 frames per second when the number of interest points is about 10000, and the problems that the computing speed of an existing three-dimensional deformation measurement method is low and real-time measurement requirements cannot be met are solved.
In order to achieve the purpose, the technical scheme provided by the invention is as follows: a real-time three-dimensional deformation measurement method based on GPU parallel acceleration comprises the following steps:
1) using Zhangyingyou scaling method to make stereo scaling on left and right fixed cameras to obtain projection matrix M of left and right camerasL、MR;
2) Synchronously shooting left and right images L of the surface of the target object before deformation by using the two cameras0、 R0And the left and right images L at the ith moment in the deformation processi、RiWherein i ═ 1,2,3, …, n;
3) in the image L0Selecting an interest area, and taking a batch of interest points P at equal intervals in the interest areaL0;
4) Copying a projection matrix of the camera, all shot images and interest points to a GPU;
5) on the GPU, for each interest point PL0Firstly, an IC-GN algorithm is used for searching the image R0Corresponding point P onR0Then using PL0、PR0The coordinates of the two points are calculated by a triangulation method to obtain the three-dimensional coordinates P of the interest point before deformationW0;
6) On the GPU, the following operations are carried out on each time i in the deformation process: first, for each point of interest PL0Use the IC-GN algorithm to find it in the image Li、RiCorresponding point P onLiAnd PRiThen using PLi、PRiThe coordinates of the two points are calculated by triangulation to obtain the three-dimensional coordinates P of the interest point at the moment iwiFinally with PWiMinus PW0Obtaining three-dimensional deformation data D of the interest point at the moment iWi;
7) And copying the three-dimensional deformation data of all the interest points at each moment back to the CPU, so as to obtain the three-dimensional deformation of the surface of the object at each moment.
In step 1), the projection matrix has a size of 3 × 4, which represents the relationship between the three-dimensional space coordinates and the two-dimensional coordinates on the camera image.
In step 3), the interest area refers to an area which needs to be measured and is designated by a user, and the interest point interval in the area is also selected according to the measurement requirement.
In step 4), the shot image is firstly stored in a page-locked memory allocated by using a runtime function cudamallocost in the CUDA, and then the data is copied to the GPU by using a runtime function cudaMemcpy in the CUDA; the camera parameters are copied to the constant memory of the GPU, enabling it to be accessed at high speed.
In step 5) and step 6), the IC-GN algorithm is used, wherein the input is a batch of interest points, reference images and target images, and a CUDA thread block is used to process a computation task corresponding to an interest point, including the following:
a. carrying out precalculation: for each interest point, calculating a corresponding Hessian matrix and storing data; using a CUDA thread block to complete the calculation task of each interest point, wherein the Hessian matrix is
Representing the accumulation of all pixel positions within a reference sub-area, which is a 33 x 33 sub-image centered at the point of interest; ψ is the coordinate of the point of interest, # is the local coordinate in the reference sub-area, # R (ψ + ζ) is the gradient of the reference image,
is a Jacobian matrix, and T represents the transposition of the matrix;
b. and (c) for each interest point, setting the coordinate of the interest point as (x, y), and estimating the initial value p of the deformation vector of the interest point by using an image feature assisted method (u, u)x,uy,uxx,uxy,uyy,v,vx,vy,vxx,vxy,vyy) (ii) a Wherein u, v are translation amounts; u. ofx,uy,vx,vyIs the first order gradient component; u. ofxx,uxy,uyy,vxx,vxy,vyyIs the second order gradient component; here, a CUDA thread is used to accomplish a programCalculating the interest points;
c. for each interest point, iteratively updating the corresponding deformation vector p according to the following steps:
c1, calculating the deformation vector increment delta p:
wherein H-
1The inverse of the Hessian matrix is represented,
and
normalized coefficients for the reference and target sub-regions respectively,
representing the target sub-area after subtraction of the mean value of the gray levels,
representing the reference subarea after subtracting the gray mean value, and W (zeta; p) represents a transformation function from the local coordinate of the reference subarea to the local coordinate of the target subarea;
c2, calculating new transformation function W (ζ; p') as W (W) by using Δ p-1(ζ; Δ p); p) wherein W-1(ζ; Δ p) is the inverse of W (ζ; Δ p); then extracting a new deformation vector p 'from the new transformation function W (zeta; p');
c3, updating p, namely making p equal to p';
c4, repeating c1 to c3 until | | | Δ p | | < 0.001, and | | · | | | represents the modular length of the vector;
d. and (3) calculating the coordinates of the interest point at the corresponding point of the target map as (x ', y'), wherein x 'is x + u, and y' is y + v.
In step 6), the IC-GN algorithm used does not need to be pre-calculated, and the data stored after the IC-GN algorithm is pre-calculated in step 5) is directly used.
In step 5) and step 6), triangulation methods are used, including the following:
a. let the coordinate of the interest point on the left view be (x)L,yL) The point coordinate on the right view is (x)R,yR) The corresponding three-dimensional coordinate is (X)W,YW,ZW);
b. (X) is calculated in the following mannerW,YW,ZW) Each CUDA thread calculates a three-dimensional coordinate;
wherein A is a coefficient matrix, and
b is a matrix of constant terms, an
m
L rcRepresenting a projection matrix M
LM in the r-th row and c-th column
R rcRepresenting a projection matrix M
RWhere r is 1,2,3, and c is 1,2,3, 4.
Compared with the prior art, the invention has the following advantages and beneficial effects:
1. in all matching of three-dimensional deformation measurement, the invention leads the left camera image L before deformation to be0As a reference image, data obtained by IC-GN pre-calculation such as Hessian matrix and the like corresponding to the interest points can be repeatedly utilized in the processing of images at all times in the three-dimensional deformation process, so that a large amount of calculation is saved, the processing speed is accelerated, and the calculation time is shortened.
2. The GPU program is developed based on the CUDA platform, so that development cost can be saved, development difficulty is reduced, meanwhile, the special CUDA program and corresponding program optimization can furthest exert the calculation performance of GPU hardware, and the requirement of measuring three-dimensional deformation in real time is met.
Detailed Description
The present invention will be described in further detail with reference to examples, but the embodiments of the present invention are not limited thereto.
The real-time three-dimensional deformation measurement method based on GPU parallel acceleration provided by the embodiment comprises the following steps:
1) using a Zhangyingyou calibration method to carry out three-dimensional calibration on the left and right fixed cameras to obtain the projection matrixes M of the left and right camerasL、MR。
2) Synchronously shooting left and right images L of the surface of the target object before deformation by using the two cameras0、 R0And the left and right images L at the ith moment in the deformation processi、RiWhere i is 1,2,3, …, n.
3) In the image L0Selecting an interest area, and taking a batch of interest points P at equal intervals in the interest areaL0(ii) a The interest area refers to an area which is specified by a user and needs to be measured, and the interest point interval in the area is also selected according to the measurement requirement.
4) Copying a projection matrix of the camera, all shot images and interest points to a GPU; the method comprises the steps that a shot image is stored in a page locking memory distributed by using a runtime function cudaMallocost in a CUDA (compute unified device architecture), and then data are copied to a GPU (graphics processing unit) by using a runtime function cudaMemcpy function in the CUDA; the projection matrix of the camera is copied to the constant memory of the GPU, allowing it to be accessed at high speed.
5) On the GPU, for each interest point PL0Firstly, an IC-GN algorithm is used for searching the image R0Corresponding point P onR0Then using PL0、PR0The coordinates of the two points are calculated by a triangulation method to obtain the three-dimensional coordinates P of the interest point before deformationW0。
6) On the GPU, the following operations are carried out on each time i in the deformation process: first, for each point of interest PL0Use the IC-GN algorithm to find it in the image Li、RiCorresponding point P onLiAnd PRiThen using PLi、PRiThe coordinates of the two points are calculated by triangulation to obtain the three-dimensional coordinate of the interest point at the time iMark PwiFinally with PWiMinus PW0Obtaining three-dimensional deformation data D of the interest point at the moment iWi(ii) a The IC-GN algorithm used does not need to be pre-calculated, and the data stored after the IC-GN algorithm is pre-calculated in the step 5) is directly utilized.
7) And copying the three-dimensional deformation data of all the interest points at each moment back to the CPU, so as to obtain the three-dimensional deformation of the surface of the object at each moment.
In step 5) and step 6), the IC-GN algorithm is used, wherein the input is a batch of interest points, reference images and target images, and a CUDA thread block is used to process a computation task corresponding to an interest point, including the following:
a. carrying out precalculation: for each interest point, calculating a corresponding Hessian matrix and storing data; using a CUDA thread block to complete the calculation task of each interest point, wherein the Hessian matrix is
Representing the accumulation of all pixel positions within a reference sub-area, which is a 33 x 33 sub-image centered at the point of interest; ψ is the coordinate of the point of interest, # is the local coordinate in the reference sub-area, # R (ψ + ζ) is the gradient of the reference image,
is a Jacobian matrix, and T represents the transposition of the matrix;
b. and (c) for each interest point, setting the coordinate of the interest point as (x, y), and estimating the initial value p of the deformation vector of the interest point by using an image feature assisted method (u, u)x,uy,uxx,uxy,uyy,v,vx,vy,vxx,vxy,vyy) (ii) a Wherein u, v are translation amounts; u. ofx,uy,vx,vyIs the first order gradient component; u. ofxx,uxy,uyy,vxx,vxy,vyyIs twoAn order gradient component; here, a CUDA thread is used to perform a point of interest computing task;
c. for each interest point, iteratively updating the corresponding deformation vector p according to the following steps:
c1, calculating the deformation vector increment delta p:
wherein H-
1The inverse of the Hessian matrix is represented,
and
normalized coefficients for the reference and target sub-regions respectively,
representing the target sub-area after subtraction of the mean value of the gray levels,
representing the reference subarea after subtracting the gray mean value, and W (zeta; p) represents a transformation function from the local coordinate of the reference subarea to the local coordinate of the target subarea;
c2, calculating new transformation function W (ζ; p') as W (W) by using Δ p-1(ζ; Δ p); p) wherein W-1(ζ; Δ p) is the inverse of W (ζ; Δ p); then extracting a new deformation vector p 'from the new transformation function W (zeta; p');
c3, updating p, namely making p equal to p';
c4, repeating c1 to c3 until | | | Δ p | | < 0.001, and | | · | | | represents the modular length of the vector;
d. and (3) calculating the coordinates of the interest point at the corresponding point of the target map as (x ', y'), wherein x 'is x + u, and y' is y + v.
In step 5) and step 6), triangulation methods are used, including the following:
a. setting the point of interest atThe coordinates on the left view are (x)L,yL) The point coordinate on the right view is (x)R,yR) The corresponding three-dimensional coordinate is (X)W,YW,ZW);
b. (X) is calculated in the following mannerW,YW,ZW) Each CUDA thread calculates a three-dimensional coordinate;
wherein A is a coefficient matrix, and
b is a matrix of constant terms, an
m
L rcRepresenting a projection matrix M
LM in the r-th row and c-th column
R rcRepresenting a projection matrix M
RWhere r is 1,2,3, and c is 1,2,3, 4.
The above embodiments are preferred embodiments of the present invention, but the present invention is not limited to the above embodiments, and any other changes, modifications, substitutions, combinations, and simplifications which do not depart from the spirit and principle of the present invention should be construed as equivalents thereof, and all such changes, modifications, substitutions, combinations, and simplifications are intended to be included in the scope of the present invention.