A kind of input method of 3D based on the OpenCV camera calibration
Technical field
The present invention relates to a kind of 3D input method, be specifically related to a kind of 3D input method based on OpenCV camera calibration technology with 6DOF.
Background technology
Traditional 2D input equipment,, as trace ball, mouse and plotting apparatus etc., only provide plane (two dimension) positional information, and its three-dimensional position and directional information in space coordinates can not be provided.In order to make up the deficiency of 2D input equipment, a lot of three-dimensional input equipments have appearred in recent years, they are widely applied to the numerous areas such as amusement, robot simulation, medical science, industry, input equipment as three-dimensional operating system, the multidimensional of various game class, simulation class virtual scene is controlled, the principal and subordinate of robot control system, aerial vehicle simulation, operation control etc.
Current main-stream 3D input equipment can be divided into mechanical type, electromagnetic type, optical profile type, acoustics formula and inertia-type etc. according to principle of work, and these device structures are complicated, and line is many, and cost is high, and Maintenance Difficulty should use very inconvenient.The present invention is based on cross-platform computer vision storehouse OpenCV camera calibration technology, utilize general network video camera and PC (perhaps flush bonding processor) to realize chessboard spatial pose accurate Calculation, then with the input message of chessboard posture information as system, for new field has been opened up in the application of 3D input equipment.
Summary of the invention
Order of the present invention be to provide a kind of simple in structure, line is few, easy for installation, cost is low, the technology based on the OpenCV camera calibration of easy realization, has three-dimensional (3D) input method of 6DOF.
The object of the present invention is achieved like this:
(1) size parameter of input checker size, angle point number and video camera output image;
Checker size, angle point number that whether the parameter that (2) judges this input preserves with the last time, the output image in the same size, if consistent, program execution step (3), otherwise program execution step (4);
(3) camera is demarcated, is solved the inner parameter matrix of video camera and the lopsided coefficient that camera lens causes:
1) input need to be carried out the amount of images of camera calibration;
2) mobile or rotation chessboard arrives different positions, and the image by the camera acquisition chessboard, be numbered in order and preserve;
3) image that gathers is carried out gray scale and process, extract the angle point information of checkerboard image;
4) whether the angle point quantity of the checkerboard image that extracts of judgement is consistent with the angle point sum of chessboard, if unanimously, carry out 5), if inconsistent, step 2 again), gather next pictures;
5) extract the information of all angle points of chessboard, and interim the preservation;
6) judge whether the amount of images that video camera demarcates is identical with the number of setting, and, if different, returns to step 2) continue to gather picture, if identical, execution step 7);
7) collect the chessboard angle point information of every different angles, calculate internal reference matrix and the lopsided coefficient of camera;
The internal reference matrix that 8) will calculate and lopsided coefficient, preserve into the XML file, and releasing memory, execution step 4);
(4) image of camera collection chessboard carried out the gray scale processing;
(5) extract the angle point information of chessboard on image;
(6) judge whether the angle point number of input picture is consistent with the angle point sum of chessboard,, if inconsistent, extracts new image, re-executes step (4), if consistent, execution step (7);
(7) extract the positional information of all angle points of chessboard, according to internal reference matrix and the lopsided coefficient of camera, solve the pose of current chessboard, pass through space analysis, obtain respectively 6 degree of freedom information of chessboard, be position (x, y, z) and attitude (γ, β, α), return to finally step (4) and carry out new round cycle calculations, until extracted all images.
Beneficial effect of the present invention is:
The present invention uses chessboard in the movement in space or the rotation amount input message as the 3D input equipment, has overcome the shortcomings such as complex structure, the cost of traditional 3D input equipment be high, difficult in maintenance.Through experiment test, this 3D input equipment can obtain and effectively process the pose of chessboard more accurately, realizes operator's control intention.
Description of drawings
Figure 13 D input equipment schematic diagram;
Figure 23 D input equipment process flow diagram;
Fig. 3 camera calibration process flow diagram.
Embodiment
Below in conjunction with accompanying drawing, the present invention is described further.
The present invention is with a regular black and white chessboard, a Daepori open network video camera and a PC (or embedded microprocessor), camera calibration technology based on OpenCV visual processes storehouse, picture by camera acquisition, and carry out image and process, calculate in real time the chessboard spatial pose, use the 3D input equipment of chessboard pose as input message.
At first the present invention uses the chessboard picture of camera acquisition diverse location, utilize the camera calibration technology of OpenCV, extract the corner location information in chessboard, utilize the corresponding point of angle point on chessboard and its image to carry out direct linear transformation's (DLT conversion) and least square method is determined the inner parameter of camera and, by the lopsided coefficient that camera lens causes, generated and preserve the XML file of video camera internal reference matrix and lopsided coefficient; Then take in real time the chessboard picture by video camera, and picture is carried out gray scale process; Identify and extract the angle point of chessboard, whether judgement is consistent with the real angle point number of chessboard by the chessboard angle point number of identification; , if the number of angle point is consistent, calculate the positional information of chessboard angle point; In conjunction with the corner location information of the internal reference that has solved, lopsided coefficient and chessboard, solve the chessboard volume coordinate information take video camera as initial point, this chessboard volume coordinate is just as the real-time input message of 3D input equipment.
As shown in Figure 1: this equipment is by a regular black and white chessboard (1), general network camera (2), PC or embedded microprocessor (3), form (5) based on function library (4) and the data output unit of OpenCV camera calibration technology.
At first, prepare a black and white chessboard, the checker size is s, and the angle point number is that the parameter of a * b(chessboard can design according to real needs); Then by USB interface, camera is connected with PC, starts video camera, set corresponding initiation parameter, last artificial mobile or rotation chessboard, allow video camera capture in real time the picture frame that comprises chessboard and to process.Idiographic flow as shown in Figure 2, carry out according to the following steps by specific algorithm and operation:
Steps A: at first checker size and chessboard angle point total number, and the size parameter input of video camera output picture;
Step B: according to grid size and angle point number that whether the parameter of this input preserves with the last time, the image in the same size, judge whether system needs video camera is demarcated again, if consistent, program judgement Yes, program enters step C, otherwise program enters step D;
Step C: video camera is demarcated, solved the inner parameter matrix of video camera and the lopsided coefficient that camera lens causes, for solving the chessboard pose, get ready, idiographic flow as shown in Figure 3.
Step C-1: input need to be carried out the number of pictures of camera calibration;
Step C-2: mobile or rotation chessboard arrives different positions, and passes through the image of camera acquisition chessboard, is numbered in order and preserves;
Step C-3: the picture of above-mentioned collection is carried out gray scale process, call cvFindChessboardCorners() function extracts the angle point information of chessboard picture;
Step C-4: whether the angle point number of judgement input picture is consistent with the angle point sum of chessboard,, if consistent, carries out C-5,, if inconsistent, returns to step C-2, next pictures of Resurvey;
Step C-5: after the success of picture Corner Detection, call cvFind Corner SubPix () and extract the information of all angle points of chessboard, and interim the preservation;
Step C-6: whether the number of pictures that camera calibration is carried out in judgement is identical with the number of setting,, if different, return to step C-2 and continues to gather picture;
Step C-7: collect the chessboard angle point information of every different angles, call cvCalibrateCamera2 () function and calculate internal reference matrix and the lopsided coefficient of camera;
Step C-8:, calculating internal reference matrix and lopsided coefficient, preserve into the XML file, and releasing memory, and recall to master routine step D.
Step D:, by the picture of camera collection chessboard, then carry out gray scale and process;
Step e: call cvFind Chessboard Corners() function extracts the angle point information of chessboard on picture;
Step F: whether the angle point number of judgement input picture is consistent with the angle point sum of chessboard,, if inconsistent, returns to step D, new chessboard picture of Resurvey;
Step I: call cvFind Corner SubPix () and extract the positional information of all angle points of chessboard, and in conjunction with internal reference matrix and the lopsided coefficient of the above-mentioned video camera of having preserved, call the pose that cvFind Extrinsic Camera Params2 () function solves current chessboard,, finally by space analysis, obtain respectively 6 degree of freedom information of chessboard, be position (x, y, z) and attitude (γ, β, α), return to finally step D and carry out new round cycle calculations.
So far, by the agency of is complete based on the method for the 3D input equipment of camera calibration technology, in every case any simple modification, equivalent variations is carried out in above enforcement, all belongs in the scope of technical solution of the present invention.