Incorrect fundamental matrix from blender camera simulation

I have set up a basic simulation in Blender with a simple mesh model and 2 cameras. The camera views both have full overlap of the object. The first camera is at the origin and the second camera is at t = [1.15, 0.15, -0.36]m and Quat(w,x,y,z) = [0.985, -0.013, 0.084, 0.149] both relative to the first camera (and the world since camera 0 is aligned with world origin). The second camera has a relative translation and rotation from the first camera. The default coordinate system for a Blender camera can be seen by the RGB axes in the image below, with the Z axis pointing away from the image direction.
I've calculated using Matlab's stereo camera calibration app. I then use the fundamental Matrix and the SURF feature points to calculate the epipolar lines of the first image from the points in the second image. I then plot these lines on both of the images to compare. The camera images appear to have a positive x axis pointing to the right and a positive y axis pointing down which is the opposite to the camera coordinate system.
Image 1 is on the left and image 2 is on the right.
You can see that the epipolar lines don't align with the points in either image. I've also checked point correspondences manually using x'*F*x = 0 and the values returned have not been close to 0. When I change the cameras to be in a stereo setup i.e. with no relative rotation and only translated along the x axis, the epipolar lines do align with the points. I also tried manually calculating the fundamental matrix since I can get the intrinsics and extrinsics from the blender simulation and had the same result. Any ideas on why the fundamental matrix/epipolar lines don't seem to be correct?
Code:
image_1 = imread('images/monkey_1.png');
image_2 = imread('images/monkey_2.png');
load(fullfile('params','stereo_camera_calib.mat'));
%%Extract and plot features
I1 = rgb2gray(image_1);
I1 = undistortImage(I1,stereoParams.CameraParameters1);
points_1 = detectSURFFeatures(I1);
[features_1,points_1] = extractFeatures(I1,points_1);
points_1 = points_1.selectStrongest(10);
I2 = rgb2gray(image_2);
I2 = undistortImage(I2,stereoParams.CameraParameters2);
points_2 = detectSURFFeatures(I2);
[features_2,points_2] = extractFeatures(I2,points_2);
points_2 = points_2.selectStrongest(10);
image_handle_1 = figure;
iptsetpref('ImshowAxesVisible','on');
imshow(I1);
hold on
plot(points_1);
image_handle_2 = figure;
iptsetpref('ImshowAxesVisible','on');
imshow(I2);
hold on
plot(points_2);
%%Calculate fundamental matrix
F = stereoParams.FundamentalMatrix;
%%Calculate epipolar lines
epiLines = epipolarLine(F, points_2.Location);
set(0, 'CurrentFigure', image_handle_1);
points = lineToBorderPoints(epiLines,size(image_1));
line(points(:,[1,3])',points(:,[2,4])');
set(0, 'CurrentFigure', image_handle_2);
points = lineToBorderPoints(epiLines,size(image_2));
line(points(:,[1,3])',points(:,[2,4])');

Answers (0)

Asked:

on 25 May 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!