Same question: http://stackoverflow.com/questions/34461821/calibration-of-images-to-obtain-a-top-view-for-points-that-lie-on-a-same-plane Though, the below code is from Matlab. I am open to any solutions using opencv. Calibration:
I have calibrated the camera using this vision toolbox in Matlab. I used checkerboard images to do so. After calibration I get the following:
>> cameraParams
cameraParams =
cameraParameters with properties:
Camera Intrinsics
IntrinsicMatrix: [3x3 double]
FocalLength: [1.0446e+03 1.0428e+03]
PrincipalPoint: [604.1474 359.7477]
Skew: 3.5436
Lens Distortion
RadialDistortion: [0.0397 0.0798 -0.2034]
TangentialDistortion: [-0.0063 -0.0165]
Camera Extrinsics
RotationMatrices: [3x3x18 double]
TranslationVectors: [18x3 double]
Accuracy of Estimation
MeanReprojectionError: 0.1269
ReprojectionErrors: [48x2x18 double]
ReprojectedPoints: [48x2x18 double]
Calibration Settings
NumPatterns: 18
WorldPoints: [48x2 double]
WorldUnits: 'mm'
EstimateSkew: 1
NumRadialDistortionCoefficients: 3
EstimateTangentialDistortion: 1
Aim: I have recorded trajectories of some objects in motion using this camera. Each object corresponds to a single point in a frame. Now, I want to project the points such that I get a top-view.
Data sample:
K>> [xcor_i,ycor_i ]
ans =
-101.7000 -77.4040
-102.4200 -77.4040
-103.6600 -77.4040
-103.9300 -76.6720
-103.9900 -76.5130
-104.0000 -76.4780
-105.0800 -76.4710
-106.0400 -77.5660
-106.2500 -77.8050
-106.2900 -77.8570
-106.3000 -77.8680
-106.3000 -77.8710
-107.7500 -78.9680
-108.0600 -79.2070
-108.1200 -79.2590
-109.9500 -80.3680
-111.4200 -80.6090
-112.8200 -81.7590
-113.8500 -82.3750
-115.1500 -83.2410
-116.1500 -83.4290
-116.3700 -83.8360
-117.5000 -84.2910
-117.7400 -84.3890
-118.8800 -84.7770
-119.8400 -85.2270
-121.1400 -85.3250
-123.2200 -84.9800
-125.4700 -85.2710
-127.0400 -85.7000
-128.8200 -85.7930
-130.6500 -85.8130
-132.4900 -85.8180
-134.3300 -86.5500
-136.1700 -87.0760
-137.6500 -86.0920
-138.6900 -86.9760
-140.3600 -87.9000
-142.1600 -88.4660
-144.7200 -89.3210
Code(Ref:http://stackoverflow.com/a/27260492/3646408):
load('C:\Users\sony\Dropbox\calibration_images\matlab_calibration_data.mat');
R = cameraParams.RotationMatrices(:,:,1);
t = cameraParams.TranslationVectors(1, :);
% combine rotation and translation into one matrix:
R(3, :) = t;
%Now compute the homography between the checkerboard and the image plane:
H = R * cameraParams.IntrinsicMatrix;
%Transform the image using the inverse of the homography:
I=imread('C:\Users\sony\Dropbox\calibration_images\Images\exp_0.jpg');
J = imwarp(I, projective2d(inv(H)));
imshow(J);
How can I do the same for points?
Edit 1:
Quoting text from OReilly Learning OpenCV Pg 412: "Once we have the homography matrix and the height parameter set as we wish, we could then remove the chessboard and drive the cart around, making a bird’s-eye view video of the path..." This what I essentially wish to achieve.
New info:
- Note all these points(in data sample) are the on the same plane.
- Also, this plane is perpendicular to one of images of checkerboard used for calibration. For that image(below), I know the height of origin of the checkerboard of from ground(193.040 cm).
Edit 2: Two questions where I am stuck right now:
- Do I need to calibrate all the images or just the image shown above in which the board is perpendicular to the board.
- Using the code given in http://stackoverflow.com/a/27260492/3646408 I can calibrate and get the bird's eye view if the they lie on same plane. But how to do if they are perpendicular.