2016-04-12 4 views
0

У меня есть эталонное изображение, и я хочу, чтобы нарисовать круг вокруг картины, которая существует в опорном кадре. Теперь нарисуйте прямоугольник над изображением, который существует в эталонном изображении, но я не знаю, как сделать его круг.Нарисуйте круг вокруг распознанного изображения в Matlab

boxImage = imread('RefImg.jpg'); 
sceneImage = imread('full_image.jpg'); 
boxPoints = detectSURFFeatures(rgb2gray(boxImage)); 
scenePoints = detectSURFFeatures(rgb2gray(sceneImage)); 
[boxFeatures, boxPoints] = extractFeatures(rgb2gray(boxImage), boxPoints); 
[sceneFeatures, scenePoints] = extractFeatures(rgb2gray(sceneImage), scenePoints); 

boxPairs = matchFeatures(boxFeatures, sceneFeatures); 
matchedBoxPoints = boxPoints(boxPairs(:, 1), :); 
matchedScenePoints = scenePoints(boxPairs(:, 2), :); 
figure; 
showMatchedFeatures(rgb2gray(boxImage),rgb2gray(sceneImage), matchedBoxPoints, ... 
    matchedScenePoints, 'montage'); 
title('Putatively Matched Points (Including Outliers)'); 
[tform, inlierBoxPoints, inlierScenePoints] = ... 
    estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'affine'); 
figure; 
showMatchedFeatures(rgb2gray(boxImage), rgb2gray(sceneImage), inlierBoxPoints, ... 
    inlierScenePoints, 'montage'); 
title('Matched Points (Inliers Only)'); 

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); 
    figure; 


imshow(sceneImage); 
hold on; 
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y'); 
title('Detected Box'); 

Спасибо,

+1

есть функция в CVST 'insertShape' – Amro

ответ

0

Вы можете использовать rectangle на самом деле нарисовать эллипс вокруг вашего объекта интереса с помощью параметра Curvature.

%// Transform your points 
boxCorners = [1, 1; size(boxImage, 2), size(boxImage, 1)]; 
box = transformPointsForward(tform, boxCorners); 

%// Position as [x, y, width, height] 
position = [boxCorners(1,:), diff(boxCorners)]; 

%// Display the image 
imshow(sceneImage); 
hold on 

%// Plot an ellipse at this location 
rectangle('Position', position, 'Curvature', [1 1]) 

Если вы хотите, чтобы принудительное исполнение фактического круга, вы хотите, чтобы диаметр диагонального расстояния поперек прямоугольника и центра, чтобы быть серединой диагонали прямоугольника.

boxCorners = [1, 1; size(boxImage, 2), size(boxImage, 1)]; 
box = transformPointsForward(tform, boxCorners); 

%// Now compute the diagonal distance (diameter) 
diameter = sqrt(sum(diff(box).^2)); 

%// Now determine the middle of the circle 
center = mean(box); 

%// Display the image 
imshow(sceneImage); 
hold on 

%// Now plot the circle 
t = linspace(0, 2*pi, 100); 
plot(center(1) + cos(t) * diameter/2, ... 
    center(2) + sin(t) * diameter/2); 
+0

И как я должен отображать все это по эталонному изображению? –

+0

Я попытался: line (прямоугольник, прямоугольник, «цвет», «y»), но эллипс не отображается. –

+0

@NeaguV «прямоугольник» * - это команда построения графика. Я обновил ответ командой 'imshow'. – Suever