Using vision.Cas​cadeObject​Detector to find rotated faces and findSURFFeatures to align them with original - doesn't work!

1 次查看(过去 30 天)
I'm trying to use a face detector to locate rotated faces in an image and calculate their bounding box locations in the original unrotated image. When I run this code, the rotated face does not line up with the original. Here is the image I am using, blanked out in part to make the test code only search for one face.
Not sure why this doesn't work...
clear all
% Create a face detector
fD1 = vision.CascadeObjectDetector;
I = imread('visionteam+rotfaces1.jpg');
% This detects the first face and puts a bounding box around it.
bboxes = step(fD1, I); % Detect face
fI = insertObjectAnnotation(I, 'rectangle', bboxes, 'a');
figure, imshow(fI)
title('Detected face');
% bboxes x,y,sizex, sizey = 189 41 41 41
% Now rotate the image and detect faces.
I2 = imrotate(I,-90);
bboxes2 = step(fD1, I2); % Detect face
fI2 = insertObjectAnnotation(I2, 'rectangle', bboxes2, 'b');
figure, imshow(fI2)
title('Detected face');
% bboxes2 = 202 354 42 42
% Now use detectSURFFeatures to match up original face and rotated face
% DOESN'T WORK!
original = rgb2gray(I);
x12 = bboxes(1,2)+1:bboxes(1,2)+bboxes(1,4);
y12 = bboxes(1,1)+1:bboxes(1,1)+bboxes(1,3);
oROI = original(x12,y12);
distorted = imrotate(oROI,-90);
ptsOriginal = detectSURFFeatures(original);
ptsDistorted = detectSURFFeatures(distorted);
[featuresOriginal, validPtsOriginal] = extractFeatures(original, ptsOriginal);
[featuresDistorted, validPtsDistorted] = extractFeatures(distorted, ptsDistorted);
% Match features by using their descriptors.
indexPairs = matchFeatures(featuresOriginal, featuresDistorted);
% Retrieve locations of corresponding points for each image.
matchedOriginal = validPtsOriginal(indexPairs(:,1));
matchedDistorted = validPtsDistorted(indexPairs(:,2));
% Show putative point matches.
figure;
showMatchedFeatures(original,distorted,matchedOriginal,matchedDistorted);
title('Putatively matched points (including outliers)');

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Feature Detection and Extraction 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by