【发布时间】:2021-06-04 07:35:31
【问题描述】:
我希望图像中的眼睛是水平的
$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:
rightEyeY = 446
rightEyeX = 625
leftEyeY = 433
leftEyeX = 733
TO:
rightEyeY = 432
rightEyeX = 640
leftEyeY = 432
leftEyeX = 749
【问题讨论】:
-
中间点将被
$rightEyeY - $leftEyeY;中的两个除以 -
How can I get the coordinates of each eye after rotation?- 你为什么不旋转每只眼睛? -
正如stackoverflow.com/questions/8742237/coordinate-rotation-in-php 中所指出的,您正在计算
$x和$y,同时在计算中使用它们。 -
@NigelRen 他是先减法再加法。但我正在这样做。我只是计算并将其放入变量中。即使我改变了变量名,也不会影响结果。
-
在第一个计算 -
$x = $x * $cosa - $y * $sina;,你改变了$x的值,这肯定会影响到下一个结果$y = $x * $sina + $y * $cosa;,它依赖于原来的x坐标。跨度>
标签: php rotation coordinates imagick