Invalid indexing operation- drawing epipolar lines
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello
I am creating Stereo images processing project modeled on Matlab's examples. A copy pasted code from one of them not works well.
I1 = rgb2gray(imread('viprectification_deskLeft.png'));
I2 = rgb2gray(imread('viprectification_deskRight.png'));
points1 = detectHarrisFeatures(I1);
points2 = detectHarrisFeatures(I2);
[features1, valid_points1] = extractFeatures(I1, points1);
[features2, valid_points2] = extractFeatures(I2, points2);
indexPairs = matchFeatures(features1, features2);
matchedPoints1 = valid_points1(indexPairs(:, 1),:);
matchedPoints2 = valid_points2(indexPairs(:, 2),:);
figure; showMatchedFeatures(I1, I2, matchedPoints1, matchedPoints2);
load stereoPointPairs
[fLMedS, inliers] = estimateFundamentalMatrix(matchedPoints1,matchedPoints2,'NumTrials',4000);
figure;
subplot(121); imshow(I1);
title('Inliers and Epipolar Lines in First Image'); hold on;
plot(matchedPoints1(inliers,1), matchedPoints1(inliers,2), 'go');
An error:
Error using epilineTest (line 23) Invalid indexing operation.
Best regards
EDIT:// I deleted if/end, this was unnecessary
4 comentarios
Geoff Hayes
el 7 de Jun. de 2014
If it is the last line, plot(matchedPoints1(inliers,1), matchedPoints1(inliers,2), 'go');, put a breakpoint here and re-run the function. When the code pauses at this line, run the following commands in the Command Window
>> size(matchedPoints1)
>> size(matchedPoints2)
>> size(inliers)
>> size(matchedPoints1(inliers,1))
>> size(matchedPoints1(inliers,2))
What are the results returned for each of the above commands? Unfortunately, I can't run your code since I don't have the Computer Vision System Toolbox..
Respuesta aceptada
Más respuestas (3)
Geoff Hayes
el 7 de Jun. de 2014
The second error is obvious: the matchedPoints1 matrix is only 89x1 but the matchedPoints1(inliers,2) is trying to access the second column which doesn't exist. Hence the Index exceeds matrix dimensions. Strange since the extractFeatures function sates that it does return an mx2 matrix (valid_points1/2) and you are getting an mx1 (after the extraction from valid_points into matchedPoints).
Looking at http://www.mathworks.com/help/vision/ref/extractfeatures.html, the second return value, valid_points from extractFeatures, is not necessarily an mx2 matrix of coordinates but will/should match the input data type. In your case, that is cornerPoints (I think?) based on the return value of the * detectHarrisFeatures* function (see http://www.mathworks.com/help/vision/ref/detectharrisfeatures.html ). So I suspect that your valid_points1/2 and so matchedPoints1/2 are cornerPoints objects. To verify this, re-run the code with the breakpoint and when the code pauses, in the command window type
>> class(matchedPoints1)
>> class(valid_points1)
>> class(matchedPoints2)
>> class(valid_points2)
If that is the case, then even though the size of this object is 89x1, it may only be a single object with 89 points so you cannot treat it like an array (see http://www.mathworks.com/help/vision/ref/cornerpoints-class.html). This class does provide its own plotting method so that may be of some use i.e. plot(matchedPoints1).
Jan
el 8 de Jun. de 2014
Editada: Jan
el 8 de Jun. de 2014
4 comentarios
Geoff Hayes
el 9 de Jun. de 2014
I think that the problem may be that you are trying to merge the two examples. The first was looks fine - it doesn't try to use the plot function against the matchedPoints1/2 sets of data (cornerPoints) that are computed using the detectHarrisFeatures function. The "mistake" with the other is that it doesn't discuss how it generates the matchedPoints1/2 sets of data. But seeing how the example later uses them to plot data, then we have to assume that they have been pre-calculated using some algorithm that returns mx2 arrays of coordinates.
Jan
el 9 de Jun. de 2014
1 comentario
Geoff Hayes
el 9 de Jun. de 2014
Take a look at the documentation for cornerPoints http://www.mathworks.com/help/vision/ref/cornerpoints-class.html. If matchedPoints1 is a cornerPoints object, then matchedPoints1.Location may return something that will give you an idea of the [x y] coordinates.
Ver también
Categorías
Más información sobre Feature Detection and Extraction en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!