Using vision.CascadeObjectDetector to find rotated faces and findSURFFeatures to align them with original - doesn't work!
2 次查看(过去 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...
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/289789/image.jpeg)
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)');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/289793/image.jpeg)
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Feature Detection and Extraction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!