gpt4 book ai didi

PHP - 如何获得旋转后点的坐标?

转载 作者:行者123 更新时间:2023-12-04 08:00:38 25 4
gpt4 key购买 nike

我希望图像中的眼睛是水平的

$rightEyeY = 446;
$rightEyeX = 625;
$leftEyeY = 433;
$leftEyeX = 733;

// Get middle point of two eyes
$y = $rightEyeY - $leftEyeY;
$x = $rightEyeX - $leftEyeX;

$angle = rad2deg(atan2($y, $x)) - 180; // -6.8 degrees

$manager = new ImageManager(['driver' => 'imagick']);
$image = $manager->make('image.jpg')->rotate($angle);
$a = $angle * pi() / 180.0;
$cosa = cos($a);
$sina = sin($a);
$x = $x * $cosa - $y * $sina; // This one calculates x of the middle point not each eye.
$y = $x * $sina + $y * $cosa; // This one calculates y of the middle point not each eye.
旋转后如何获得每只眼睛的坐标?
我想要那些变量在顶部
FROM:
右眼 = 446
右眼X = 625
左眼 = 433
左眼X = 733
TO:
右眼 = 432
右眼X = 640
左眼 = 432
左眼X = 749

最佳答案

我尝试了一些东西,但得到了其他坐标。它看起来很适合我。诀窍是旋转平移到中心。我认为差异来自 -6.83 的角度是错误的(OP 代码中的眼睛距离)。

If you do not translate, the rotation will be done at (0,0) the origin of the coordinate system which is then top left corner in image space, but you want the center.


$angle = deg2rad(-6.83);
list($leftX, $leftY) = $rotateEye($leftEyeX, $leftEyeY, $angle);
list($rightX, $rightY) = $rotateEye($rightEyeX, $rightEyeY, $angle);
并给我
L: (734.56131177907, 734.56131177907)
R: (628.87375746869, 418.91568508316)
但是图像看起来像那样,左蓝色,右红色。底部一对是原点,顶部旋转 -6.83 度。
enter image description here
二维旋转矩阵和平移代码
$rotateEye = function ($x, $y, $angle) use ($centerX, $centerY): array {
$tx = $x - $centerX;
$ty = $y - $centerY;
$rx = cos($angle) * $tx - sin($angle) * $ty;
$ry = sin($angle) * $tx + cos($angle) * $ty;
return [$rx + $centerX, $ry + $centerY];
};
这里有 pastebin的完整代码。

关于PHP - 如何获得旋转后点的坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66495632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com