Image 面部对齐后的眼睛位置
面部对齐(imrotate)后,我无法找到眼睛中心 代码如下:Image 面部对齐后的眼睛位置,image,matlab,math,image-processing,Image,Matlab,Math,Image Processing,面部对齐(imrotate)后,我无法找到眼睛中心 代码如下: img = imread('1000306439_a1744969b8_1369_11099615@N00.jpg'); eyes = [230 238; 126 124]; if length(size(IMG)) > 2 img = rgb2gray(img); end subplot(1,2,1),imshow(img);hold on; plot(eyes(1,:),eyes(2,:),'-rx'); hol
img = imread('1000306439_a1744969b8_1369_11099615@N00.jpg');
eyes = [230 238; 126 124];
if length(size(IMG)) > 2
img = rgb2gray(img);
end
subplot(1,2,1),imshow(img);hold on;
plot(eyes(1,:),eyes(2,:),'-rx'); hold off;
tg_a = diff(eyes(2,:))/diff(eyes(1,:));
angle = tg_a*(180/pi);
img_rot = imrotate(img, angle,'crop');
Cx = size(img,2)/2;
Cy = size(img,1)/2;
R_EyeX = (Cx+(eyes(1,1)-Cx)*cosd(tg_a)-(eyes(2,1)-Cy)*sind(tg_a));
R_EyeY = (Cy+(eyes(1,1)-Cx)*sind(tg_a)+(eyes(2,1)-Cy)*cosd(tg_a));
L_EyeX = (Cx+(eyes(1,2)-Cx)*cosd(tg_a)-(eyes(2,2)-Cy)*sind(tg_a));
L_EyeY = (Cy+(eyes(1,2)-Cx)*sind(tg_a)+(eyes(2,2)-Cy)*cosd(tg_a));
subplot(1,2,2),imshow(img_rot);hold on;
plot([R_EyeX L_EyeX],[R_EyeY L_EyeY],'-rx');hold off;
结果是:
固定代码:
img = imread('1000306439_a1744969b8_1369_11099615@N00.jpg');
eyes = [230 238; 126 124];
if length(size(IMG)) > 2
img = rgb2gray(img);
end
subplot(1,2,1),imshow(img);hold on;
plot(eyes(1,:),eyes(2,:),'-rx'); hold off;
tg_a = diff(eyes(2,:))/diff(eyes(1,:));
angle = tg_a*(180/pi);
tg_a = -angle * (pi/180);
img_rot = imrotate(img, angle,'crop');
Cx = size(img,2)/2;
Cy = size(img,1)/2;
R_EyeX = (Cx+(eyes(1,1)-Cx)*cos(tg_a)-(eyes(2,1)-Cy)*sin(tg_a));
R_EyeY = (Cy+(eyes(1,1)-Cx)*sin(tg_a)+(eyes(2,1)-Cy)*cos(tg_a));
L_EyeX = (Cx+(eyes(1,2)-Cx)*cos(tg_a)-(eyes(2,2)-Cy)*sin(tg_a));
L_EyeY = (Cy+(eyes(1,2)-Cx)*sin(tg_a)+(eyes(2,2)-Cy)*cos(tg_a));
subplot(1,2,2),imshow(img_rot);hold on;
plot([R_EyeX L_EyeX],[R_EyeY L_EyeY],'-rx');hold off;
你到底有什么问题?什么东西没有按预期工作?旋转后,我没有找到眼睛的新位置,我猜
cosd(tg_a)
/sind(tg_a)
应该是cos(tg_a)
或cosd(angle)
。你的星座也有问题,因为即使有了这些修正,旋转方向也会错误。我仍然不明白tg_a=diff(眼睛(2,:)/diff(眼睛(1,:)
如何定义角度。这里不需要三角函数吗<代码>棕色?