2

EstimateGeometricTransform に関する Matlab のヘルプでは、エラーがある場合、この関数はステータスを返す可能性があると述べています (たとえば、「matchedPoints1 および matchingPoints2 入力に十分なポイントが含まれていません」)。次のように記述する必要があります。

[___,status] = estimateGeometricTransform(matchedPoints1,matchedPoints2,transformType) 

しかし、私の場合はうまくいきません。

 [tform, status] = estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, ...
     'projective');

そのコマンドの後、ステータスをチェックするために「IF」ステートメントを使用しています。それが等しくない場合は、いくつかのコマンドを実行する必要があります。しかし、コンソールにエラーが表示されます: MATCHED_POINTS1 と MATCHED_POINTS2 に十分なポイントがありません。 とプログラムが停止します。

どうしたの?

video = 'sample.avi';
hVideoSource = vision.VideoFileReader(video, 'ImageColorSpace', 'Intensity');
hVideoOut = vision.VideoPlayer('Name', 'Detected Box');     

boxImage = imread('cross2.jpg');
boxImage = rgb2gray(boxImage);

boxPoints = detectSURFFeatures(boxImage, 'NumOctaves', 10, 'NumScaleLevels', 15);
figure; imshow(boxImage);
title('100 Strongest Feature');
hold on;
plot(boxPoints.selectStrongest(100));

while ~isDone(hVideoSource)
    sceneImage = step(hVideoSource);
    sceneImage = imadjust(sceneImage);
bw = edge(sceneImage,'canny', 0.15, 2);
bw = imfill(bw,'holes');
se = strel('disk',1); 
bw = imopen(bw,se);
[B,L] = bwboundaries(bw);
stats = regionprops(L,'Centroid','EquivDiameter');
for k = 1:length(B)
 boundary = B{k};
 radius = stats(k).EquivDiameter/2;
 xc = stats(k).Centroid(1);
 yc = stats(k).Centroid(2);
 theta = 0:0.01:2*pi;
 Xfit = radius*cos(theta) + xc;
 Yfit = radius*sin(theta) + yc;

 if (radius > 10)
     rect = [xc-radius yc-radius radius*2 radius*2];
     croppedImage = imcrop(sceneImage, rect);
     rgbImage = cat(3,sceneImage,sceneImage,sceneImage);
     rgbImage = insertShape(rgbImage, 'Circle', [xc yc radius], 'Color', 'green');
     rgbImage = insertShape(rgbImage, 'Rectangle', rect, 'Color', 'yellow');    
 end

end
scenePoints = detectSURFFeatures(croppedImage, 'NumOctaves', 10, 'NumScaleLevels', 15);


    [boxFeatures, boxPoints] = extractFeatures(boxImage, boxPoints);
    [sceneFeatures, scenePoints] = extractFeatures(croppedImage, scenePoints);
    boxPairs = matchFeatures(boxFeatures, sceneFeatures);
    matchedBoxPoints = boxPoints(boxPairs(:, 1), :);
    matchedScenePoints = scenePoints(boxPairs(:, 2), :);


[tform, ~, ~, status] = estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, ...
     'affine');
if (status ~= 1)
boxPolygon = [1, 1;...                           % top-left
        size(boxImage, 2), 1;...                 % top-right
        size(boxImage, 2), size(boxImage, 1);... % bottom-right
        1, size(boxImage, 1);...                 % bottom-left
        1, 1];                   % top-left again to close the polygon
    newBoxPolygon = transformPointsForward(tform, boxPolygon);

Poly = [newBoxPolygon(1,1) newBoxPolygon(1,2) newBoxPolygon(2,1) newBoxPolygon(2,2) ...
        newBoxPolygon(3,1) newBoxPolygon(3,2) newBoxPolygon(4,1) newBoxPolygon(4,2)...
        newBoxPolygon(5,1) newBoxPolygon(5,2)];

croppedImage = cat(3,croppedImage,croppedImage,croppedImage);
croppedImage = insertShape(croppedImage, 'Polygon', Poly, 'Color', 'green');
imshow(croppedImage);
else
croppedImage = cat(3,croppedImage,croppedImage,croppedImage);
croppedImage = insertText(croppedImage, [0 0], 'NO', 'TextColor', 'red');
imshow(croppedImage);
end

step(hVideoOut, rgbImage);
croppedImage = rgb2gray(croppedImage);
end
release(hVideoSource);
release(hVideoOut);
4

1 に答える 1

3

の前に他のオプションの出力がありますstatus

[tform,inlierpoints1,inlierpoints2]  = estimateGeometricTransform(...)

関数を呼び出す方法には、status実際にはinlierPoints1.

ステータスを取得し、関数がエラーをスローしないようにするために必要なことは次のとおりです。

[tform, ~, ~, status] = estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, ...
     'projective');

より良い方法は、 を呼び出す前にポイント数を確認することestimateGeometricTransformです。

if size(boxPairs, 1) >= 3
   tform = estimateGeometricTransform(..., 'affine')
else
   % skip this frame
end

射影には、3 ではなく 4 を使用します。

于 2013-12-25T21:02:51.693 に答える