MATLAB多边形容器(边数>>4)目标检测问题:大象检测失败排查
桌面图像中大象检测的多边形轮廓问题
我尝试修改MATLAB代码以检测桌面图像中的大象,预期使用边数远多于4的多边形大致贴合大象轮廓标记目标区域,但多次尝试后,即使调用ginput(12)仍仅得到4边形,怀疑是参数设置存在问题。以下为初始代码及我修改后的代码:
初始代码
clear all close all clc %% read images % template boxImage = imread('./immaginiObjectDetection/stapleRemover.jpg'); % desk sceneImage = imread('./immaginiObjectDetection/clutteredDesk.jpg'); figure(1), clf, imshow(boxImage) figure(2), clf, imshow(sceneImage) % figure(1), clf, imagesc(boxImage) % figure(2), clf, imagesc(sceneImage) tic %% keypoint detection boxPoints = detectSURFFeatures(boxImage); scenePoints = detectSURFFeatures(sceneImage); figure(1), clf imshow(boxImage), hold on plot(selectStrongest(boxPoints,100)), hold off figure(2), clf imshow(sceneImage), hold on plot(selectStrongest(scenePoints,100)), hold off %% keypoint description [boxFeatures, boxPoints]=extractFeatures(boxImage, boxPoints); [sceneFeatures, scenePoints]=extractFeatures(sceneImage, scenePoints); %% feature matching boxPairs = matchFeatures(boxFeatures, sceneFeatures); matchedBoxPoints = boxPoints(boxPairs(:,1),:); matchedScenePoints = scenePoints(boxPairs(:,2),:); showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints, ... matchedScenePoints, 'montage'); %% geometric consistency check [tform, inlierBoxPoints, inlierScenePoints]=... estimateGeometricTransform(matchedBoxPoints,... matchedScenePoints,'affine'); showMatchedFeatures(boxImage, sceneImage, inlierBoxPoints, ... inlierScenePoints, 'montage'); %% bounding box drawing boxPoly = [1 1; size(boxImage,2) 1; size(boxImage,2) size(boxImage,1); 1 size(boxImage,1); 1 1]; newBoxPoly=transformPointsForward(tform,boxPoly); figure, clf imshow(sceneImage), hold on line(newBoxPoly(:,1),newBoxPoly(:,2),'Color','y') hold off toc %% more precise bounding box figure, clf imshow(boxImage) [x,y]=ginput(4); %% x=[x; x(1)]; y=[y; y(1)]; newBoxPoly=transformPointsForward(tform,[x y]); figure, clf imshow(sceneImage), hold on line(newBoxPoly(:,1),newBoxPoly(:,2),'Color','y') hold off toc
修改后的代码
clear all close all clc %% read images % template boxImage = imread('./immaginiObjectDetection/elephant.jpg'); % desk sceneImage = imread('./immaginiObjectDetection/clutteredDesk.jpg'); figure(1), clf, imshow(boxImage) figure(2), clf, imshow(sceneImage) % figure(1), clf, imagesc(boxImage) % figure(2), clf, imagesc(sceneImage) tic %% keypoint detection boxPoints = detectSURFFeatures(boxImage, 'MetricThreshold', 1000); scenePoints = detectSURFFeatures(sceneImage); figure(1), clf imshow(boxImage), hold on plot(selectStrongest(boxPoints,100)), hold off figure(2), clf imshow(sceneImage), hold on plot(selectStrongest(scenePoints,100)), hold off %% keypoint description [boxFeatures, boxPoints]=extractFeatures(boxImage, boxPoints); [sceneFeatures, scenePoints]=extractFeatures(sceneImage, scenePoints); %% feature matching boxPairs = matchFeatures(boxFeatures, sceneFeatures, 'MatchThreshold', 30, ... 'Method','Exhaustive'); matchedBoxPoints = boxPoints(boxPairs(:,1),:); matchedScenePoints = scenePoints(boxPairs(:,2),:); showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints, ... matchedScenePoints, 'montage'); %% geometric consistency check [tform, inlierBoxPoints, inlierScenePoints]=... estimateGeometricTransform(matchedBoxPoints,... matchedScenePoints,'projective', 'Confidence', 90, 'MaxDistance', 3); showMatchedFeatures(boxImage, sceneImage, inlierBoxPoints, ... inlierScenePoints, 'montage'); %% bounding box drawing boxPoly = [1 1; size(boxImage,2) 1; size(boxImage,2) size(boxImage,1); 1 size(boxImage,1); 1 1]; newBoxPoly=transformPointsForward(tform,boxPoly); figure, clf imshow(sceneImage), hold on line(newBoxPoly(:,1),newBoxPoly(:,2),'Color','y') hold off toc %% more precise bounding box figure, clf imshow(boxImage) [x,y]=ginput(12); %% x=[x; x(1)]; y=[y; y(1)]; newBoxPoly=transformPointsForward(tform,[x y]); figure, clf imshow(sceneImage), hold on line(newBoxPoly(:,1),newBoxPoly(:,2),'Color','y') hold off toc
内容的提问来源于stack exchange,提问作者Francesco Scipione
相关产品推荐
相关产品推荐

