Image recognition and reconstruction of an image
1 次查看(过去 30 天)
显示 更早的评论
I'm attaching a matlab code below.
I1 = imread('professor.jpg');
I2 = imread('professor.jpg');
I1 = imrotate(I1, 270);
I2 = imrotate(I2, 180);
figure
imshowpair(I1, I2, 'montage');
title('Original Images');
% camera parameters
load upToScaleReconstructionCameraParameters.mat
I1 = undistortImage(I1, cameraParams);
I2 = undistortImage(I2, cameraParams);
figure
imshowpair(I1, I2, 'montage');
title('Undistorted Images');
% feature points
imagePoints1 = detectMinEigenFeatures(I1, 'MinQuality', 0.1);
% detected points
figure
imshow(I1, 'InitialMagnification', 50);
title('200 Strongest Corners from the First Image');
hold on
plot(selectStrongest(imagePoints1, 150));
% point tracker creation
tracker = vision.PointTracker('MaxBidirectionalError', 1, 'NumPyramidLevels', 5);
% point tracker Initialization
imagePoints1 = imagePoints1.Location;
initialize(tracker, imagePoints1, I1);
% Track the points
{imagePoints2, validIdx} == step(tracker, I2);
{matchedPoints1} == imagePoints1(validIdx);
{matchedPoints2} == imagePoints2(validIdx);
% Visualize correspondences
figure
showMatchedFeatures(I1, I2, matchedPoints1, matchedPoints2);
title('Tracked Features');
% Estimate the fundamental matrix
[E, epipolarInliers] = estimateEssentialMatrix(...
matchedPoints1, matchedPoints2, cameraParams, 'Confidence', 99);
% Find epipolar inliers
inlierPoints1 = matchedPoints1(epipolarInliers, :);
inlierPoints2 = matchedPoints2(epipolarInliers, :);
% Display inlier matches
figure
I3=showMatchedFeatures(I1, I2, inlierPoints1, inlierPoints2);
title('Epipolar Inliers');
[orient, loc] = relativeCameraPose(E, cameraParams, inlierPoints1, inlierPoints2);
% Detect dense feature points. Use an ROI to exclude points close to the
% image edges.
roi = [30, 30, size(I1, 2) - 30, size(I1, 1) - 30];
imagePoints1 = detectMinEigenFeatures(I1, 'ROI', roi, ...
'MinQuality', 0.001);
% Create the point tracker
tracker = vision.PointTracker('MaxBidirectionalError', 1, 'NumPyramidLevels', 5);
% Initialize the point tracker
imagePoints1 = imagePoints1.Location;
initialize(tracker, imagePoints1, I1);
% Track the points
[imagePoints2, validIdx] = step(tracker, I2);
matchedPoints1 = imagePoints1(validIdx, 5);
matchedPoints2 = imagePoints2(validIdx, 5);
camMatrix1 = cameraMatrix(cameraParams, eye(3), [0 0 0]);
% Compute extrinsics of the second camera
[R, t] = cameraPoseToExtrinsics(orient, loc);
camMatrix2 = cameraMatrix(cameraParams, R, t);
% Compute the 3-D points
points3D = triangulate(matchedPoints1, matchedPoints2, camMatrix1, camMatrix2);
% Get the color of each reconstructed point
numPixels = size(I1, 1) * size(I1, 2);
allColors = reshape(I1, [numPixels, 1]);
colorIdx = sub2ind([size(I1, 1), size(I1, 2)], round(matchedPoints1(:,2)), ...
round(matchedPoints1(:, 1)));
color = allColors(colorIdx, :);
% Visualize the camera locations and orientations
cameraSize = 0.3;
figure
plotCamera('Size', cameraSize, 'Color', 'r', 'Label', '1', 'Opacity', 0);
hold on
grid on
plotCamera('Location', 'Orientation', orient, 'Size', cameraSize, ...
'Color', 'b', 'Label', '2', 'Opacity', 0);
% Visualize the point cloud
%pcshow(ptCloud, 'VerticalAxis', 'y', 'VerticalAxisDir', 'down', ...
% 'MarkerSize', 45);
% Rotate and zoom the plot
camorbit(0, -30);
camzoom(1.5);
% Label the axes
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis')
title('Up to Scale Reconstruction of the Scene');
% Detect the globe
%globe = pcfitsphere(ptCloud, 0.1);
% Display the surface of the globe
%plot(globe);
title('Estimated Location and Size of the Globe');
hold off
% Determine the scale factor
scaleFactor = 10 / globe.Radius;
% Scale the point cloud
ptCloud = pointCloud(points3D * scaleFactor);
loc = loc * scaleFactor;
% Visualize the point cloud in centimeters
cameraSize = 2;
figure
plotCamera('Size', cameraSize, 'Color', 'r', 'Label', '1', 'Opacity', 0);
hold on
grid on
plotCamera('Location', loc, 'Orientation', orient, 'Size', cameraSize, ...
'Color', 'b', 'Label', '2', 'Opacity', 0);
% Visualize the point cloud
pcshow('VerticalAxis', 'y', 'VerticalAxisDir', 'down', ...
'MarkerSize', 45);
camorbit(0, -30);
camzoom(1.5);
% Label the axes
xlabel('x-axis (cm)');
ylabel('y-axis (cm)');
zlabel('z-axis (cm)')
title('Metric Reconstruction of the Scene');
The above is the code. I'm getting an error in load upToScaleReconstructionCameraParameters.mat
It says it's unable to read the file. But when I searched, this mat file is supposed to be part of some toolbox or something of that sort. Can someone please help me figure this out?
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Feature Detection and Extraction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!